diff options
author | Vladimir Krasheninnikov <boba09@list.ru> | 2025-03-01 20:31:48 +0100 |
---|---|---|
committer | Vladimir Krasheninnikov <boba09@list.ru> | 2025-03-01 20:31:48 +0100 |
commit | e9a67335409ccc75a95cf1093bedb47abc17861a (patch) | |
tree | 4abe97bc7a6f43a8dd8f891d374d61a829cbfd33 /source/windowing | |
parent | ec20848c4689e73090963255b6cf923d6859c1be (diff) |
Bring new textbox callbacks
Diffstat (limited to 'source/windowing')
-rw-r--r-- | source/windowing/StarTextBoxWidget.cpp | 20 | ||||
-rw-r--r-- | source/windowing/StarTextBoxWidget.hpp | 7 | ||||
-rw-r--r-- | source/windowing/StarWidgetLuaBindings.cpp | 28 |
3 files changed, 55 insertions, 0 deletions
diff --git a/source/windowing/StarTextBoxWidget.cpp b/source/windowing/StarTextBoxWidget.cpp index 634a006..e25e66a 100644 --- a/source/windowing/StarTextBoxWidget.cpp +++ b/source/windowing/StarTextBoxWidget.cpp @@ -168,6 +168,26 @@ 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 = cursorPosition; + if (m_cursorOffset < 0) + m_cursorOffset = 0; + if (m_cursorOffset > (int)m_text.size()) + m_cursorOffset = 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..b36d2f6 100644 --- a/source/windowing/StarWidgetLuaBindings.cpp +++ b/source/windowing/StarWidgetLuaBindings.cpp @@ -205,6 +205,34 @@ 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) { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + return textBox->getHint(); + } + }); + + 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) { + if (auto widget = parentWidget->fetchChild(widgetName)) { + if (auto textBox = as<TextBoxWidget>(widget)) + return textBox->getCursorPosition(); + } + }); + callbacks.registerCallback("getText", [parentWidget](String const& widgetName) -> Maybe<String> { if (auto widget = parentWidget->fetchChild(widgetName)) { if (auto label = as<LabelWidget>(widget)) |