Skip to content

Commit

Permalink
Revert "Remove NOTIFICATION_ENTER_TREE when paired with NOTIFICATION_…
Browse files Browse the repository at this point in the history
…THEME_CHANGED"

This reverts commit 4b817a5.

Fixes godotengine#64988.
Fixes godotengine#64997.

This caused several regressions (godotengine#64988, godotengine#64997,
godotengine#64997 (comment))
which point at a flaw in the current logic:

- `Control::NOTIFICATION_ENTER_TREE` triggers a *deferred* notification with
  `NOTIFCATION_THEME_CHANGED` as introduced in godotengine#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()`).
  • Loading branch information
akien-mga committed Aug 29, 2022
1 parent 223e083 commit fd6453c
Show file tree
Hide file tree
Showing 98 changed files with 470 additions and 259 deletions.
2 changes: 2 additions & 0 deletions editor/action_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));

Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
5 changes: 3 additions & 2 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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")));
Expand Down
4 changes: 4 additions & 0 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 3 additions & 1 deletion editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,16 @@ void CreateDialog::_sbox_input(const Ref<InputEvent> &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: {
Expand All @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions editor/create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions editor/debugger/editor_network_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
5 changes: 3 additions & 2 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions editor/debugger/editor_visual_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
25 changes: 15 additions & 10 deletions editor/editor_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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> 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;
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_about.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class EditorAbout : public AcceptDialog {
RichTextLabel *_tpl_text = nullptr;
TextureRect *_logo = nullptr;

void _theme_changed();

protected:
void _notification(int p_what);
static void _bind_methods();
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
51 changes: 29 additions & 22 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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")));
Expand Down
1 change: 1 addition & 0 deletions editor/editor_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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")));
Expand Down
Loading

0 comments on commit fd6453c

Please sign in to comment.