Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix theme propagation in various parts of the editor #65210

Merged

Conversation

YuriSizov
Copy link
Contributor

@YuriSizov YuriSizov commented Sep 1, 2022

Fixes #65090 (including the issue reported in comments).
Fixes #65114.
Likely fixes #65180.

Follow-up to #65156 and #65192 (depends on both of them, and for the moment includes commits from both of them). In this part we're starting to fix parts of the editor which were exposed by #62845. I'll be targeting specific regressions here, and a more broad code clean-up can happen in a later PR (and by anyone, really, once the first two are merged).

Currently this PR updates the code of:

  • RichTextLabel (didn't touch EditorHelp to fix the docs regression);
  • MaterialEditor and MeshEditor;
  • EditorFileDialog;

As well as other small touch ups.

Marking it as a draft for the moment. Feel free to comment with more related theme propagation regressions. (I think @groud said there was something in the tile editor?)

@Rindbee
Copy link
Contributor

Rindbee commented Sep 1, 2022

IMO, just make sure the theme-related data is set before entering the tree. And NOTIFICATION_PARENTED happens just before NOTIFICATION_ENTER_TREE. So, maybe we can try to put that propagation code in NOTIFICATION_PARENTED.

godot/scene/main/node.cpp

Lines 1122 to 1131 in 8c7be63

p_child->notification(NOTIFICATION_PARENTED);
if (data.tree) {
p_child->_set_tree(data.tree);
}
/* Notify */
//recognize children created in this node constructor
p_child->data.parent_owned = data.in_constructor;
add_child_notify(p_child);

@YuriSizov
Copy link
Contributor Author

YuriSizov commented Sep 1, 2022

IMO, just make sure the theme-related data is set before entering the tree.

Theme-related data cannot be set before entering the tree, because it is provided by parent controls.

Either way, this is unrelated to this series of PRs. We can revisit this when we make another attempt at #62846, as that's where the general systems would be affected. Here I'm improving code quality related to theme propagation, and by that virtue fix the issues.

@YuriSizov YuriSizov marked this pull request as ready for review September 1, 2022 21:07
@Rindbee
Copy link
Contributor

Rindbee commented Sep 1, 2022

Theme-related data cannot be set before entering the tree, because it is provided by parent controls.

I mean for the propagation code in add_child_notify, put them in notification(NOTIFICATION_PARENTED) instead. During NOTIFICATION_PARENTED, although it is not in the tree, it has been able to get the parent. And _propagate_theme_changed does not require the node to be in the tree, it can be considered as preprocessing before entering the tree..

godot/scene/gui/control.cpp

Lines 3092 to 3098 in c6fd311

void Control::add_child_notify(Node *p_child) {
// We propagate when this node uses a custom theme, so it can pass it on to its children.
if (data.theme_owner || data.theme_owner_window) {
// `p_notify` is false here as `NOTIFICATION_THEME_CHANGED` will be handled by `NOTIFICATION_ENTER_TREE`.
_propagate_theme_changed(p_child, data.theme_owner, data.theme_owner_window, false, true);
}
}

@YuriSizov
Copy link
Contributor Author

YuriSizov commented Sep 1, 2022

I mean for the propagation code in add_child_notify, put them in notification(NOTIFICATION_PARENTED) instead. During NOTIFICATION_PARENTED, although it is not in the tree, it has been able to get the parent.

Yes, that's a good idea and make sense. We can replace add_child_notify with handling NOTIFICATION_PARENTED and remove_child_notify with NOTIFICATION_UNPARENTED. Should be more or less the same, except it gets called before ENTER_TREE so we don't need to defer the call.

It's a bit tricky to do, not a one-to-one conversion, since we would have to perform this action from the child's POV instead of parent's. But I have an idea about that. I'll PR it tomorrow.

@Rindbee
Copy link
Contributor

Rindbee commented Sep 2, 2022

I have made a try in #65222.

@akien-mga akien-mga merged commit fe2cf6e into godotengine:master Sep 2, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment