Introduce the concept of global theme contexts
This commit adds the default theme context, which replaces the need to manually check the project and the default theme all the time; simplifies related code. It also adds framework for custom theme contexts, to be used by the editor. Custom contexts can be attached to any node, and not necessarily a GUI/Window node. Contexts do no break theme inheritance and only define which global themes a node uses as a fallback. Contexts propagate NOTIFICATION_THEME_CHANGED when one of their global themes changes. This ensures that global themes act just like themes assigned to individual nodes and can be previewed live in the editor.
This commit is contained in:
parent
8449592d92
commit
58126e479c
13 changed files with 487 additions and 246 deletions
|
|
@ -1269,7 +1269,9 @@ void Window::_notification(int p_what) {
|
|||
notification(NOTIFICATION_TRANSLATION_CHANGED);
|
||||
}
|
||||
#endif
|
||||
notification(NOTIFICATION_THEME_CHANGED);
|
||||
|
||||
// Emits NOTIFICATION_THEME_CHANGED internally.
|
||||
set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this));
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_READY: {
|
||||
|
|
@ -1313,6 +1315,8 @@ void Window::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
set_theme_context(nullptr, false);
|
||||
|
||||
if (transient) {
|
||||
_clear_transient();
|
||||
}
|
||||
|
|
@ -1889,6 +1893,11 @@ bool Window::has_theme_owner_node() const {
|
|||
return theme_owner->has_owner_node();
|
||||
}
|
||||
|
||||
void Window::set_theme_context(ThemeContext *p_context, bool p_propagate) {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
theme_owner->set_owner_context(p_context, p_propagate);
|
||||
}
|
||||
|
||||
void Window::set_theme(const Ref<Theme> &p_theme) {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
if (theme == p_theme) {
|
||||
|
|
@ -2887,7 +2896,7 @@ Window::Window() {
|
|||
max_size_used = max_size; // Update max_size_used.
|
||||
}
|
||||
|
||||
theme_owner = memnew(ThemeOwner);
|
||||
theme_owner = memnew(ThemeOwner(this));
|
||||
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue