diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index fc27c0d24ff..c176e50cee2 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1865,7 +1865,7 @@ void Control::_modal_stack_remove() { } -void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) { +void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner,bool p_assign) { Control *c = p_at->cast_to(); @@ -1884,15 +1884,30 @@ void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) { if (c) { - c->data.theme_owner=p_owner; + if (p_assign) { + c->data.theme_owner=p_owner; + } c->_notification(NOTIFICATION_THEME_CHANGED); c->update(); } } + +void Control::_theme_changed() { + + _propagate_theme_changed(this,this,false); +} + void Control::set_theme(const Ref& p_theme) { + if (data.theme==p_theme) + return; + + if (data.theme.is_valid()) { + data.theme->disconnect("changed",this,"_theme_changed"); + } + data.theme=p_theme; if (!p_theme.is_null()) { @@ -1909,6 +1924,9 @@ void Control::set_theme(const Ref& p_theme) { } + if (data.theme.is_valid()) { + data.theme->connect("changed",this,"_theme_changed"); + } } @@ -2448,6 +2466,10 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed); + ObjectTypeDB::bind_method(_MD("_theme_changed"), &Control::_theme_changed); + + + ObjectTypeDB::bind_method(_MD("_font_changed"), &Control::_font_changed); BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event"))); diff --git a/scene/gui/control.h b/scene/gui/control.h index 830ebd1620a..1337cbc4b9c 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -172,7 +172,9 @@ 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(CanvasItem *p_at, Control *p_owner); + void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign=true); + void _theme_changed(); + void _change_notify_margins(); void _update_minimum_size(); diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 92a6f0c0b9d..b351167e10e 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -219,7 +219,22 @@ Ref Theme::get_default() { void Theme::set_default_theme_font( const Ref& p_default_font ) { + if (default_theme_font==p_default_font) + return; + + if (default_theme_font.is_valid()) { + _unref_font(default_theme_font); + } + default_theme_font=p_default_font; + + if (default_theme_font.is_valid()) { + _ref_font(default_theme_font); + } + + _change_notify(); + emit_changed();; + } Ref Theme::get_default_theme_font() const {