summaryrefslogtreecommitdiff
path: root/scene/theme
diff options
context:
space:
mode:
Diffstat (limited to 'scene/theme')
-rw-r--r--scene/theme/theme_owner.cpp37
-rw-r--r--scene/theme/theme_owner.h2
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.