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

summaryrefslogtreecommitdiff
path: root/source/windowing/StarTextBoxWidget.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/windowing/StarTextBoxWidget.hpp')
-rw-r--r--source/windowing/StarTextBoxWidget.hpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/source/windowing/StarTextBoxWidget.hpp b/source/windowing/StarTextBoxWidget.hpp
new file mode 100644
index 0000000..1299d78
--- /dev/null
+++ b/source/windowing/StarTextBoxWidget.hpp
@@ -0,0 +1,85 @@
+#ifndef STAR_TEXTBOX_WIDGET_HPP
+#define STAR_TEXTBOX_WIDGET_HPP
+
+#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() override;
+
+ String getText();
+ bool setText(String const& text, bool callback = true);
+
+ // Set the regex that the text-box must match. Defaults to .*
+ String getRegex();
+ void setRegex(String const& regex);
+
+ void setColor(Color const& color);
+ 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;
+
+ String m_text;
+ String m_hint;
+ String m_regex;
+ HorizontalAnchor m_hAnchor;
+ VerticalAnchor m_vAnchor;
+ Color m_color;
+ int m_fontSize;
+ 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;
+};
+
+}
+
+#endif