Fix theme propagation for children of top level controls

This commit is contained in:
Yuri Sizov 2022-06-01 03:56:51 +03:00 committed by Relintai
parent 3b84a64a36
commit eed219ada1

View File

@ -493,53 +493,45 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_ENTER_CANVAS: { case NOTIFICATION_ENTER_CANVAS: {
data.parent = Object::cast_to<Control>(get_parent()); data.parent = Object::cast_to<Control>(get_parent());
if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
data.theme_owner = data.parent->data.theme_owner;
notification(NOTIFICATION_THEME_CHANGED);
}
if (is_set_as_toplevel()) { if (is_set_as_toplevel()) {
data.SI = get_viewport()->_gui_add_subwindow_control(this); data.SI = get_viewport()->_gui_add_subwindow_control(this);
if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
data.theme_owner = data.parent->data.theme_owner;
notification(NOTIFICATION_THEME_CHANGED);
}
} else { } else {
Node *parent = this; //meh Node *parent = get_parent();
Control *parent_control = nullptr; bool is_subwindow = false;
bool subwindow = false; bool has_parent_control = false;
while (parent) { while (parent) {
parent = parent->get_parent();
if (!parent) {
break;
}
CanvasItem *ci = Object::cast_to<CanvasItem>(parent); CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
if (ci && ci->is_set_as_toplevel()) { if (ci && ci->is_set_as_toplevel()) {
subwindow = true; is_subwindow = true;
break; break;
} }
parent_control = Object::cast_to<Control>(parent); Control *parent_control = Object::cast_to<Control>(parent);
if (parent_control) { if (parent_control) {
has_parent_control = true;
break; break;
} else if (ci) { } else if (ci) {
// Continue.
} else { } else {
break; break;
} }
parent = parent->get_parent();
} }
if (parent_control) { if (has_parent_control) {
//do nothing, has a parent control // Do nothing, has a parent control.
if (data.theme.is_null() && parent_control->data.theme_owner) { } else if (is_subwindow) {
data.theme_owner = parent_control->data.theme_owner; // Is a subwindow (process input before other controls for that canvas).
notification(NOTIFICATION_THEME_CHANGED);
}
} else if (subwindow) {
//is a subwindow (process input before other controls for that canvas)
data.SI = get_viewport()->_gui_add_subwindow_control(this); data.SI = get_viewport()->_gui_add_subwindow_control(this);
} else { } else {
//is a regular root control // Is a regular root control.
Viewport *viewport = get_viewport(); Viewport *viewport = get_viewport();
ERR_FAIL_COND(!viewport); ERR_FAIL_COND(!viewport);
data.RI = viewport->_gui_add_root_control(this); data.RI = viewport->_gui_add_root_control(this);
@ -550,7 +542,7 @@ void Control::_notification(int p_notification) {
if (data.parent_canvas_item) { if (data.parent_canvas_item) {
data.parent_canvas_item->connect("item_rect_changed", this, "_size_changed"); data.parent_canvas_item->connect("item_rect_changed", this, "_size_changed");
} else { } else {
//connect viewport // Connect viewport.
Viewport *viewport = get_viewport(); Viewport *viewport = get_viewport();
ERR_FAIL_COND(!viewport); ERR_FAIL_COND(!viewport);
viewport->connect("size_changed", this, "_size_changed"); viewport->connect("size_changed", this, "_size_changed");