From b73983340da174e1de95a49b59649f3a79438906 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Thu, 12 Aug 2021 18:35:42 +0100 Subject: [PATCH] Add bulk theme overrides to Control --- doc/classes/Control.xml | 12 +++++++++++ scene/gui/control.cpp | 44 ++++++++++++++++++++++++++++++----------- scene/gui/control.h | 5 +++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 43e3c97bffa..0834521c911 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -306,6 +306,18 @@ [/codeblocks] + + + + Prevents [code]*_theme_*_override[/code] methods from emitting [constant NOTIFICATION_THEME_CHANGED] until [method end_bulk_theme_override] is called. + + + + + + Ends a bulk theme override update. See [method begin_bulk_theme_override]. + + diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index a2e6872da66..d37ccd63ec9 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1686,6 +1686,17 @@ Rect2 Control::get_anchorable_rect() const { return Rect2(Point2(), get_size()); } +void Control::begin_bulk_theme_override() { + data.bulk_theme_override = true; +} + +void Control::end_bulk_theme_override() { + ERR_FAIL_COND(!data.bulk_theme_override); + + data.bulk_theme_override = false; + _notify_theme_changed(); +} + void Control::add_theme_icon_override(const StringName &p_name, const Ref &p_icon) { ERR_FAIL_COND(!p_icon.is_valid()); @@ -1695,7 +1706,7 @@ void Control::add_theme_icon_override(const StringName &p_name, const Refconnect("changed", callable_mp(this, &Control::_override_changed), Vector(), CONNECT_REFERENCE_COUNTED); - notification(NOTIFICATION_THEME_CHANGED); + _notify_theme_changed(); } void Control::add_theme_style_override(const StringName &p_name, const Ref &p_style) { @@ -1707,7 +1718,7 @@ void Control::add_theme_style_override(const StringName &p_name, const Ref