summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-31 15:55:46 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-31 15:55:46 +0100
commit4cfdd253849896cfb0e4c9f3510004f6dcbfddc6 (patch)
tree79486f8b1205f2dbbabe4aa864c8a274232e5251 /scene
parent6d9c9d30b9c50177a68695fba8a42998b2b49d4c (diff)
parent13b87c13c7de36e5258ff16500ae15a9a9041525 (diff)
Merge pull request #67507 from Sauermann/fix-toplevel-root-control-node
Fix event propagation to child after set_as_toplevel
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/control.cpp6
-rw-r--r--scene/gui/control.h3
-rw-r--r--scene/main/canvas_item.cpp17
-rw-r--r--scene/main/canvas_item.h3
4 files changed, 29 insertions, 0 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index f7c056316d..6f5e2cf058 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -692,6 +692,12 @@ Transform2D Control::get_transform() const {
return xform;
}
+void Control::_toplevel_changed_on_parent() {
+ // Update root control status.
+ _notification(NOTIFICATION_EXIT_CANVAS);
+ _notification(NOTIFICATION_ENTER_CANVAS);
+}
+
/// Anchors and offsets.
void Control::_set_anchor(Side p_side, real_t p_anchor) {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index a93a88e5b4..5977f4dbea 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -292,6 +292,9 @@ private:
void _update_minimum_size();
void _size_changed();
+ void _toplevel_changed() override{}; // Controls don't need to do anything, only other CanvasItems.
+ void _toplevel_changed_on_parent() override;
+
void _clear_size_warning();
// Input events.
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 35176f0edd..cde3503bdf 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -400,11 +400,28 @@ void CanvasItem::set_as_top_level(bool p_top_level) {
_exit_canvas();
top_level = p_top_level;
+ _toplevel_changed();
_enter_canvas();
_notify_transform();
}
+void CanvasItem::_toplevel_changed() {
+ // Inform children that toplevel status has changed on a parent.
+ int childs = get_child_count();
+ for (int i = 0; i < childs; i++) {
+ CanvasItem *child = Object::cast_to<CanvasItem>(get_child(i));
+ if (child) {
+ child->_toplevel_changed_on_parent();
+ }
+ }
+}
+
+void CanvasItem::_toplevel_changed_on_parent() {
+ // Inform children that toplevel status has changed on a parent.
+ _toplevel_changed();
+}
+
bool CanvasItem::is_set_as_top_level() const {
return top_level;
}
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 1c84ea338a..1ddfaa288c 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -125,6 +125,9 @@ private:
void _propagate_visibility_changed(bool p_parent_visible_in_tree);
void _handle_visibility_change(bool p_visible);
+ virtual void _toplevel_changed();
+ virtual void _toplevel_changed_on_parent();
+
void _redraw_callback();
void _enter_canvas();