diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-13 21:10:45 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-06-13 21:11:24 -0300 |
commit | 26d63b559433c12c8208d36ab586d36e47752829 (patch) | |
tree | 45bb673048ab8ed0c6958ec9092bffeaf7a94c01 /scene/gui | |
parent | d03f1131d75204fc0eb2d30896d4aff132c790aa (diff) |
propagate theme changes properly even through 2D nodes, fixes #4754
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 43 | ||||
-rw-r--r-- | scene/gui/control.h | 2 |
2 files changed, 33 insertions, 12 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index dfad7d1432..534bcbf16a 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -437,6 +437,12 @@ void Control::_notification(int p_notification) { if (is_set_as_toplevel()) { 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 { @@ -470,6 +476,10 @@ void Control::_notification(int p_notification) { if (parent_control) { //do nothing, has a parent control + if (data.theme.is_null() && parent_control->data.theme_owner) { + data.theme_owner=parent_control->data.theme_owner; + 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); @@ -1829,18 +1839,29 @@ void Control::_modal_stack_remove() { } -void Control::_propagate_theme_changed(Control *p_owner) { +void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) { - for(int i=0;i<get_child_count();i++) { + Control *c = p_at->cast_to<Control>(); + + if (c && c->data.theme.is_valid()) // has a theme, this can't be propagated + return; + + for(int i=0;i<p_at->get_child_count();i++) { + + CanvasItem *child = p_at->get_child(i)->cast_to<CanvasItem>(); + if (child) { + _propagate_theme_changed(child,p_owner); + } - Control *child = get_child(i)->cast_to<Control>(); - if (child && child->data.theme.is_null()) //has no theme, propagate - child->_propagate_theme_changed(p_owner); } - data.theme_owner=p_owner; - _notification(NOTIFICATION_THEME_CHANGED); - update(); + + if (c) { + + c->data.theme_owner=p_owner; + c->_notification(NOTIFICATION_THEME_CHANGED); + c->update(); + } } void Control::set_theme(const Ref<Theme>& p_theme) { @@ -1849,15 +1870,15 @@ void Control::set_theme(const Ref<Theme>& p_theme) { data.theme=p_theme; if (!p_theme.is_null()) { - _propagate_theme_changed(this); + _propagate_theme_changed(this,this); } else { Control *parent = get_parent()?get_parent()->cast_to<Control>():NULL; if (parent && parent->data.theme_owner) { - _propagate_theme_changed(parent->data.theme_owner); + _propagate_theme_changed(this,parent->data.theme_owner); } else { - _propagate_theme_changed(NULL); + _propagate_theme_changed(this,NULL); } } diff --git a/scene/gui/control.h b/scene/gui/control.h index 59704ae29b..69ee41f180 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -169,7 +169,7 @@ private: float _get_range(int p_idx) const; float _s2a(float p_val, AnchorType p_anchor,float p_range) const; float _a2s(float p_val, AnchorType p_anchor,float p_range) const; - void _propagate_theme_changed(Control *p_owner); + void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner); void _change_notify_margins(); void _update_minimum_size(); |