diff options
author | Hop311 <Hop3114@gmail.com> | 2024-07-28 00:25:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-28 00:25:05 +0200 |
commit | bf4d061b06374cd696f1f1644548f4d7af86f5ec (patch) | |
tree | 9ab24e79d47c2c56dfd68ebf89e419d30324c92c /extension/src/openvic-extension/classes/GUINode.cpp | |
parent | 0300a10ed7839710750b3937307c1f6c11c7bd75 (diff) | |
parent | 164db4eb8f24e87755e02bae0e539f4f266e15b9 (diff) |
Merge pull request #245 from OpenVicProject/free-on-remove
Free removed child nodes
Diffstat (limited to 'extension/src/openvic-extension/classes/GUINode.cpp')
-rw-r--r-- | extension/src/openvic-extension/classes/GUINode.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/extension/src/openvic-extension/classes/GUINode.cpp b/extension/src/openvic-extension/classes/GUINode.cpp index 674f162..d8ab6c1 100644 --- a/extension/src/openvic-extension/classes/GUINode.cpp +++ b/extension/src/openvic-extension/classes/GUINode.cpp @@ -83,6 +83,9 @@ void GUINode::_bind_methods() { OV_BIND_METHOD(GUINode::hide_node, { "path" }); OV_BIND_METHOD(GUINode::hide_nodes, { "paths" }); + OV_BIND_METHOD(GUINode::remove_node, { "path" }); + OV_BIND_METHOD(GUINode::remove_nodes, { "paths" }); + OV_BIND_SMETHOD(int_to_string_suffixed, { "val" }); OV_BIND_SMETHOD(float_to_string_suffixed, { "val" }); OV_BIND_SMETHOD(float_to_string_dp, { "val", "decimal_places" }); @@ -207,17 +210,46 @@ APPLY_TO_TEXTURE_TYPES(TEXTURE_GET_FUNCTIONS) Error GUINode::hide_node(NodePath const& path) const { CanvasItem* node = _cast_node<CanvasItem>(get_node_internal(path)); ERR_FAIL_NULL_V(node, FAILED); + node->hide(); + return OK; } Error GUINode::hide_nodes(TypedArray<NodePath> const& paths) const { Error ret = OK; + for (int32_t i = 0; i < paths.size(); ++i) { if (hide_node(paths[i]) != OK) { ret = FAILED; } } + + return ret; +} + +Error GUINode::remove_node(NodePath const& path) const { + Node* node = get_node_internal(path); + ERR_FAIL_NULL_V(node, FAILED); + + Node* parent = node->get_parent(); + ERR_FAIL_NULL_V(parent, FAILED); + + parent->remove_child(node); + node->queue_free(); + + return OK; +} + +Error GUINode::remove_nodes(TypedArray<NodePath> const& paths) const { + Error ret = OK; + + for (int32_t i = 0; i < paths.size(); ++i) { + if (remove_node(paths[i]) != OK) { + ret = FAILED; + } + } + return ret; } @@ -331,7 +363,7 @@ void GUINode::set_click_mask_from_nodepaths(TypedArray<NodePath> const& paths) { update_click_mask(); } -bool GUINode::_has_point(godot::Vector2 const& p_point) const { +bool GUINode::_has_point(Vector2 const& p_point) const { if (!_click_mask.is_valid()) { return Control::_has_point(p_point); } |