mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 08:15:38 +07:00
node: remove_child_at function
This commit is contained in:
@@ -128,6 +128,8 @@ namespace e2d
|
|||||||
|
|
||||||
node_iptr child_at(std::size_t index) noexcept;
|
node_iptr child_at(std::size_t index) noexcept;
|
||||||
const_node_iptr child_at(std::size_t index) const noexcept;
|
const_node_iptr child_at(std::size_t index) const noexcept;
|
||||||
|
|
||||||
|
node_iptr remove_child_at(std::size_t index) noexcept;
|
||||||
protected:
|
protected:
|
||||||
node() = default;
|
node() = default;
|
||||||
node(gobject owner);
|
node(gobject owner);
|
||||||
|
|||||||
@@ -145,5 +145,10 @@ function node.bring_to_front(self) end
|
|||||||
---@return node
|
---@return node
|
||||||
function node.child_at(self, index) end
|
function node.child_at(self, index) end
|
||||||
|
|
||||||
|
---@param self node
|
||||||
|
---@param index integer
|
||||||
|
---@return node
|
||||||
|
function node.remove_child_at(self, index) end
|
||||||
|
|
||||||
---@type node
|
---@type node
|
||||||
_G.node = _G.node or node
|
_G.node = _G.node or node
|
||||||
|
|||||||
@@ -147,6 +147,12 @@ namespace e2d::bindings::high
|
|||||||
return index >= 0
|
return index >= 0
|
||||||
? n.child_at(math::numeric_cast<std::size_t>(index))
|
? n.child_at(math::numeric_cast<std::size_t>(index))
|
||||||
: node_iptr();
|
: node_iptr();
|
||||||
|
},
|
||||||
|
|
||||||
|
"remove_child_at", [](node& n, i32 index) -> node_iptr {
|
||||||
|
return index >= 0
|
||||||
|
? n.remove_child_at(math::numeric_cast<std::size_t>(index))
|
||||||
|
: node_iptr();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,6 +430,13 @@ namespace e2d
|
|||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node_iptr node::remove_child_at(std::size_t index) noexcept {
|
||||||
|
node_iptr child = child_at(index);
|
||||||
|
return remove_child(child)
|
||||||
|
? child
|
||||||
|
: node_iptr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
|
|||||||
@@ -450,6 +450,27 @@ TEST_CASE("node") {
|
|||||||
REQUIRE_FALSE(cp->child_at(3));
|
REQUIRE_FALSE(cp->child_at(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SECTION("remove_child_at") {
|
||||||
|
auto p = node::create();
|
||||||
|
|
||||||
|
auto n1 = node::create(p);
|
||||||
|
auto n2 = node::create(p);
|
||||||
|
auto n3 = node::create(p);
|
||||||
|
|
||||||
|
REQUIRE_FALSE(n1->remove_child_at(0));
|
||||||
|
|
||||||
|
REQUIRE(p->remove_child_at(1) == n2);
|
||||||
|
REQUIRE_FALSE(n2->has_parent());
|
||||||
|
REQUIRE(p->child_count() == 2u);
|
||||||
|
|
||||||
|
REQUIRE(p->remove_child_at(0) == n1);
|
||||||
|
REQUIRE_FALSE(n1->has_parent());
|
||||||
|
REQUIRE(p->child_count() == 1u);
|
||||||
|
|
||||||
|
REQUIRE(p->remove_child_at(0) == n3);
|
||||||
|
REQUIRE_FALSE(n3->has_parent());
|
||||||
|
REQUIRE(p->child_count() == 0u);
|
||||||
|
}
|
||||||
SECTION("add_child_to_back/add_child_to_front") {
|
SECTION("add_child_to_back/add_child_to_front") {
|
||||||
auto p = node::create();
|
auto p = node::create();
|
||||||
auto n1 = node::create();
|
auto n1 = node::create();
|
||||||
|
|||||||
Reference in New Issue
Block a user