fix layer move nodes

This commit is contained in:
2019-11-10 13:51:02 +01:00
parent 8452bbe3e9
commit 35937ad4c6

View File

@@ -497,6 +497,8 @@ void Node::move_child(Node* n, int index)
{
App::I->ui_task([&]
{
int count = YGNodeGetChildCount(y_node);
index = glm::clamp<int>(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<int>(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)