fix: root node id overriding

This commit is contained in:
MihailRis 2025-11-23 19:37:44 +03:00
parent 17e8d9bb1b
commit 91cb5ab7d8
4 changed files with 8 additions and 9 deletions

View File

@ -23,11 +23,12 @@ void UiDocument::rebuildIndices() {
map["root"] = root; map["root"] = root;
} }
const UINodesMap& UiDocument::getMap() const { void UiDocument::pushIndices(const std::shared_ptr<gui::UINode>& node) {
return map; gui::UINode::getIndices(node, map);
map["root"] = root;
} }
UINodesMap& UiDocument::getMapWriteable() { const UINodesMap& UiDocument::getMap() const {
return map; return map;
} }

View File

@ -36,10 +36,10 @@ public:
); );
void rebuildIndices(); void rebuildIndices();
void pushIndices(const std::shared_ptr<gui::UINode>& node);
const std::string& getId() const; const std::string& getId() const;
const UINodesMap& getMap() const; const UINodesMap& getMap() const;
UINodesMap& getMapWriteable();
std::shared_ptr<gui::UINode> getRoot() const; std::shared_ptr<gui::UINode> getRoot() const;
std::shared_ptr<gui::UINode> get(const std::string& id) const; std::shared_ptr<gui::UINode> get(const std::string& id) const;
const uidocscript& getScript() const; const uidocscript& getScript() const;

View File

@ -310,7 +310,7 @@ bool GUI::isFocusCaught() const {
} }
void GUI::add(std::shared_ptr<UINode> node) { void GUI::add(std::shared_ptr<UINode> node) {
UINode::getIndices(node, rootDocument->getMapWriteable()); rootDocument->pushIndices(node);
container->add(std::move(node)); container->add(std::move(node));
} }

View File

@ -105,7 +105,7 @@ static int l_container_add(lua::State* L) {
auto subnode = guiutil::create( auto subnode = guiutil::create(
engine->getGUI(), xmlsrc, std::move(env) engine->getGUI(), xmlsrc, std::move(env)
); );
UINode::getIndices(subnode, docnode.document->getMapWriteable()); docnode.document->pushIndices(subnode);
node->add(std::move(subnode)); node->add(std::move(subnode));
} catch (const std::exception& err) { } catch (const std::exception& err) {
throw std::runtime_error("container:add(...): " + std::string(err.what())); throw std::runtime_error("container:add(...): " + std::string(err.what()));
@ -410,9 +410,7 @@ static const std::string& request_node_id(const DocumentNode& docnode) {
reinterpret_cast<std::ptrdiff_t>(docnode.node.get())); reinterpret_cast<std::ptrdiff_t>(docnode.node.get()));
} }
docnode.node->setId(std::move(id)); docnode.node->setId(std::move(id));
UINode::getIndices( docnode.document->pushIndices(docnode.node);
docnode.node, docnode.document->getMapWriteable()
);
return docnode.node->getId(); return docnode.node->getId();
} }