osb/source/windowing/StarTextBoxWidget.hpp

93 lines
2.3 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#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() const;
2023-06-20 04:33:09 +00:00
bool setText(String const& text, bool callback = true);
bool getHidden() const;
void setHidden(bool hidden);
2023-06-20 04:33:09 +00:00
// 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);
2023-06-20 04:33:09 +00:00
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;
2023-06-20 04:33:09 +00:00
String m_text;
String m_hint;
String m_regex;
HorizontalAnchor m_hAnchor;
VerticalAnchor m_vAnchor;
Color m_color;
String m_processingDirectives;
2023-06-21 12:29:40 +00:00
String m_font;
2023-06-20 04:33:09 +00:00
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