diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-15 17:14:03 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-04-15 17:14:03 +1000 |
commit | 90f3835dae164b48ee63eaf4e1d586ca34961536 (patch) | |
tree | f599bc59c1244426ea8b28704f5bc4ece4a5fbdf /source/windowing/StarWidgetLuaBindings.cpp | |
parent | 37d72623759ecb36e738e5f6853293a8f021d628 (diff) |
widget.getText didn't work for labels and buttons??
Diffstat (limited to 'source/windowing/StarWidgetLuaBindings.cpp')
-rw-r--r-- | source/windowing/StarWidgetLuaBindings.cpp | 38 |
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) { |