widget.getText didn't work for labels and buttons??

This commit is contained in:
Kae 2024-04-15 17:14:03 +10:00
parent 37d7262375
commit 90f3835dae
5 changed files with 31 additions and 16 deletions

View File

@ -314,6 +314,10 @@ void ButtonWidget::setPressedOffset(Vec2I const& offset) {
m_pressedOffset = offset;
}
String const& ButtonWidget::getText() const {
return m_text;
}
void ButtonWidget::setText(String const& text) {
m_text = text;
}

View File

@ -66,6 +66,7 @@ public:
Vec2I const& pressedOffset() const;
void setPressedOffset(Vec2I const& offset);
virtual String const& getText() const;
virtual void setText(String const& text);
virtual void setFontSize(int size);
virtual void setFontDirectives(String directives);

View File

@ -154,7 +154,7 @@ void TextBoxWidget::update(float dt) {
}
}
String TextBoxWidget::getText() const {
String const& TextBoxWidget::getText() const {
return m_text;
}

View File

@ -13,7 +13,7 @@ public:
virtual void update(float dt) override;
String getText() const;
String const& getText() const;
bool setText(String const& text, bool callback = true);
bool getHidden() const;

View File

@ -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))
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))
if (auto widget = parentWidget->fetchChild(widgetName)) {
if (auto label = as<LabelWidget>(widget))
label->setText(text);
else if (auto button = parentWidget->fetchChild<ButtonWidget>(widgetName))
else if (auto button = as<ButtonWidget>(widget))
button->setText(text);
else if (auto textBox = parentWidget->fetchChild<TextBoxWidget>(widgetName))
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))
if (auto widget = parentWidget->fetchChild(widgetName)) {
if (auto label = as<LabelWidget>(widget))
label->setColor(color);
else if (auto button = parentWidget->fetchChild<ButtonWidget>(widgetName))
else if (auto button = as<ButtonWidget>(widget))
button->setFontColor(color);
else if (auto textBox = parentWidget->fetchChild<TextBoxWidget>(widgetName))
else if (auto textBox = as<TextBoxWidget>(widget))
textBox->setColor(color);
}
});
callbacks.registerCallback("setImage", [parentWidget](String const& widgetName, String const& imagePath) {