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

Add bulk change guards to successive theme overrides in Editor and GUI #83626

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@ void CodeTextEditor::_update_text_editor_theme() {
int status_bar_font_size = get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts));
error->add_theme_font_override("font", status_bar_font);
error->add_theme_font_size_override("font_size", status_bar_font_size);
error->end_bulk_theme_override();

int count = status_bar->get_child_count();
for (int i = 0; i < count; i++) {
Control *n = Object::cast_to<Control>(status_bar->get_child(i));
Expand All @@ -1726,7 +1728,6 @@ void CodeTextEditor::_update_text_editor_theme() {
n->add_theme_font_size_override("font_size", status_bar_font_size);
}
}
error->end_bulk_theme_override();
}

void CodeTextEditor::_on_settings_change() {
Expand Down Expand Up @@ -1834,25 +1835,28 @@ void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) {

void CodeTextEditor::_update_status_bar_theme() {
error_button->set_icon(get_editor_theme_icon(SNAME("StatusError")));
warning_button->set_icon(get_editor_theme_icon(SNAME("NodeWarning")));

error_button->begin_bulk_theme_override();
error_button->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
error_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
error_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
error_button->end_bulk_theme_override();

warning_button->set_icon(get_editor_theme_icon(SNAME("NodeWarning")));
warning_button->begin_bulk_theme_override();
warning_button->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
warning_button->add_theme_font_override("font", get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
warning_button->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
warning_button->end_bulk_theme_override();

line_and_col_txt->begin_bulk_theme_override();
line_and_col_txt->add_theme_font_override("font", get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
line_and_col_txt->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
line_and_col_txt->end_bulk_theme_override();
}

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
7 changes: 7 additions & 0 deletions editor/editor_about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ const String EditorAbout::META_TEXT_TO_COPY = "text_to_copy";
void EditorAbout::_theme_changed() {
const Ref<Font> font = get_theme_font(SNAME("source"), EditorStringName(EditorFonts));
const int font_size = get_theme_font_size(SNAME("source_size"), EditorStringName(EditorFonts));

_tpl_text->begin_bulk_theme_override();
_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);
_tpl_text->end_bulk_theme_override();

_license_text->begin_bulk_theme_override();
_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);
_license_text->end_bulk_theme_override();

_logo->set_texture(get_editor_theme_icon(SNAME("Logo")));
}

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 @@ -828,10 +828,12 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
for (int i = 0; i < hbc->get_child_count(); i++) {
Control *child = Object::cast_to<Control>(hbc->get_child(i));
child->begin_bulk_theme_override();
child->add_theme_style_override("normal", sbempty);
child->add_theme_style_override("hover", sbempty);
child->add_theme_style_override("focus", sbempty);
child->add_theme_style_override("pressed", sbempty);
child->end_bulk_theme_override();
}

HSeparator *separator = memnew(HSeparator);
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void EditorHelp::_update_theme_item_cache() {

theme_cache.background_style = get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"));

class_desc->begin_bulk_theme_override();
class_desc->add_theme_font_override("normal_font", theme_cache.doc_font);
class_desc->add_theme_font_size_override("normal_font_size", theme_cache.doc_font_size);

Expand All @@ -168,6 +169,7 @@ void EditorHelp::_update_theme_item_cache() {
class_desc->add_theme_constant_override("table_v_separation", get_theme_constant(SNAME("table_v_separation"), SNAME("EditorHelp")));
class_desc->add_theme_constant_override("text_highlight_h_padding", get_theme_constant(SNAME("text_highlight_h_padding"), SNAME("EditorHelp")));
class_desc->add_theme_constant_override("text_highlight_v_padding", get_theme_constant(SNAME("text_highlight_v_padding"), SNAME("EditorHelp")));
class_desc->end_bulk_theme_override();
}

void EditorHelp::_search(bool p_search_previous) {
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,10 +2104,12 @@ void EditorInspectorArray::_setup() {
ae.margin->set_mouse_filter(MOUSE_FILTER_PASS);
if (is_inside_tree()) {
Size2 min_size = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles))->get_minimum_size();
ae.margin->begin_bulk_theme_override();
ae.margin->add_theme_constant_override("margin_left", min_size.x / 2);
ae.margin->add_theme_constant_override("margin_top", min_size.y / 2);
ae.margin->add_theme_constant_override("margin_right", min_size.x / 2);
ae.margin->add_theme_constant_override("margin_bottom", min_size.y / 2);
ae.margin->end_bulk_theme_override();
}
ae.panel->add_child(ae.margin);

Expand Down Expand Up @@ -2252,10 +2254,12 @@ void EditorInspectorArray::_notification(int p_what) {
ae.move_down->set_icon(get_editor_theme_icon(SNAME("MoveDown")));
}
Size2 min_size = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles))->get_minimum_size();
ae.margin->begin_bulk_theme_override();
ae.margin->add_theme_constant_override("margin_left", min_size.x / 2);
ae.margin->add_theme_constant_override("margin_top", min_size.y / 2);
ae.margin->add_theme_constant_override("margin_right", min_size.x / 2);
ae.margin->add_theme_constant_override("margin_bottom", min_size.y / 2);
ae.margin->end_bulk_theme_override();

if (ae.erase) {
ae.erase->set_icon(get_editor_theme_icon(SNAME("Remove")));
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ void EditorLog::_update_theme() {
log->add_theme_constant_override("text_highlight_v_padding", 0);

const int font_size = get_theme_font_size(SNAME("output_source_size"), EditorStringName(EditorFonts));
log->begin_bulk_theme_override();
log->add_theme_font_size_override("normal_font_size", font_size);
log->add_theme_font_size_override("bold_font_size", font_size);
log->add_theme_font_size_override("italics_font_size", font_size);
log->add_theme_font_size_override("mono_font_size", font_size);
log->end_bulk_theme_override();

type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_editor_theme_icon(SNAME("Popup")));
type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_editor_theme_icon(SNAME("StatusError")));
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,7 @@ void EditorPropertyResource::_update_property_bg() {

updating_theme = true;

begin_bulk_theme_override();
if (sub_inspector != nullptr) {
int count_subinspectors = 0;
Node *n = get_parent();
Expand All @@ -3283,14 +3284,14 @@ void EditorPropertyResource::_update_property_bg() {
add_theme_color_override("property_color", get_theme_color(SNAME("sub_inspector_property_color"), EditorStringName(Editor)));
add_theme_style_override("bg_selected", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(Editor)));
add_theme_style_override("bg", get_theme_stylebox("sub_inspector_property_bg" + itos(count_subinspectors), EditorStringName(Editor)));

add_theme_constant_override("v_separation", 0);
} else {
add_theme_color_override("property_color", get_theme_color(SNAME("property_color"), SNAME("EditorProperty")));
add_theme_style_override("bg_selected", get_theme_stylebox(SNAME("bg_selected"), SNAME("EditorProperty")));
add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("EditorProperty")));
add_theme_constant_override("v_separation", get_theme_constant(SNAME("v_separation"), SNAME("EditorProperty")));
}
end_bulk_theme_override();

updating_theme = false;
queue_redraw();
Expand Down Expand Up @@ -3483,7 +3484,6 @@ void EditorPropertyResource::fold_resource() {

void EditorPropertyResource::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
if (!updating_theme) {
_update_property_bg();
Expand Down
2 changes: 2 additions & 0 deletions editor/gui/editor_run_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ void EditorRunBar::_notification(int p_what) {

write_movie_button->set_icon(get_editor_theme_icon(SNAME("MainMovieWrite")));
// This button behaves differently, so color it as such.
write_movie_button->begin_bulk_theme_override();
write_movie_button->add_theme_color_override("icon_normal_color", Color(1, 1, 1, 0.7));
write_movie_button->add_theme_color_override("icon_pressed_color", Color(0, 0, 0, 0.84));
write_movie_button->add_theme_color_override("icon_hover_color", Color(1, 1, 1, 0.9));
write_movie_button->end_bulk_theme_override();
} break;
}
}
Expand Down
14 changes: 8 additions & 6 deletions editor/gui/editor_zoom_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,38 +195,40 @@ EditorZoomWidget::EditorZoomWidget() {
// Zoom buttons
zoom_minus = memnew(Button);
zoom_minus->set_flat(true);
add_child(zoom_minus);
zoom_minus->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_minus));
zoom_minus->set_shortcut(ED_SHORTCUT_ARRAY("canvas_item_editor/zoom_minus", TTR("Zoom Out"), { int32_t(KeyModifierMask::CMD_OR_CTRL | Key::MINUS), int32_t(KeyModifierMask::CMD_OR_CTRL | Key::KP_SUBTRACT) }));
zoom_minus->set_shortcut_context(this);
zoom_minus->set_focus_mode(FOCUS_NONE);
add_child(zoom_minus);
zoom_minus->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_minus));

zoom_reset = memnew(Button);
zoom_reset->set_flat(true);

Ref<StyleBoxEmpty> empty_stylebox = memnew(StyleBoxEmpty);
zoom_reset->add_theme_style_override("normal", empty_stylebox);
zoom_reset->add_theme_style_override("hover", empty_stylebox);
zoom_reset->add_theme_style_override("focus", empty_stylebox);
zoom_reset->add_theme_style_override("pressed", empty_stylebox);
add_child(zoom_reset);
zoom_reset->add_theme_constant_override("outline_size", Math::ceil(2 * EDSCALE));
zoom_reset->add_theme_color_override("font_outline_color", Color(0, 0, 0));
zoom_reset->add_theme_color_override("font_color", Color(1, 1, 1));
zoom_reset->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_reset));

zoom_reset->set_shortcut(ED_GET_SHORTCUT("canvas_item_editor/zoom_100_percent"));
zoom_reset->set_shortcut_context(this);
zoom_reset->set_focus_mode(FOCUS_NONE);
zoom_reset->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
// Prevent the button's size from changing when the text size changes
zoom_reset->set_custom_minimum_size(Size2(56 * EDSCALE, 0));
add_child(zoom_reset);
zoom_reset->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_reset));

zoom_plus = memnew(Button);
zoom_plus->set_flat(true);
add_child(zoom_plus);
zoom_plus->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_plus));
zoom_plus->set_shortcut(ED_SHORTCUT_ARRAY("canvas_item_editor/zoom_plus", TTR("Zoom In"), { int32_t(KeyModifierMask::CMD_OR_CTRL | Key::EQUAL), int32_t(KeyModifierMask::CMD_OR_CTRL | Key::KP_ADD) }));
zoom_plus->set_shortcut_context(this);
zoom_plus->set_focus_mode(FOCUS_NONE);
add_child(zoom_plus);
zoom_plus->connect("pressed", callable_mp(this, &EditorZoomWidget::_button_zoom_plus));

_update_zoom_label();

Expand Down
10 changes: 8 additions & 2 deletions editor/import/audio_stream_import_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ void AudioStreamImportSettings::_notification(int p_what) {
connect("confirmed", callable_mp(this, &AudioStreamImportSettings::_reimport));
} break;

case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_ENTER_TREE: {
case NOTIFICATION_THEME_CHANGED: {
_play_button->set_icon(get_editor_theme_icon(SNAME("MainPlay")));
_stop_button->set_icon(get_editor_theme_icon(SNAME("Stop")));

_preview->set_color(get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
color_rect->set_color(get_theme_color(SNAME("dark_color_1"), EditorStringName(Editor)));

_current_label->begin_bulk_theme_override();
_current_label->add_theme_font_override("font", get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
_current_label->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
_current_label->end_bulk_theme_override();

_duration_label->begin_bulk_theme_override();
_duration_label->add_theme_font_override("font", get_theme_font(SNAME("status_source"), EditorStringName(EditorFonts)));
_duration_label->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), EditorStringName(EditorFonts)));
_duration_label->end_bulk_theme_override();

zoom_in->set_icon(get_editor_theme_icon(SNAME("ZoomMore")));
zoom_out->set_icon(get_editor_theme_icon(SNAME("ZoomLess")));
Expand Down
Loading
Loading