Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix event propagation to child after set_as_toplevel #67507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,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) {
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ class Control : public CanvasItem {
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.
Expand Down
17 changes: 17 additions & 0 deletions scene/main/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,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;
}
Expand Down
3 changes: 3 additions & 0 deletions scene/main/canvas_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class CanvasItem : public Node {
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();
Expand Down