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

summaryrefslogtreecommitdiff
path: root/source/windowing/StarWidgetLuaBindings.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-04-15 17:14:03 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-04-15 17:14:03 +1000
commit90f3835dae164b48ee63eaf4e1d586ca34961536 (patch)
treef599bc59c1244426ea8b28704f5bc4ece4a5fbdf /source/windowing/StarWidgetLuaBindings.cpp
parent37d72623759ecb36e738e5f6853293a8f021d628 (diff)
widget.getText didn't work for labels and buttons??
Diffstat (limited to 'source/windowing/StarWidgetLuaBindings.cpp')
-rw-r--r--source/windowing/StarWidgetLuaBindings.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/source/windowing/StarWidgetLuaBindings.cpp b/source/windowing/StarWidgetLuaBindings.cpp
index 5b59d48..16ef279 100644
--- a/source/windowing/StarWidgetLuaBindings.cpp
+++ b/source/windowing/StarWidgetLuaBindings.cpp
@@ -206,27 +206,37 @@ LuaCallbacks LuaBindings::makeWidgetCallbacks(Widget* parentWidget, GuiReaderPtr
// callbacks only valid for specific widget types
callbacks.registerCallback("getText", [parentWidget](String const& widgetName) -> Maybe<String> {
- if (auto textBox = parentWidget->fetchChild<TextBoxWidget>(widgetName))
- return textBox->getText();
+ if (auto widget = parentWidget->fetchChild(widgetName)) {
+ if (auto label = as<LabelWidget>(widget))
+ return label->text();
+ else if (auto button = as<ButtonWidget>(widget))
+ return button->getText();
+ else if (auto textBox = as<TextBoxWidget>(widget))
+ return textBox->getText();
+ }
return {};
});
callbacks.registerCallback("setText", [parentWidget](String const& widgetName, String const& text) {
- if (auto label = parentWidget->fetchChild<LabelWidget>(widgetName))
- label->setText(text);
- else if (auto button = parentWidget->fetchChild<ButtonWidget>(widgetName))
- button->setText(text);
- else if (auto textBox = parentWidget->fetchChild<TextBoxWidget>(widgetName))
- textBox->setText(text);
+ if (auto widget = parentWidget->fetchChild(widgetName)) {
+ if (auto label = as<LabelWidget>(widget))
+ label->setText(text);
+ else if (auto button = as<ButtonWidget>(widget))
+ button->setText(text);
+ else if (auto textBox = as<TextBoxWidget>(widget))
+ textBox->setText(text);
+ }
});
callbacks.registerCallback("setFontColor", [parentWidget](String const& widgetName, Color const& color) {
- if (auto label = parentWidget->fetchChild<LabelWidget>(widgetName))
- label->setColor(color);
- else if (auto button = parentWidget->fetchChild<ButtonWidget>(widgetName))
- button->setFontColor(color);
- else if (auto textBox = parentWidget->fetchChild<TextBoxWidget>(widgetName))
- textBox->setColor(color);
+ if (auto widget = parentWidget->fetchChild(widgetName)) {
+ if (auto label = as<LabelWidget>(widget))
+ label->setColor(color);
+ else if (auto button = as<ButtonWidget>(widget))
+ button->setFontColor(color);
+ else if (auto textBox = as<TextBoxWidget>(widget))
+ textBox->setColor(color);
+ }
});
callbacks.registerCallback("setImage", [parentWidget](String const& widgetName, String const& imagePath) {