diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-03-02 11:28:55 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-02 11:28:55 +1100 |
commit | 3893151fe217a684aba77669bab6ca3b828943e7 (patch) | |
tree | 2616c70d9fa2ec2a2f01462327bc07b984579b26 /source/windowing | |
parent | 3e89b9cabf9b56f337b6b953d2222b56969d7375 (diff) | |
parent | 63d8c8e8db0a80f9dc98f98e845bc4654060ada4 (diff) |
Merge pull request #203 from KrashV/new-widget-callbacks
Bring new widget callbacks
Diffstat (limited to 'source/windowing')
-rw-r--r-- | source/windowing/StarTextBoxWidget.cpp | 16 | ||||
-rw-r--r-- | source/windowing/StarTextBoxWidget.hpp | 7 | ||||
-rw-r--r-- | source/windowing/StarWidgetLuaBindings.cpp | 30 |
3 files changed, 53 insertions, 0 deletions
diff --git a/source/windowing/StarTextBoxWidget.cpp b/source/windowing/StarTextBoxWidget.cpp index 634a006..f438231 100644 --- a/source/windowing/StarTextBoxWidget.cpp +++ b/source/windowing/StarTextBoxWidget.cpp @@ -168,6 +168,22 @@ bool TextBoxWidget::setText(String const& text, bool callback, bool moveCursor) return true; } +String const& TextBoxWidget::getHint() const { + return m_hint; +} + +void TextBoxWidget::setHint(String const& hint) { + m_hint = hint; +} + +int const& TextBoxWidget::getCursorPosition() const { + return m_cursorOffset; +} + +void TextBoxWidget::setCursorPosition(int cursorPosition) { + m_cursorOffset = clamp(cursorPosition, 0, (int)m_text.size()); +} + bool TextBoxWidget::getHidden() const { return m_textHidden; } diff --git a/source/windowing/StarTextBoxWidget.hpp b/source/windowing/StarTextBoxWidget.hpp index 5fed88e..b6666ed 100644 --- a/source/windowing/StarTextBoxWidget.hpp +++ b/source/windowing/StarTextBoxWidget.hpp @@ -16,6 +16,13 @@ public: 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); diff --git a/source/windowing/StarWidgetLuaBindings.cpp b/source/windowing/StarWidgetLuaBindings.cpp index 16ef279..89eef00 100644 --- a/source/windowing/StarWidgetLuaBindings.cpp +++ b/source/windowing/StarWidgetLuaBindings.cpp @@ -205,6 +205,36 @@ LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr // callbacks only valid for specific widget types + callbacks.registerCallback("setHint", [parentWidget](String const& widgetName, String const& hint) { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + textBox->setHint(hint); + } + }); + + callbacks.registerCallback("getHint", [parentWidget](String const& widgetName) -> Maybe<String> { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + return textBox->getHint(); + } + return {}; + }); + + callbacks.registerCallback("setCursorPosition", [parentWidget](String const& widgetName, int cursorPosition) { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + textBox->setCursorPosition(cursorPosition); + } + }); + + callbacks.registerCallback("getCursorPosition", [parentWidget](String const& widgetName) -> Maybe<int> { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + return textBox->getCursorPosition(); + } + return {}; + }); + callbacks.registerCallback("getText", [parentWidget](String const& widgetName) -> Maybe<String> { if (auto widget = parentWidget->fetchChild(widgetName)) { if (auto label = as<LabelWidget>(widget)) |