refactor: add GUI instance reference to UI nodes

This commit is contained in:
MihailRis
2025-04-02 14:55:53 +03:00
parent 74a94f869c
commit 4c48afbb90
70 changed files with 1133 additions and 832 deletions
+7 -5
View File
@@ -80,8 +80,9 @@ static int l_container_add(lua::State* L) {
}
auto xmlsrc = lua::require_string(L, 2);
try {
auto subnode =
guiutil::create(xmlsrc, docnode.document->getEnvironment());
auto subnode = guiutil::create(
engine->getGUI(), xmlsrc, docnode.document->getEnvironment()
);
node->add(subnode);
UINode::getIndices(subnode, docnode.document->getMapWriteable());
} catch (const std::exception& err) {
@@ -93,7 +94,7 @@ static int l_container_add(lua::State* L) {
static int l_node_destruct(lua::State* L) {
auto docnode = get_document_node(L);
auto node = docnode.node;
engine->getGUI()->postRunnable([node]() {
engine->getGUI().postRunnable([node]() {
auto parent = node->getParent();
if (auto container = dynamic_cast<Container*>(parent)) {
container->remove(node.get());
@@ -651,7 +652,7 @@ static void p_set_focused(
const std::shared_ptr<UINode>& node, lua::State* L, int idx
) {
if (lua::toboolean(L, idx) && !node->isFocused()) {
engine->getGUI()->setFocus(node);
engine->getGUI().setFocus(node);
} else if (node->isFocused()) {
node->defocus();
}
@@ -782,7 +783,7 @@ static int l_gui_get_locales_info(lua::State* L) {
}
static int l_gui_getviewport(lua::State* L) {
return lua::pushvec2(L, engine->getGUI()->getContainer()->getSize());
return lua::pushvec2(L, engine->getGUI().getContainer()->getSize());
}
static int l_gui_clear_markup(lua::State* L) {
@@ -845,6 +846,7 @@ static int l_gui_load_document(lua::State* L) {
auto args = lua::tovalue(L, 3);
auto documentPtr = UiDocument::read(
engine->getGUI(),
scripting::get_root_environment(),
alias,
filename,