UiDocument

This commit is contained in:
MihailRis
2024-02-07 19:29:20 +03:00
parent c902ed506b
commit 1dd0e9f939
17 changed files with 257 additions and 42 deletions
+9 -2
View File
@@ -21,6 +21,9 @@ static Align align_from_string(const std::string& str, Align def) {
/* Read basic UINode properties */
static void _readUINode(xml::xmlelement element, UINode& node) {
if (element->has("id")) {
node.setId(element->attr("id").getText());
}
if (element->has("coord")) {
node.setCoord(element->attr("coord").asVec2());
}
@@ -111,7 +114,7 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
_readPanel(reader, element, *button);
if (element->has("onclick")) {
auto callback = scripting::create_runnable("<onclick>", element->attr("onclick").getText());
auto callback = scripting::create_runnable("<onclick>", element->attr("onclick").getText(), reader.getEnvironment());
button->listenAction([callback](GUI*) {
callback();
});
@@ -139,7 +142,7 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
return textbox;
}
UiXmlReader::UiXmlReader() {
UiXmlReader::UiXmlReader(const scripting::Environment& env) : env(env) {
add("label", readLabel);
add("button", readButton);
add("textbox", readTextBox);
@@ -181,3 +184,7 @@ std::shared_ptr<UINode> UiXmlReader::readXML(
const std::string& UiXmlReader::getFilename() const {
return filename;
}
const scripting::Environment& UiXmlReader::getEnvironment() const {
return env;
}