From 8b128081e82b41f1ea5d7799236f17e6f2c1d087 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 2 Sep 2022 17:45:09 +0300 Subject: Un-defer the initial theme changed notification Co-authored-by: Rindbee --- scene/theme/theme_owner.cpp | 37 +++++++++++++++++++++++++++++++++++++ scene/theme/theme_owner.h | 2 ++ 2 files changed, 39 insertions(+) (limited to 'scene/theme') diff --git a/scene/theme/theme_owner.cpp b/scene/theme/theme_owner.cpp index 1ac1d0f9fe..e89aa1b28d 100644 --- a/scene/theme/theme_owner.cpp +++ b/scene/theme/theme_owner.cpp @@ -68,6 +68,43 @@ bool ThemeOwner::has_owner_node() const { // Theme propagation. +void ThemeOwner::assign_theme_on_parented(Node *p_for_node) { + // We check if there are any themes affecting the parent. If that's the case + // its children also need to be affected. + // We don't notify here because `NOTIFICATION_THEME_CHANGED` will be handled + // a bit later by `NOTIFICATION_ENTER_TREE`. + + Node *parent = p_for_node->get_parent(); + + Control *parent_c = Object::cast_to(parent); + if (parent_c && parent_c->has_theme_owner_node()) { + propagate_theme_changed(p_for_node, parent_c->get_theme_owner_node(), false, true); + } else { + Window *parent_w = Object::cast_to(parent); + if (parent_w && parent_w->has_theme_owner_node()) { + propagate_theme_changed(p_for_node, parent_w->get_theme_owner_node(), false, true); + } + } +} + +void ThemeOwner::clear_theme_on_unparented(Node *p_for_node) { + // We check if there were any themes affecting the parent. If that's the case + // its children need were also affected and need to be updated. + // We don't notify because we're exiting the tree, and it's not important. + + Node *parent = p_for_node->get_parent(); + + Control *parent_c = Object::cast_to(parent); + if (parent_c && parent_c->has_theme_owner_node()) { + propagate_theme_changed(p_for_node, nullptr, false, true); + } else { + Window *parent_w = Object::cast_to(parent); + if (parent_w && parent_w->has_theme_owner_node()) { + propagate_theme_changed(p_for_node, nullptr, false, true); + } + } +} + void ThemeOwner::propagate_theme_changed(Node *p_to_node, Node *p_owner_node, bool p_notify, bool p_assign) { Control *c = Object::cast_to(p_to_node); Window *w = c == nullptr ? Object::cast_to(p_to_node) : nullptr; diff --git a/scene/theme/theme_owner.h b/scene/theme/theme_owner.h index 38344c3d9e..59b72c1627 100644 --- a/scene/theme/theme_owner.h +++ b/scene/theme/theme_owner.h @@ -53,6 +53,8 @@ public: // Theme propagation. + void assign_theme_on_parented(Node *p_for_node); + void clear_theme_on_unparented(Node *p_for_node); void propagate_theme_changed(Node *p_to_node, Node *p_owner_node, bool p_notify, bool p_assign); // Theme lookup. -- cgit v1.2.3