Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/windowing/StarTextBoxWidget.hpp
blob: b6666edee77a72901e8ece76c46796acb4f01250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once

#include "StarWidget.hpp"

namespace Star {

enum class SpecialRepeatKeyCodes : String::Char { None, Delete, Backspace, Left, Right };

STAR_CLASS(TextBoxWidget);
class TextBoxWidget : public Widget {
public:
  TextBoxWidget(String const& startingText, String const& hint, WidgetCallbackFunc callback);

  virtual void update(float dt) override;

  String const& getText() const;
  bool setText(String const& text, bool callback = true, bool moveCursor = true);

  String const& getHint() const;
  void setHint(String const& hint);

  int const& getCursorPosition() const;
  void setCursorPosition(int cursorPosition);


  bool getHidden() const;
  void setHidden(bool hidden);

  // Set the regex that the text-box must match.  Defaults to .*
  String getRegex();
  void setRegex(String const& regex);

  void setColor(Color const& color);
  void setDirectives(String const& directives);
  void setFontSize(int fontSize);
  void setMaxWidth(int maxWidth);
  void setOverfillMode(bool overfillMode);

  void setOnBlurCallback(WidgetCallbackFunc onBlur);
  void setOnEnterKeyCallback(WidgetCallbackFunc onEnterKey);
  void setOnEscapeKeyCallback(WidgetCallbackFunc onEscapeKey);

  void setNextFocus(Maybe<String> nextFocus);
  void setPrevFocus(Maybe<String> prevFocus);

  bool sendEvent(InputEvent const& event) override;

  void setDrawBorder(bool drawBorder);
  void setTextAlign(HorizontalAnchor hAnchor);
  int getCursorOffset();

  virtual void mouseOver() override;
  virtual void mouseOut() override;
  virtual void mouseReturnStillDown() override;

  virtual void blur() override;

  virtual KeyboardCaptureMode keyboardCaptured() const override;

protected:
  virtual void renderImpl() override;

private:
  bool innerSendEvent(InputEvent const& event);
  bool modText(String const& text);
  bool newTextValid(String const& text) const;

  bool m_textHidden;
  String m_text;
  String m_hint;
  String m_regex;
  HorizontalAnchor m_hAnchor;
  VerticalAnchor m_vAnchor;
  TextStyle m_textStyle;
  int m_maxWidth;
  int m_cursorOffset;
  bool m_isHover;
  bool m_isPressed;
  SpecialRepeatKeyCodes m_repeatCode;
  int64_t m_repeatKeyThreshold;
  WidgetCallbackFunc m_callback;
  WidgetCallbackFunc m_onBlur;
  WidgetCallbackFunc m_onEnterKey;
  WidgetCallbackFunc m_onEscapeKey;
  Maybe<String> m_nextFocus;
  Maybe<String> m_prevFocus;
  bool m_drawBorder;
  Vec2I m_cursorHoriz;
  Vec2I m_cursorVert;
  bool m_overfillMode;
};

}