From fd6453c45ec0da79f2c7794b1c94f31fd6e477d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 29 Aug 2022 11:04:31 +0200 Subject: [PATCH] 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()`). --- editor/action_map_editor.cpp | 2 + editor/animation_bezier_editor.cpp | 4 +- editor/animation_track_editor.cpp | 5 +- editor/code_editor.cpp | 4 + editor/connections_dialog.cpp | 4 +- editor/create_dialog.cpp | 9 +- editor/create_dialog.h | 2 + editor/debugger/editor_network_profiler.cpp | 1 + editor/debugger/editor_profiler.cpp | 5 +- editor/debugger/editor_visual_profiler.cpp | 5 +- editor/debugger/script_editor_debugger.cpp | 4 +- editor/editor_about.cpp | 25 +++-- editor/editor_about.h | 2 + editor/editor_audio_buses.cpp | 2 + editor/editor_autoload_settings.cpp | 1 + editor/editor_file_dialog.cpp | 1 + editor/editor_help.cpp | 51 +++++---- editor/editor_help.h | 1 + editor/editor_inspector.cpp | 2 + editor/editor_log.cpp | 74 +++++++------ editor/editor_log.h | 2 + editor/editor_path.cpp | 1 + editor/editor_properties.cpp | 28 ++++- editor/editor_properties_array_dict.cpp | 9 +- editor/editor_resource_picker.cpp | 5 +- editor/editor_spin_slider.cpp | 1 + editor/editor_toaster.cpp | 1 + editor/editor_zoom_widget.cpp | 1 + editor/export/export_template_manager.cpp | 1 + editor/groups_editor.cpp | 1 + .../import/audio_stream_import_settings.cpp | 3 +- .../import/dynamic_font_import_settings.cpp | 1 + editor/node_dock.cpp | 1 + editor/plugins/abstract_polygon_2d_editor.cpp | 1 + .../animation_blend_space_1d_editor.cpp | 1 + .../animation_blend_space_2d_editor.cpp | 1 + .../animation_blend_tree_editor_plugin.cpp | 9 +- .../animation_blend_tree_editor_plugin.h | 1 + .../animation_state_machine_editor.cpp | 5 +- .../plugins/asset_library_editor_plugin.cpp | 3 + editor/plugins/canvas_item_editor_plugin.cpp | 23 ++-- editor/plugins/canvas_item_editor_plugin.h | 1 + editor/plugins/control_editor_plugin.cpp | 5 + editor/plugins/font_config_plugin.cpp | 10 ++ editor/plugins/font_config_plugin.h | 1 + .../gradient_texture_2d_editor_plugin.cpp | 2 + editor/plugins/input_event_editor_plugin.cpp | 1 + editor/plugins/node_3d_editor_plugin.cpp | 72 +++++++------ editor/plugins/node_3d_editor_plugin.h | 2 + editor/plugins/path_2d_editor_plugin.cpp | 1 + editor/plugins/path_3d_editor_plugin.cpp | 2 + editor/plugins/polygon_2d_editor_plugin.cpp | 4 +- .../resource_preloader_editor_plugin.cpp | 1 + editor/plugins/root_motion_editor_plugin.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 10 +- editor/plugins/script_text_editor.cpp | 9 +- editor/plugins/shader_editor_plugin.cpp | 1 + editor/plugins/sprite_2d_editor_plugin.cpp | 1 + .../plugins/sprite_frames_editor_plugin.cpp | 1 + editor/plugins/style_box_editor_plugin.cpp | 8 ++ editor/plugins/texture_editor_plugin.cpp | 9 ++ .../plugins/texture_region_editor_plugin.cpp | 1 + editor/plugins/theme_editor_plugin.cpp | 11 +- editor/plugins/theme_editor_preview.cpp | 6 +- editor/plugins/tiles/tile_data_editors.cpp | 3 + editor/plugins/tiles/tile_map_editor.cpp | 3 + .../tiles/tile_set_atlas_source_editor.cpp | 1 + editor/plugins/tiles/tile_set_editor.cpp | 1 + ...le_set_scenes_collection_source_editor.cpp | 1 + .../plugins/visual_shader_editor_plugin.cpp | 9 +- editor/project_settings_editor.cpp | 35 +++--- editor/project_settings_editor.h | 1 + editor/scene_create_dialog.cpp | 1 + editor/scene_tree_editor.cpp | 7 +- editor/scene_tree_editor.h | 1 + editor/script_create_dialog.cpp | 3 +- editor/shader_create_dialog.cpp | 40 ++++--- editor/shader_create_dialog.h | 1 + .../gridmap/editor/grid_map_editor_plugin.cpp | 13 ++- .../gridmap/editor/grid_map_editor_plugin.h | 1 + .../openxr/editor/openxr_action_editor.cpp | 7 +- modules/openxr/editor/openxr_action_editor.h | 1 + .../editor/openxr_action_map_editor.cpp | 1 + .../editor/openxr_action_set_editor.cpp | 11 +- .../openxr/editor/openxr_action_set_editor.h | 1 + .../editor/openxr_select_action_dialog.cpp | 1 + ...enxr_select_interaction_profile_dialog.cpp | 1 + scene/gui/code_edit.cpp | 3 +- scene/gui/color_picker.cpp | 4 +- scene/gui/control.h | 1 - scene/gui/file_dialog.cpp | 100 +++++++++--------- scene/gui/file_dialog.h | 2 + scene/gui/gradient_edit.cpp | 4 +- scene/gui/graph_edit.cpp | 1 + scene/gui/popup.cpp | 3 +- scene/gui/scroll_container.cpp | 5 +- scene/main/window.h | 1 - tests/scene/test_code_edit.h | 4 - 98 files changed, 473 insertions(+), 262 deletions(-) diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index c8ab98a80fc..7cfedffcbff 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -577,6 +577,7 @@ String InputEventConfigurationDialog::_get_device_string(int p_device) const { void InputEventConfigurationDialog::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { input_list_search->set_right_icon(input_list_search->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); @@ -1057,6 +1058,7 @@ void ActionMapEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, void ActionMapEditor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { action_list_search->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); if (!actions_cache.is_empty()) { diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index c121ab42d3d..9af8b907c48 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -216,8 +216,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/animation_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); - } break; - + [[fallthrough]]; + } case NOTIFICATION_THEME_CHANGED: { bezier_icon = get_theme_icon(SNAME("KeyBezierPoint"), SNAME("EditorIcons")); bezier_handle_icon = get_theme_icon(SNAME("KeyBezierHandle"), SNAME("EditorIcons")); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 379e2cb5109..64221b83306 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1489,6 +1489,7 @@ int AnimationTimelineEdit::get_name_limit() const { void AnimationTimelineEdit::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/animation_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); add_track->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); @@ -4758,8 +4759,8 @@ void AnimationTrackEditor::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { panner->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/animation_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning"))); - } break; - + [[fallthrough]]; + } case NOTIFICATION_THEME_CHANGED: { zoom_icon->set_texture(get_theme_icon(SNAME("Zoom"), SNAME("EditorIcons"))); bezier_edit_icon->set_icon(get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons"))); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 9dddcbbebaa..2b1584b20c8 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -1740,6 +1740,10 @@ void CodeTextEditor::_update_status_bar_theme() { void CodeTextEditor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + _update_status_bar_theme(); + } break; + case NOTIFICATION_THEME_CHANGED: { _update_status_bar_theme(); if (toggle_scripts_button->is_visible()) { diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index bfa9081af25..587c16c229d 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -230,8 +230,9 @@ void ConnectDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { bind_editor->edit(cdbinds); - } break; + [[fallthrough]]; + } case NOTIFICATION_THEME_CHANGED: { for (int i = 0; i < type_list->get_item_count(); i++) { String type_name = Variant::get_type_name((Variant::Type)type_list->get_item_id(i)); @@ -912,6 +913,7 @@ void ConnectionsDock::_connect_pressed() { void ConnectionsDock::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); } break; diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 02ce081c02e..03e636d43ad 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -423,10 +423,16 @@ void CreateDialog::_sbox_input(const Ref &p_ie) { } } +void CreateDialog::_update_theme() { + search_box->set_right_icon(search_options->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + favorite->set_icon(search_options->get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons"))); +} + void CreateDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { connect("confirmed", callable_mp(this, &CreateDialog::_confirmed)); + _update_theme(); } break; case NOTIFICATION_EXIT_TREE: { @@ -443,8 +449,7 @@ void CreateDialog::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - search_box->set_right_icon(search_options->get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); - favorite->set_icon(search_options->get_theme_icon(SNAME("Favorites"), SNAME("EditorIcons"))); + _update_theme(); } break; } } diff --git a/editor/create_dialog.h b/editor/create_dialog.h index 9a17993e11d..f7731d2726b 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -101,6 +101,8 @@ class CreateDialog : public ConfirmationDialog { bool _is_class_disabled_by_feature_profile(const StringName &p_class) const; void _load_favorites_and_history(); + void _update_theme(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/debugger/editor_network_profiler.cpp b/editor/debugger/editor_network_profiler.cpp index 185553cac05..8c18eba71d6 100644 --- a/editor/debugger/editor_network_profiler.cpp +++ b/editor/debugger/editor_network_profiler.cpp @@ -40,6 +40,7 @@ void EditorNetworkProfiler::_bind_methods() { void EditorNetworkProfiler::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons"))); clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 30197e6d8b1..b49cab9df73 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -394,9 +394,10 @@ void EditorProfiler::_clear_pressed() { void EditorProfiler::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: - case NOTIFICATION_TRANSLATION_CHANGED: - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_TRANSLATION_CHANGED: { activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons"))); clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); } break; diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index df1a59cc99a..6f3dd1793cd 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -424,9 +424,10 @@ void EditorVisualProfiler::_clear_pressed() { void EditorVisualProfiler::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: - case NOTIFICATION_TRANSLATION_CHANGED: - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_TRANSLATION_CHANGED: { if (is_layout_rtl()) { activate->set_icon(get_theme_icon(SNAME("PlayBackwards"), SNAME("EditorIcons"))); } else { diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 1036561a479..fab211f18c6 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -787,8 +787,8 @@ void ScriptEditorDebugger::_notification(int p_what) { error_tree->connect("item_selected", callable_mp(this, &ScriptEditorDebugger::_error_selected)); error_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_error_activated)); breakpoints_tree->connect("item_activated", callable_mp(this, &ScriptEditorDebugger::_breakpoint_tree_clicked)); - } break; - + [[fallthrough]]; + } case NOTIFICATION_THEME_CHANGED: { skip_breakpoints->set_icon(get_theme_icon(skip_breakpoints_value ? SNAME("DebugSkipBreakpointsOn") : SNAME("DebugSkipBreakpointsOff"), SNAME("EditorIcons"))); copy->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons"))); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index cdf300e288a..7baaffb1be9 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -38,18 +38,22 @@ // The metadata key used to store and retrieve the version text to copy to the clipboard. static const String META_TEXT_TO_COPY = "text_to_copy"; +void EditorAbout::_theme_changed() { + const Ref font = get_theme_font(SNAME("source"), SNAME("EditorFonts")); + const int font_size = get_theme_font_size(SNAME("source_size"), SNAME("EditorFonts")); + _tpl_text->add_theme_font_override("normal_font", font); + _tpl_text->add_theme_font_size_override("normal_font_size", font_size); + _tpl_text->add_theme_constant_override("line_separation", 4 * EDSCALE); + _license_text->add_theme_font_override("normal_font", font); + _license_text->add_theme_font_size_override("normal_font_size", font_size); + _license_text->add_theme_constant_override("line_separation", 4 * EDSCALE); + _logo->set_texture(get_theme_icon(SNAME("Logo"), SNAME("EditorIcons"))); +} + void EditorAbout::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { - const Ref font = get_theme_font(SNAME("source"), SNAME("EditorFonts")); - const int font_size = get_theme_font_size(SNAME("source_size"), SNAME("EditorFonts")); - _tpl_text->add_theme_font_override("normal_font", font); - _tpl_text->add_theme_font_size_override("normal_font_size", font_size); - _tpl_text->add_theme_constant_override("line_separation", 4 * EDSCALE); - _license_text->add_theme_font_override("normal_font", font); - _license_text->add_theme_font_size_override("normal_font_size", font_size); - _license_text->add_theme_constant_override("line_separation", 4 * EDSCALE); - _logo->set_texture(get_theme_icon(SNAME("Logo"), SNAME("EditorIcons"))); + case NOTIFICATION_ENTER_TREE: { + _theme_changed(); } break; } } @@ -116,6 +120,7 @@ EditorAbout::EditorAbout() { set_hide_on_ok(true); VBoxContainer *vbc = memnew(VBoxContainer); + vbc->connect("theme_changed", callable_mp(this, &EditorAbout::_theme_changed)); HBoxContainer *hbc = memnew(HBoxContainer); hbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); hbc->set_alignment(BoxContainer::ALIGNMENT_CENTER); diff --git a/editor/editor_about.h b/editor/editor_about.h index b152f1b4d32..971843f6d22 100644 --- a/editor/editor_about.h +++ b/editor/editor_about.h @@ -62,6 +62,8 @@ private: RichTextLabel *_tpl_text = nullptr; TextureRect *_logo = nullptr; + void _theme_changed(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index cc65cddfb27..a95cc4981a6 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -66,6 +66,7 @@ void EditorAudioBus::_update_visible_channels() { void EditorAudioBus::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { for (int i = 0; i < CHANNELS_MAX; i++) { channel[i].vu_l->set_under_texture(get_theme_icon(SNAME("BusVuEmpty"), SNAME("EditorIcons"))); @@ -1024,6 +1025,7 @@ EditorAudioBuses *EditorAudioBuses::register_editor() { void EditorAudioBuses::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { bus_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); } break; diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 7dff0d54f78..120ac5b984a 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -59,6 +59,7 @@ void EditorAutoloadSettings::_notification(int p_what) { get_tree()->get_root()->call_deferred(SNAME("add_child"), info.node); } } + browse_button->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); } break; case NOTIFICATION_THEME_CHANGED: { diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index cc0f60fee57..5d249b0fabe 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -70,6 +70,7 @@ VBoxContainer *EditorFileDialog::get_vbox() { void EditorFileDialog::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_READY: case NOTIFICATION_THEME_CHANGED: case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_TRANSLATION_CHANGED: { diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 29a0781e96d..fe03166a011 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -44,6 +44,29 @@ DocTools *EditorHelp::doc = nullptr; +void EditorHelp::_update_theme() { + text_color = get_theme_color(SNAME("text_color"), SNAME("EditorHelp")); + title_color = get_theme_color(SNAME("title_color"), SNAME("EditorHelp")); + headline_color = get_theme_color(SNAME("headline_color"), SNAME("EditorHelp")); + comment_color = get_theme_color(SNAME("comment_color"), SNAME("EditorHelp")); + symbol_color = get_theme_color(SNAME("symbol_color"), SNAME("EditorHelp")); + value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp")); + qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp")); + type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp")); + + class_desc->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp"))); + class_desc->add_theme_constant_override("line_separation", get_theme_constant(SNAME("line_separation"), SNAME("EditorHelp"))); + class_desc->add_theme_constant_override("table_h_separation", get_theme_constant(SNAME("table_h_separation"), SNAME("EditorHelp"))); + class_desc->add_theme_constant_override("table_v_separation", get_theme_constant(SNAME("table_v_separation"), SNAME("EditorHelp"))); + + doc_font = get_theme_font(SNAME("doc"), SNAME("EditorFonts")); + doc_bold_font = get_theme_font(SNAME("doc_bold"), SNAME("EditorFonts")); + doc_title_font = get_theme_font(SNAME("doc_title"), SNAME("EditorFonts")); + doc_code_font = get_theme_font(SNAME("doc_source"), SNAME("EditorFonts")); + + doc_title_font_size = get_theme_font_size(SNAME("doc_title_size"), SNAME("EditorFonts")); +} + void EditorHelp::_search(bool p_search_previous) { if (p_search_previous) { find_bar->search_prev(); @@ -523,6 +546,7 @@ void EditorHelp::_update_doc() { method_line.clear(); section_line.clear(); + _update_theme(); String link_color_text = title_color.to_html(false); DocData::ClassDoc cd = doc->class_list[edited_class]; // Make a copy, so we can sort without worrying. @@ -1985,29 +2009,10 @@ void EditorHelp::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - _class_desc_resized(true); + if (is_inside_tree()) { + _class_desc_resized(true); + } update_toggle_scripts_button(); - - text_color = get_theme_color(SNAME("text_color"), SNAME("EditorHelp")); - title_color = get_theme_color(SNAME("title_color"), SNAME("EditorHelp")); - headline_color = get_theme_color(SNAME("headline_color"), SNAME("EditorHelp")); - comment_color = get_theme_color(SNAME("comment_color"), SNAME("EditorHelp")); - symbol_color = get_theme_color(SNAME("symbol_color"), SNAME("EditorHelp")); - value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp")); - qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp")); - type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp")); - - class_desc->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp"))); - class_desc->add_theme_constant_override("line_separation", get_theme_constant(SNAME("line_separation"), SNAME("EditorHelp"))); - class_desc->add_theme_constant_override("table_h_separation", get_theme_constant(SNAME("table_h_separation"), SNAME("EditorHelp"))); - class_desc->add_theme_constant_override("table_v_separation", get_theme_constant(SNAME("table_v_separation"), SNAME("EditorHelp"))); - - doc_font = get_theme_font(SNAME("doc"), SNAME("EditorFonts")); - doc_bold_font = get_theme_font(SNAME("doc_bold"), SNAME("EditorFonts")); - doc_title_font = get_theme_font(SNAME("doc_title"), SNAME("EditorFonts")); - doc_code_font = get_theme_font(SNAME("doc_source"), SNAME("EditorFonts")); - - doc_title_font_size = get_theme_font_size(SNAME("doc_title_size"), SNAME("EditorFonts")); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -2185,6 +2190,7 @@ void EditorHelpBit::_bind_methods() { void EditorHelpBit::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { rich_text->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp"))); rich_text->clear(); @@ -2266,6 +2272,7 @@ void FindBar::popup_search() { void FindBar::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { find_prev->set_icon(get_theme_icon(SNAME("MoveUp"), SNAME("EditorIcons"))); find_next->set_icon(get_theme_icon(SNAME("MoveDown"), SNAME("EditorIcons"))); diff --git a/editor/editor_help.h b/editor/editor_help.h index 20eb7f78fc4..c9c1afb51b4 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -145,6 +145,7 @@ class EditorHelp : public VBoxContainer { int scroll_to = -1; + void _update_theme(); void _help_callback(const String &p_topic); void _add_text(const String &p_bbcode); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 21dbb5ab978..8716196658d 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -2175,6 +2175,7 @@ bool EditorInspectorArray::can_drop_data_fw(const Point2 &p_point, const Variant void EditorInspectorArray::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { Color color = get_theme_color(SNAME("dark_color_1"), SNAME("Editor")); odd_style->set_bg_color(color.darkened(-0.08)); @@ -2368,6 +2369,7 @@ void EditorPaginator::update(int p_page, int p_max_page) { void EditorPaginator::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { first_page_button->set_icon(get_theme_icon(SNAME("PageFirst"), SNAME("EditorIcons"))); prev_page_button->set_icon(get_theme_icon(SNAME("PagePrevious"), SNAME("EditorIcons"))); diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index dbb6706cb37..86b01452408 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -64,48 +64,52 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f } } +void EditorLog::_update_theme() { + Ref normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts")); + if (normal_font.is_valid()) { + log->add_theme_font_override("normal_font", normal_font); + } + + log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); + log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4)); + + Ref bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); + if (bold_font.is_valid()) { + log->add_theme_font_override("bold_font", bold_font); + } + + type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); + + type_filter_map[MSG_TYPE_STD]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); + type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); + type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); + type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); + + clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); + copy_button->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons"))); + collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons"))); + show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); + + theme_cache.error_color = get_theme_color(SNAME("error_color"), SNAME("Editor")); + theme_cache.error_icon = get_theme_icon(SNAME("Error"), SNAME("EditorIcons")); + theme_cache.warning_color = get_theme_color(SNAME("warning_color"), SNAME("Editor")); + theme_cache.warning_icon = get_theme_icon(SNAME("Warning"), SNAME("EditorIcons")); + theme_cache.message_color = get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6); +} + void EditorLog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { + _update_theme(); _load_state(); } break; case NOTIFICATION_THEME_CHANGED: { - Ref normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts")); - if (normal_font.is_valid()) { - log->add_theme_font_override("normal_font", normal_font); - } - - log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); - log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4)); - - Ref bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); - if (bold_font.is_valid()) { - log->add_theme_font_override("bold_font", bold_font); - } - - type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); - - type_filter_map[MSG_TYPE_STD]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); - type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); - type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); - type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_theme_type_variation("EditorLogFilterButton"); - - clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); - copy_button->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons"))); - collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons"))); - show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); - search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); - - theme_cache.error_color = get_theme_color(SNAME("error_color"), SNAME("Editor")); - theme_cache.error_icon = get_theme_icon(SNAME("Error"), SNAME("EditorIcons")); - theme_cache.warning_color = get_theme_color(SNAME("warning_color"), SNAME("Editor")); - theme_cache.warning_icon = get_theme_icon(SNAME("Warning"), SNAME("EditorIcons")); - theme_cache.message_color = get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6); - + _update_theme(); _rebuild_log(); } break; } diff --git a/editor/editor_log.h b/editor/editor_log.h index 0e17eb7949f..43d70374145 100644 --- a/editor/editor_log.h +++ b/editor/editor_log.h @@ -175,6 +175,8 @@ private: void _save_state(); void _load_state(); + void _update_theme(); + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index b8b6d57c08a..a8f8f7ab970 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -182,6 +182,7 @@ void EditorPath::_id_pressed(int p_idx) { void EditorPath::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { update_path(); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index c3fd46c5119..0e69c0e2f45 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -167,7 +167,8 @@ void EditorPropertyMultilineText::update_property() { void EditorPropertyMultilineText::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { Ref df = get_theme_icon(SNAME("DistractionFree"), SNAME("EditorIcons")); open_big_text->set_icon(df); @@ -321,6 +322,7 @@ void EditorPropertyTextEnum::_bind_methods() { void EditorPropertyTextEnum::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { edit_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); accept_button->set_icon(get_theme_icon(SNAME("ImportCheck"), SNAME("EditorIcons"))); @@ -402,6 +404,7 @@ void EditorPropertyLocale::setup(const String &p_hint_text) { void EditorPropertyLocale::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { locale_edit->set_icon(get_theme_icon(SNAME("Translation"), SNAME("EditorIcons"))); } break; @@ -497,6 +500,7 @@ void EditorPropertyPath::set_save_mode() { void EditorPropertyPath::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { path_edit->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); } break; @@ -1149,6 +1153,7 @@ void EditorPropertyLayersGrid::_bind_methods() { void EditorPropertyLayers::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { button->set_normal_texture(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); button->set_pressed_texture(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); @@ -1672,7 +1677,8 @@ void EditorPropertyEasing::setup(bool p_positive_only, bool p_flip) { void EditorPropertyEasing::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { preset->clear(); preset->add_icon_item(get_theme_icon(SNAME("CurveLinear"), SNAME("EditorIcons")), "Linear", EASING_LINEAR); preset->add_icon_item(get_theme_icon(SNAME("CurveIn"), SNAME("EditorIcons")), "Ease In", EASING_IN); @@ -1769,6 +1775,7 @@ void EditorPropertyVector2::_update_ratio() { void EditorPropertyVector2::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons"))); linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); @@ -1878,6 +1885,7 @@ void EditorPropertyRect2::update_property() { void EditorPropertyRect2::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -2045,6 +2053,7 @@ Vector3 EditorPropertyVector3::get_vector() { void EditorPropertyVector3::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons"))); linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); @@ -2179,6 +2188,7 @@ void EditorPropertyVector2i::_update_ratio() { void EditorPropertyVector2i::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons"))); linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); @@ -2288,6 +2298,7 @@ void EditorPropertyRect2i::update_property() { void EditorPropertyRect2i::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -2428,6 +2439,7 @@ void EditorPropertyVector3i::_update_ratio() { void EditorPropertyVector3i::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { linked->set_normal_texture(get_theme_icon(SNAME("Unlinked"), SNAME("EditorIcons"))); linked->set_pressed_texture(get_theme_icon(SNAME("Instance"), SNAME("EditorIcons"))); @@ -2539,6 +2551,7 @@ void EditorPropertyPlane::update_property() { void EditorPropertyPlane::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -2692,6 +2705,7 @@ void EditorPropertyQuaternion::_warning_pressed() { void EditorPropertyQuaternion::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -2846,6 +2860,7 @@ void EditorPropertyVector4::update_property() { void EditorPropertyVector4::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -2937,6 +2952,7 @@ void EditorPropertyVector4i::update_property() { void EditorPropertyVector4i::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 4; i++) { @@ -3031,6 +3047,7 @@ void EditorPropertyAABB::update_property() { void EditorPropertyAABB::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 6; i++) { @@ -3113,6 +3130,7 @@ void EditorPropertyTransform2D::update_property() { void EditorPropertyTransform2D::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 6; i++) { @@ -3209,6 +3227,7 @@ void EditorPropertyBasis::update_property() { void EditorPropertyBasis::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 9; i++) { @@ -3306,6 +3325,7 @@ void EditorPropertyTransform3D::update_using_transform(Transform3D p_transform) void EditorPropertyTransform3D::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 12; i++) { @@ -3411,6 +3431,7 @@ void EditorPropertyProjection::update_using_transform(Projection p_transform) { void EditorPropertyProjection::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { const Color *colors = _get_property_colors(); for (int i = 0; i < 16; i++) { @@ -3481,6 +3502,7 @@ void EditorPropertyColor::_picker_opening() { void EditorPropertyColor::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { picker->set_custom_minimum_size(Size2(0, get_theme_constant(SNAME("color_picker_button_height"), SNAME("Editor")))); } break; @@ -3704,6 +3726,7 @@ void EditorPropertyNodePath::setup(const NodePath &p_base_hint, Vector t = get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")); clear->set_icon(t); @@ -4115,6 +4138,7 @@ void EditorPropertyResource::set_use_sub_inspector(bool p_enable) { void EditorPropertyResource::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_THEME_CHANGED: { if (!updating_theme) { _update_property_bg(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index fa7e5cf4a9b..f6953e88661 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -485,7 +485,8 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d void EditorPropertyArray::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { change_type->clear(); for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) { @@ -1165,7 +1166,8 @@ void EditorPropertyDictionary::_object_id_selected(const StringName &p_property, void EditorPropertyDictionary::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { change_type->clear(); for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (i == Variant::CALLABLE || i == Variant::SIGNAL || i == Variant::RID) { @@ -1403,7 +1405,8 @@ void EditorPropertyLocalizableString::_object_id_selected(const StringName &p_pr void EditorPropertyLocalizableString::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_THEME_CHANGED: { + case NOTIFICATION_THEME_CHANGED: + case NOTIFICATION_ENTER_TREE: { if (Object::cast_to