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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Krasheninnikov <boba09@list.ru>2025-03-01 20:31:48 +0100
committerVladimir Krasheninnikov <boba09@list.ru>2025-03-01 20:31:48 +0100
commite9a67335409ccc75a95cf1093bedb47abc17861a (patch)
tree4abe97bc7a6f43a8dd8f891d374d61a829cbfd33
parentec20848c4689e73090963255b6cf923d6859c1be (diff)
Bring new textbox callbacks
-rw-r--r--doc/lua/openstarbound/widget.md33
-rw-r--r--source/windowing/StarTextBoxWidget.cpp20
-rw-r--r--source/windowing/StarTextBoxWidget.hpp7
-rw-r--r--source/windowing/StarWidgetLuaBindings.cpp28
4 files changed, 88 insertions, 0 deletions
diff --git a/doc/lua/openstarbound/widget.md b/doc/lua/openstarbound/widget.md
new file mode 100644
index 0000000..4d97e9a
--- /dev/null
+++ b/doc/lua/openstarbound/widget.md
@@ -0,0 +1,33 @@
+# Widget
+
+New widget callbacks introduced in OpenStarbound.
+
+## General callbacks
+
+These callbacks are available for all widgets.
+
+---
+
+## Widget specific callbacks
+
+These callbacks only work for some widget types.
+
+---
+
+#### `String` widget.getHint(`String` widgetName)
+
+Gets the hint text of a TextBoxWidget.
+
+#### `void` widget.setHint(`String` widgetName, `String` hint)
+
+Sets the hint text of a TextBoxWidget.
+
+---
+
+#### `String` widget.getCursorPosition(`String` widgetName)
+
+Gets the cursor position of a TextBoxWidget.
+
+#### `void` widget.setCursorPosition(`String` widgetName, `int` cursorPosition)
+
+Sets the cursor position of a TextBoxWidget. \ No newline at end of file
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))