diff options
author | Yuri Sizov <yuris@humnom.net> | 2022-09-02 17:45:09 +0300 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2022-09-02 23:44:23 +0300 |
commit | 8b128081e82b41f1ea5d7799236f17e6f2c1d087 (patch) | |
tree | 6f232a809d623c0cf89cd0940a29e5758cc90837 /scene/theme | |
parent | ddc55ef746e6778b902aa2ebeaf09d9b8d9943b5 (diff) |
Un-defer the initial theme changed notification
Co-authored-by: Rindbee <idleman@yeah.net>
Diffstat (limited to 'scene/theme')
-rw-r--r-- | scene/theme/theme_owner.cpp | 37 | ||||
-rw-r--r-- | scene/theme/theme_owner.h | 2 |
2 files changed, 39 insertions, 0 deletions
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<Control>(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<Window>(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<Control>(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<Window>(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<Control>(p_to_node); Window *w = c == nullptr ? Object::cast_to<Window>(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. |