summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-08-29 11:04:31 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-08-29 11:11:29 +0200
commitfd6453c45ec0da79f2c7794b1c94f31fd6e477d7 (patch)
treef924f74107842bd3c316f5c5c9ab5da810314c43 /scene/gui
parent223e083d36ac1ca3f7aa46898d8870e476132f7a (diff)
Revert "Remove NOTIFICATION_ENTER_TREE when paired with NOTIFICATION_THEME_CHANGED"
This reverts commit 4b817a565cab8af648c88cfc7ab6481e86ee3625. Fixes #64988. Fixes #64997. This caused several regressions (#64988, #64997, https://github.com/godotengine/godot/issues/64997#issuecomment-1229970605) which point at a flaw in the current logic: - `Control::NOTIFICATION_ENTER_TREE` triggers a *deferred* notification with `NOTIFCATION_THEME_CHANGED` as introduced in #62845. - Some classes use their `THEME_CHANGED` to cache theme items in member variables (e.g. `style_normal`, etc.), and use those member variables in `ENTER_TREE`, `READY`, `DRAW`, etc. Since the `THEME_CHANGE` notification is now deferred, they end up accessing invalid state and this can lead to not applying theme properly (e.g. for EditorHelp) or crashing (e.g. for EditorLog or CodeEdit). So we need to go back to the drawing board and see if `THEME_CHANGED` can be called earlier so that the previous logic still works? Or can we refactor all engine code to make sure that: - `ENTER_TREE` and similar do not depend on theme properties cached in member variables. - Or `THEME_CHANGE` does trigger a general UI update to make sure that any bad theme handling in `ENTER_TREE` and co. gets fixed when `THEME_CHANGE` does arrive for the first time. But that means having a temporary invalid (and possibly still crashing) state, and doing some computations twice which might be heavy (e.g. `EditorHelp::_update_doc()`).
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/code_edit.cpp3
-rw-r--r--scene/gui/color_picker.cpp4
-rw-r--r--scene/gui/control.h1
-rw-r--r--scene/gui/file_dialog.cpp98
-rw-r--r--scene/gui/file_dialog.h2
-rw-r--r--scene/gui/gradient_edit.cpp4
-rw-r--r--scene/gui/graph_edit.cpp1
-rw-r--r--scene/gui/popup.cpp3
-rw-r--r--scene/gui/scroll_container.cpp5
9 files changed, 65 insertions, 56 deletions
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index b9760499ef..e54ba7ce13 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -36,7 +36,8 @@
void CodeEdit::_notification(int p_what) {
switch (p_what) {
- case NOTIFICATION_THEME_CHANGED: {
+ case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_ENTER_TREE: {
style_normal = get_theme_stylebox(SNAME("normal"));
font = get_theme_font(SNAME("font"));
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index ed42d1c5ea..a417e7b9e2 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -63,8 +63,8 @@ void ColorPicker::_notification(int p_what) {
}
}
#endif
- } break;
-
+ [[fallthrough]];
+ }
case NOTIFICATION_THEME_CHANGED: {
btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
btn_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 66cd15542a..6215594ae0 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -357,7 +357,6 @@ public:
NOTIFICATION_MOUSE_EXIT = 42,
NOTIFICATION_FOCUS_ENTER = 43,
NOTIFICATION_FOCUS_EXIT = 44,
- // This doesn't need to be paired with `NOTIFICATION_ENTER_TREE`.
NOTIFICATION_THEME_CHANGED = 45,
NOTIFICATION_SCROLL_BEGIN = 47,
NOTIFICATION_SCROLL_END = 48,
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index ab2c19e9b1..57655afb4c 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -59,6 +59,38 @@ VBoxContainer *FileDialog::get_vbox() {
return vbox;
}
+void FileDialog::_theme_changed() {
+ Color font_color = vbox->get_theme_color(SNAME("font_color"), SNAME("Button"));
+ Color font_hover_color = vbox->get_theme_color(SNAME("font_hover_color"), SNAME("Button"));
+ Color font_focus_color = vbox->get_theme_color(SNAME("font_focus_color"), SNAME("Button"));
+ Color font_pressed_color = vbox->get_theme_color(SNAME("font_pressed_color"), SNAME("Button"));
+
+ dir_up->add_theme_color_override("icon_normal_color", font_color);
+ dir_up->add_theme_color_override("icon_hover_color", font_hover_color);
+ dir_up->add_theme_color_override("icon_focus_color", font_focus_color);
+ dir_up->add_theme_color_override("icon_pressed_color", font_pressed_color);
+
+ dir_prev->add_theme_color_override("icon_color_normal", font_color);
+ dir_prev->add_theme_color_override("icon_color_hover", font_hover_color);
+ dir_prev->add_theme_color_override("icon_focus_color", font_focus_color);
+ dir_prev->add_theme_color_override("icon_color_pressed", font_pressed_color);
+
+ dir_next->add_theme_color_override("icon_color_normal", font_color);
+ dir_next->add_theme_color_override("icon_color_hover", font_hover_color);
+ dir_next->add_theme_color_override("icon_focus_color", font_focus_color);
+ dir_next->add_theme_color_override("icon_color_pressed", font_pressed_color);
+
+ refresh->add_theme_color_override("icon_normal_color", font_color);
+ refresh->add_theme_color_override("icon_hover_color", font_hover_color);
+ refresh->add_theme_color_override("icon_focus_color", font_focus_color);
+ refresh->add_theme_color_override("icon_pressed_color", font_pressed_color);
+
+ show_hidden->add_theme_color_override("icon_normal_color", font_color);
+ show_hidden->add_theme_color_override("icon_hover_color", font_hover_color);
+ show_hidden->add_theme_color_override("icon_focus_color", font_focus_color);
+ show_hidden->add_theme_color_override("icon_pressed_color", font_pressed_color);
+}
+
void FileDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -67,51 +99,22 @@ void FileDialog::_notification(int p_what) {
}
} break;
- case NOTIFICATION_TRANSLATION_CHANGED: {
- update_filters();
- } break;
-
- case NOTIFICATION_THEME_CHANGED: {
- dir_up->set_icon(get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
+ case NOTIFICATION_ENTER_TREE: {
+ dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
if (vbox->is_layout_rtl()) {
- dir_prev->set_icon(get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
- dir_next->set_icon(get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
} else {
- dir_prev->set_icon(get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
- dir_next->set_icon(get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
}
- refresh->set_icon(get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
- show_hidden->set_icon(get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
-
- Color font_color = get_theme_color(SNAME("font_color"), SNAME("Button"));
- Color font_hover_color = get_theme_color(SNAME("font_hover_color"), SNAME("Button"));
- Color font_focus_color = get_theme_color(SNAME("font_focus_color"), SNAME("Button"));
- Color font_pressed_color = get_theme_color(SNAME("font_pressed_color"), SNAME("Button"));
-
- dir_up->add_theme_color_override("icon_normal_color", font_color);
- dir_up->add_theme_color_override("icon_hover_color", font_hover_color);
- dir_up->add_theme_color_override("icon_focus_color", font_focus_color);
- dir_up->add_theme_color_override("icon_pressed_color", font_pressed_color);
-
- dir_prev->add_theme_color_override("icon_color_normal", font_color);
- dir_prev->add_theme_color_override("icon_color_hover", font_hover_color);
- dir_prev->add_theme_color_override("icon_focus_color", font_focus_color);
- dir_prev->add_theme_color_override("icon_color_pressed", font_pressed_color);
-
- dir_next->add_theme_color_override("icon_color_normal", font_color);
- dir_next->add_theme_color_override("icon_color_hover", font_hover_color);
- dir_next->add_theme_color_override("icon_focus_color", font_focus_color);
- dir_next->add_theme_color_override("icon_color_pressed", font_pressed_color);
-
- refresh->add_theme_color_override("icon_normal_color", font_color);
- refresh->add_theme_color_override("icon_hover_color", font_hover_color);
- refresh->add_theme_color_override("icon_focus_color", font_focus_color);
- refresh->add_theme_color_override("icon_pressed_color", font_pressed_color);
-
- show_hidden->add_theme_color_override("icon_normal_color", font_color);
- show_hidden->add_theme_color_override("icon_hover_color", font_hover_color);
- show_hidden->add_theme_color_override("icon_focus_color", font_focus_color);
- show_hidden->add_theme_color_override("icon_pressed_color", font_pressed_color);
+ refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
+ show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
+ _theme_changed();
+ } break;
+
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ update_filters();
} break;
}
}
@@ -503,10 +506,10 @@ void FileDialog::update_file_list() {
}
TreeItem *root = tree->create_item();
- Ref<Texture2D> folder = get_theme_icon(SNAME("folder"), SNAME("FileDialog"));
- Ref<Texture2D> file_icon = get_theme_icon(SNAME("file"), SNAME("FileDialog"));
- const Color folder_color = get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog"));
- const Color file_color = get_theme_color(SNAME("file_icon_modulate"), SNAME("FileDialog"));
+ Ref<Texture2D> folder = vbox->get_theme_icon(SNAME("folder"), SNAME("FileDialog"));
+ Ref<Texture2D> file_icon = vbox->get_theme_icon(SNAME("file"), SNAME("FileDialog"));
+ const Color folder_color = vbox->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog"));
+ const Color file_color = vbox->get_theme_color(SNAME("file_icon_modulate"), SNAME("FileDialog"));
List<String> files;
List<String> dirs;
@@ -603,7 +606,7 @@ void FileDialog::update_file_list() {
ti->set_icon_modulate(0, file_color);
if (mode == FILE_MODE_OPEN_DIR) {
- ti->set_custom_color(0, get_theme_color(SNAME("files_disabled"), SNAME("FileDialog")));
+ ti->set_custom_color(0, vbox->get_theme_color(SNAME("files_disabled"), SNAME("FileDialog")));
ti->set_selectable(0, false);
}
Dictionary d;
@@ -1003,6 +1006,7 @@ FileDialog::FileDialog() {
vbox = memnew(VBoxContainer);
add_child(vbox, false, INTERNAL_MODE_FRONT);
+ vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed));
mode = FILE_MODE_SAVE_FILE;
set_title(TTRC("Save a File"));
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 4ea39691c1..4945094086 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -143,6 +143,8 @@ private:
virtual void _post_popup() override;
protected:
+ void _theme_changed();
+
void _notification(int p_what);
static void _bind_methods();
//bind helpers
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index be097f7543..cc27a6b7c2 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -292,8 +292,8 @@ void GradientEdit::_notification(int p_what) {
if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
}
- } break;
-
+ [[fallthrough]];
+ }
case NOTIFICATION_THEME_CHANGED: {
draw_spacing = BASE_SPACING * get_theme_default_base_scale();
draw_point_width = BASE_POINT_WIDTH * get_theme_default_base_scale();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index a556514e0d..00f2e48601 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -424,6 +424,7 @@ void GraphEdit::remove_child_notify(Node *p_child) {
void GraphEdit::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
port_hotzone_inner_extent = get_theme_constant("port_hotzone_inner_extent");
port_hotzone_outer_extent = get_theme_constant("port_hotzone_outer_extent");
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 7461f48a6c..c4396f636a 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -240,7 +240,8 @@ void PopupPanel::_notification(int p_what) {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
} break;
- case NOTIFICATION_ENTER_TREE: {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_READY: {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
_update_child_rects();
} break;
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index f58cb0fe70..8fd547813d 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -317,9 +317,10 @@ void ScrollContainer::_reposition_children() {
void ScrollContainer::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
- case NOTIFICATION_TRANSLATION_CHANGED:
- case NOTIFICATION_THEME_CHANGED: {
+ case NOTIFICATION_TRANSLATION_CHANGED: {
_updating_scrollbars = true;
call_deferred(SNAME("_update_scrollbar_position"));
} break;