Merge pull request #990 from MihailRis/recursion-related-fixes

fix recursion-related bugs
This commit is contained in:
MihailRis 2026-09-26 21:06:57 +03:00 • committed by GitHub
commit 4946a25ca5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 4 deletions

View file

@ -25,8 +25,12 @@ void InlineFrame::setDocument(const std::shared_ptr<UiDocument>& document) {
if (document == nullptr) { if (document == nullptr) {
return; return;
} }
auto newRoot = document->getRoot();
if (newRoot->hasParent()) {
return;
}
this->document = document; this->document = document;
this->root = document->getRoot(); this->root = std::move(newRoot);
add(root); add(root);
root->setSize(size); root->setSize(size);

View file

@ -60,6 +60,10 @@ bool UINode::isHover() const {
return hover; return hover;
} }
bool UINode::hasParent() const {
return parent != nullptr;
}
void UINode::setParent(UINode* node) { void UINode::setParent(UINode* node) {
parent = node; parent = node;
} }
@ -376,14 +380,14 @@ void UINode::setGravity(Gravity gravity) {
} }
} }
bool UINode::isSubnodeOf(const UINode* node) { bool UINode::isDescendantOf(const UINode* node) {
if (parent == nullptr) { if (parent == nullptr) {
return false; return false;
} }
if (parent == node) { if (parent == node) {
return true; return true;
} }
return parent->isSubnodeOf(node); return parent->isDescendantOf(node);
} }
void UINode::getIndices( void UINode::getIndices(

View file

@ -176,6 +176,7 @@ namespace gui {
void setMouseOver(bool flag); void setMouseOver(bool flag);
virtual void setParent(UINode* node); virtual void setParent(UINode* node);
bool hasParent() const;
UINode* getParent() const; UINode* getParent() const;
std::shared_ptr<UINode> getParentShared() const; std::shared_ptr<UINode> getParentShared() const;
@ -290,7 +291,7 @@ namespace gui {
virtual void setGravity(Gravity gravity); virtual void setGravity(Gravity gravity);
bool isSubnodeOf(const UINode* node); bool isDescendantOf(const UINode* node);
/// @brief collect all nodes having id /// @brief collect all nodes having id
static void getIndices( static void getIndices(

View file

@ -165,6 +165,13 @@ static int l_container_set_interval(lua::State* L) {
static int l_move_into(lua::State* L) { static int l_move_into(lua::State* L) {
auto node = get_document_node(L, 1); auto node = get_document_node(L, 1);
auto dest = get_document_node(L, 2); auto dest = get_document_node(L, 2);
if (dest.node == nullptr) {
return 0;
}
if (dest.node->isDescendantOf(node.node.get())) {
luaL_error(L, "unable to move element to its descendant");
return 0;
}
UINode::moveInto( UINode::moveInto(
node.node, std::dynamic_pointer_cast<Container>(dest.node) node.node, std::dynamic_pointer_cast<Container>(dest.node)
); );