From 35937ad4c6d52fd5ebec38c18399ad317a99bbdb Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sun, 10 Nov 2019 13:51:02 +0100 Subject: [PATCH] fix layer move nodes --- src/node.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/node.cpp b/src/node.cpp index dc81f9f..a5755a8 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -497,6 +497,8 @@ void Node::move_child(Node* n, int index) { App::I->ui_task([&] { + int count = YGNodeGetChildCount(y_node); + index = glm::clamp(index, 0, count - 1); YGNodeRemoveChild(y_node, n->y_node); YGNodeInsertChild(y_node, n->y_node, index); auto it = std::find_if(m_children.begin(), m_children.end(), @@ -509,29 +511,14 @@ void Node::move_child(Node* n, int index) void Node::move_child_front(Node* n) { - App::I->ui_task([&] - { - int count = YGNodeGetChildCount(y_node); - move_child(n, count - 1); - }); + int count = YGNodeGetChildCount(y_node); + move_child(n, count - 1); } void Node::move_child_offset(Node* n, int offset) { - App::I->ui_task([&] - { - int count = YGNodeGetChildCount(y_node); - for (int i = 0; i < count; i++) - { - if (YGNodeGetChild(y_node, i) == n->y_node) - { - int new_index = glm::clamp(i + offset, 0, count - 1); - YGNodeRemoveChild(y_node, n->y_node); - YGNodeInsertChild(y_node, n->y_node, new_index); - break; - } - } - }); + int idx = get_child_index(n); + move_child(n, idx + offset); } int Node::get_child_index(Node* n)