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

Replace flat buttons with flat-styled buttons with a visible pressed state #81939

Merged
merged 1 commit into from
Sep 25, 2023
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: 8 additions & 8 deletions editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,30 +1814,30 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
hbc->add_child(memnew(VSeparator));

skip_breakpoints = memnew(Button);
skip_breakpoints->set_flat(true);
skip_breakpoints->set_theme_type_variation("FlatButton");
hbc->add_child(skip_breakpoints);
skip_breakpoints->set_tooltip_text(TTR("Skip Breakpoints"));
skip_breakpoints->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_skip_breakpoints));

hbc->add_child(memnew(VSeparator));

copy = memnew(Button);
copy->set_flat(true);
copy->set_theme_type_variation("FlatButton");
hbc->add_child(copy);
copy->set_tooltip_text(TTR("Copy Error"));
copy->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_copy));

hbc->add_child(memnew(VSeparator));

step = memnew(Button);
step->set_flat(true);
step->set_theme_type_variation("FlatButton");
hbc->add_child(step);
step->set_tooltip_text(TTR("Step Into"));
step->set_shortcut(ED_GET_SHORTCUT("debugger/step_into"));
step->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_step));

next = memnew(Button);
next->set_flat(true);
next->set_theme_type_variation("FlatButton");
hbc->add_child(next);
next->set_tooltip_text(TTR("Step Over"));
next->set_shortcut(ED_GET_SHORTCUT("debugger/step_over"));
Expand All @@ -1846,14 +1846,14 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
hbc->add_child(memnew(VSeparator));

dobreak = memnew(Button);
dobreak->set_flat(true);
dobreak->set_theme_type_variation("FlatButton");
hbc->add_child(dobreak);
dobreak->set_tooltip_text(TTR("Break"));
dobreak->set_shortcut(ED_GET_SHORTCUT("debugger/break"));
dobreak->connect("pressed", callable_mp(this, &ScriptEditorDebugger::debug_break));

docontinue = memnew(Button);
docontinue->set_flat(true);
docontinue->set_theme_type_variation("FlatButton");
hbc->add_child(docontinue);
docontinue->set_tooltip_text(TTR("Continue"));
docontinue->set_shortcut(ED_GET_SHORTCUT("debugger/continue"));
Expand Down Expand Up @@ -2028,10 +2028,10 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
vmem_total->set_custom_minimum_size(Size2(100, 0) * EDSCALE);
vmem_hb->add_child(vmem_total);
vmem_refresh = memnew(Button);
vmem_refresh->set_flat(true);
vmem_refresh->set_theme_type_variation("FlatButton");
vmem_hb->add_child(vmem_refresh);
vmem_export = memnew(Button);
vmem_export->set_flat(true);
vmem_export->set_theme_type_variation("FlatButton");
vmem_export->set_tooltip_text(TTR("Export list to a CSV file"));
vmem_hb->add_child(vmem_export);
vmem_vb->add_child(vmem_hb);
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,21 +803,21 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
HBoxContainer *hbc = memnew(HBoxContainer);
vb->add_child(hbc);
solo = memnew(Button);
solo->set_flat(true);
solo->set_theme_type_variation("FlatButton");
solo->set_toggle_mode(true);
solo->set_tooltip_text(TTR("Solo"));
solo->set_focus_mode(FOCUS_NONE);
solo->connect("pressed", callable_mp(this, &EditorAudioBus::_solo_toggled));
hbc->add_child(solo);
mute = memnew(Button);
mute->set_flat(true);
mute->set_theme_type_variation("FlatButton");
mute->set_toggle_mode(true);
mute->set_tooltip_text(TTR("Mute"));
mute->set_focus_mode(FOCUS_NONE);
mute->connect("pressed", callable_mp(this, &EditorAudioBus::_mute_toggled));
hbc->add_child(mute);
bypass = memnew(Button);
bypass->set_flat(true);
bypass->set_theme_type_variation("FlatButton");
bypass->set_toggle_mode(true);
bypass->set_tooltip_text(TTR("Bypass"));
bypass->set_focus_mode(FOCUS_NONE);
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_help_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ EditorHelpSearch::EditorHelpSearch() {
hbox->add_child(search_box);

case_sensitive_button = memnew(Button);
case_sensitive_button->set_flat(true);
case_sensitive_button->set_theme_type_variation("FlatButton");
case_sensitive_button->set_tooltip_text(TTR("Case Sensitive"));
case_sensitive_button->connect("pressed", callable_mp(this, &EditorHelpSearch::_update_results));
case_sensitive_button->set_toggle_mode(true);
case_sensitive_button->set_focus_mode(Control::FOCUS_NONE);
hbox->add_child(case_sensitive_button);

hierarchy_button = memnew(Button);
hierarchy_button->set_flat(true);
hierarchy_button->set_theme_type_variation("FlatButton");
hierarchy_button->set_tooltip_text(TTR("Show Hierarchy"));
hierarchy_button->connect("pressed", callable_mp(this, &EditorHelpSearch::_update_results));
hierarchy_button->set_toggle_mode(true);
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ EditorLog::EditorLog() {

// Clear.
clear_button = memnew(Button);
clear_button->set_flat(true);
clear_button->set_theme_type_variation("FlatButton");
clear_button->set_focus_mode(FOCUS_NONE);
clear_button->set_shortcut(ED_SHORTCUT("editor/clear_output", TTR("Clear Output"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::K));
clear_button->set_shortcut_context(this);
Expand All @@ -435,7 +435,7 @@ EditorLog::EditorLog() {

// Copy.
copy_button = memnew(Button);
copy_button->set_flat(true);
copy_button->set_theme_type_variation("FlatButton");
copy_button->set_focus_mode(FOCUS_NONE);
copy_button->set_shortcut(ED_SHORTCUT("editor/copy_output", TTR("Copy Selection"), KeyModifierMask::CMD_OR_CTRL | Key::C));
copy_button->set_shortcut_context(this);
Expand All @@ -449,7 +449,7 @@ EditorLog::EditorLog() {

// Collapse.
collapse_button = memnew(Button);
collapse_button->set_flat(true);
collapse_button->set_theme_type_variation("FlatButton");
collapse_button->set_focus_mode(FOCUS_NONE);
collapse_button->set_tooltip_text(TTR("Collapse duplicate messages into one log entry. Shows number of occurrences."));
collapse_button->set_toggle_mode(true);
Expand All @@ -459,7 +459,7 @@ EditorLog::EditorLog() {

// Show Search.
show_search_button = memnew(Button);
show_search_button->set_flat(true);
show_search_button->set_theme_type_variation("FlatButton");
show_search_button->set_focus_mode(FOCUS_NONE);
show_search_button->set_toggle_mode(true);
show_search_button->set_pressed(true);
Expand Down
26 changes: 25 additions & 1 deletion editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
toolbar_stylebox->set_border_color(accent_color);
toolbar_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE));
toolbar_stylebox->set_content_margin(SIDE_BOTTOM, 0);
toolbar_stylebox->set_expand_margin_all(2 * EDSCALE);
toolbar_stylebox->set_expand_margin_individual(4 * EDSCALE, 2 * EDSCALE, 4 * EDSCALE, 4 * EDSCALE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That stylebox is actually clipping buttons, but it's not noticeable if you don't have styles rendered on them. And the sides were too close with the pressed style on, so I extended them a bit.

Copy link
Member

@KoBeWi KoBeWi Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Without this change, the side margins match the top margin (bottom does look bad though).
idk, maybe your change is ok.

theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox);

// Script Editor
Expand Down Expand Up @@ -1020,6 +1020,30 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_constant("h_separation", "Button", 4 * EDSCALE);
theme->set_constant("outline_size", "Button", 0);

// Flat button variations.

Ref<StyleBoxEmpty> style_flat_button = make_empty_stylebox();
for (int i = 0; i < 4; i++) {
style_flat_button->set_content_margin((Side)i, style_widget->get_margin((Side)i) + style_widget->get_border_width((Side)i));
}

Ref<StyleBoxFlat> style_flat_button_pressed = style_widget_pressed->duplicate();
Color flat_pressed_color = dark_color_1.lerp(accent_color, 0.2) * Color(0.8, 0.8, 0.8, 0.85);
if (dark_theme) {
flat_pressed_color = dark_color_1.lerp(accent_color, 0.2) * Color(0.6, 0.6, 0.6, 0.85);
}
style_flat_button_pressed->set_bg_color(flat_pressed_color);

theme->set_stylebox("normal", "FlatButton", style_flat_button);
theme->set_stylebox("hover", "FlatButton", style_flat_button);
theme->set_stylebox("pressed", "FlatButton", style_flat_button_pressed);
theme->set_stylebox("disabled", "FlatButton", style_flat_button);

theme->set_stylebox("normal", "FlatMenuButton", style_flat_button);
theme->set_stylebox("hover", "FlatMenuButton", style_flat_button);
theme->set_stylebox("pressed", "FlatMenuButton", style_flat_button_pressed);
theme->set_stylebox("disabled", "FlatMenuButton", style_flat_button);

const float ACTION_BUTTON_EXTRA_MARGIN = 32 * EDSCALE;

theme->set_type_variation("InspectorActionButton", "Button");
Expand Down
20 changes: 10 additions & 10 deletions editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,13 +1741,13 @@ EditorFileDialog::EditorFileDialog() {
HBoxContainer *pathhb = memnew(HBoxContainer);

dir_prev = memnew(Button);
dir_prev->set_flat(true);
dir_prev->set_theme_type_variation("FlatButton");
dir_prev->set_tooltip_text(TTR("Go to previous folder."));
dir_next = memnew(Button);
dir_next->set_flat(true);
dir_next->set_theme_type_variation("FlatButton");
dir_next->set_tooltip_text(TTR("Go to next folder."));
dir_up = memnew(Button);
dir_up->set_flat(true);
dir_up->set_theme_type_variation("FlatButton");
dir_up->set_tooltip_text(TTR("Go to parent folder."));

pathhb->add_child(dir_prev);
Expand All @@ -1771,20 +1771,20 @@ EditorFileDialog::EditorFileDialog() {
dir->set_h_size_flags(Control::SIZE_EXPAND_FILL);

refresh = memnew(Button);
refresh->set_flat(true);
refresh->set_theme_type_variation("FlatButton");
refresh->set_tooltip_text(TTR("Refresh files."));
refresh->connect("pressed", callable_mp(this, &EditorFileDialog::update_file_list));
pathhb->add_child(refresh);

favorite = memnew(Button);
favorite->set_flat(true);
favorite->set_theme_type_variation("FlatButton");
favorite->set_toggle_mode(true);
favorite->set_tooltip_text(TTR("(Un)favorite current folder."));
favorite->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_pressed));
pathhb->add_child(favorite);

show_hidden = memnew(Button);
show_hidden->set_flat(true);
show_hidden->set_theme_type_variation("FlatButton");
show_hidden->set_toggle_mode(true);
show_hidden->set_pressed(is_showing_hidden_files());
show_hidden->set_tooltip_text(TTR("Toggle the visibility of hidden files."));
Expand All @@ -1797,7 +1797,7 @@ EditorFileDialog::EditorFileDialog() {
view_mode_group.instantiate();

mode_thumbnails = memnew(Button);
mode_thumbnails->set_flat(true);
mode_thumbnails->set_theme_type_variation("FlatButton");
mode_thumbnails->connect("pressed", callable_mp(this, &EditorFileDialog::set_display_mode).bind(DISPLAY_THUMBNAILS));
mode_thumbnails->set_toggle_mode(true);
mode_thumbnails->set_pressed(display_mode == DISPLAY_THUMBNAILS);
Expand All @@ -1806,7 +1806,7 @@ EditorFileDialog::EditorFileDialog() {
pathhb->add_child(mode_thumbnails);

mode_list = memnew(Button);
mode_list->set_flat(true);
mode_list->set_theme_type_variation("FlatButton");
mode_list->connect("pressed", callable_mp(this, &EditorFileDialog::set_display_mode).bind(DISPLAY_LIST));
mode_list->set_toggle_mode(true);
mode_list->set_pressed(display_mode == DISPLAY_LIST);
Expand Down Expand Up @@ -1848,11 +1848,11 @@ EditorFileDialog::EditorFileDialog() {

fav_hb->add_spacer();
fav_up = memnew(Button);
fav_up->set_flat(true);
fav_up->set_theme_type_variation("FlatButton");
fav_hb->add_child(fav_up);
fav_up->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_up));
fav_down = memnew(Button);
fav_down->set_flat(true);
fav_down->set_theme_type_variation("FlatButton");
fav_hb->add_child(fav_down);
fav_down->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_down));

Expand Down
6 changes: 3 additions & 3 deletions editor/plugins/abstract_polygon_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,19 +726,19 @@ AbstractPolygon2DEditor::AbstractPolygon2DEditor(bool p_wip_destructive) {
edge_point = PosVertex();

button_create = memnew(Button);
button_create->set_flat(true);
button_create->set_theme_type_variation("FlatButton");
add_child(button_create);
button_create->connect("pressed", callable_mp(this, &AbstractPolygon2DEditor::_menu_option).bind(MODE_CREATE));
button_create->set_toggle_mode(true);

button_edit = memnew(Button);
button_edit->set_flat(true);
button_edit->set_theme_type_variation("FlatButton");
add_child(button_edit);
button_edit->connect("pressed", callable_mp(this, &AbstractPolygon2DEditor::_menu_option).bind(MODE_EDIT));
button_edit->set_toggle_mode(true);

button_delete = memnew(Button);
button_delete->set_flat(true);
button_delete->set_theme_type_variation("FlatButton");
add_child(button_delete);
button_delete->connect("pressed", callable_mp(this, &AbstractPolygon2DEditor::_menu_option).bind(MODE_DELETE));
button_delete->set_toggle_mode(true);
Expand Down
10 changes: 5 additions & 5 deletions editor/plugins/animation_blend_space_1d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
bg.instantiate();

tool_blend = memnew(Button);
tool_blend->set_flat(true);
tool_blend->set_theme_type_variation("FlatButton");
tool_blend->set_toggle_mode(true);
tool_blend->set_button_group(bg);
top_hb->add_child(tool_blend);
Expand All @@ -672,15 +672,15 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
tool_blend->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace1DEditor::_tool_switch).bind(3));

tool_select = memnew(Button);
tool_select->set_flat(true);
tool_select->set_theme_type_variation("FlatButton");
tool_select->set_toggle_mode(true);
tool_select->set_button_group(bg);
top_hb->add_child(tool_select);
tool_select->set_tooltip_text(TTR("Select and move points, create points with RMB."));
tool_select->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace1DEditor::_tool_switch).bind(0));

tool_create = memnew(Button);
tool_create->set_flat(true);
tool_create->set_theme_type_variation("FlatButton");
tool_create->set_toggle_mode(true);
tool_create->set_button_group(bg);
top_hb->add_child(tool_create);
Expand All @@ -690,15 +690,15 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
tool_erase_sep = memnew(VSeparator);
top_hb->add_child(tool_erase_sep);
tool_erase = memnew(Button);
tool_erase->set_flat(true);
tool_erase->set_theme_type_variation("FlatButton");
top_hb->add_child(tool_erase);
tool_erase->set_tooltip_text(TTR("Erase points."));
tool_erase->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace1DEditor::_erase_selected));

top_hb->add_child(memnew(VSeparator));

snap = memnew(Button);
snap->set_flat(true);
snap->set_theme_type_variation("FlatButton");
snap->set_toggle_mode(true);
top_hb->add_child(snap);
snap->set_pressed(true);
Expand Down
14 changes: 7 additions & 7 deletions editor/plugins/animation_blend_space_2d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
bg.instantiate();

tool_blend = memnew(Button);
tool_blend->set_flat(true);
tool_blend->set_theme_type_variation("FlatButton");
tool_blend->set_toggle_mode(true);
tool_blend->set_button_group(bg);
top_hb->add_child(tool_blend);
Expand All @@ -892,23 +892,23 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
tool_blend->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(3));

tool_select = memnew(Button);
tool_select->set_flat(true);
tool_select->set_theme_type_variation("FlatButton");
tool_select->set_toggle_mode(true);
tool_select->set_button_group(bg);
top_hb->add_child(tool_select);
tool_select->set_tooltip_text(TTR("Select and move points, create points with RMB."));
tool_select->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(0));

tool_create = memnew(Button);
tool_create->set_flat(true);
tool_create->set_theme_type_variation("FlatButton");
tool_create->set_toggle_mode(true);
tool_create->set_button_group(bg);
top_hb->add_child(tool_create);
tool_create->set_tooltip_text(TTR("Create points."));
tool_create->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(1));

tool_triangle = memnew(Button);
tool_triangle->set_flat(true);
tool_triangle->set_theme_type_variation("FlatButton");
tool_triangle->set_toggle_mode(true);
tool_triangle->set_button_group(bg);
top_hb->add_child(tool_triangle);
Expand All @@ -918,7 +918,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
tool_erase_sep = memnew(VSeparator);
top_hb->add_child(tool_erase_sep);
tool_erase = memnew(Button);
tool_erase->set_flat(true);
tool_erase->set_theme_type_variation("FlatButton");
top_hb->add_child(tool_erase);
tool_erase->set_tooltip_text(TTR("Erase points and triangles."));
tool_erase->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_erase_selected));
Expand All @@ -927,7 +927,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
top_hb->add_child(memnew(VSeparator));

auto_triangles = memnew(Button);
auto_triangles->set_flat(true);
auto_triangles->set_theme_type_variation("FlatButton");
top_hb->add_child(auto_triangles);
auto_triangles->connect("pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled));
auto_triangles->set_toggle_mode(true);
Expand All @@ -936,7 +936,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
top_hb->add_child(memnew(VSeparator));

snap = memnew(Button);
snap->set_flat(true);
snap->set_theme_type_variation("FlatButton");
snap->set_toggle_mode(true);
top_hb->add_child(snap);
snap->set_pressed(true);
Expand Down
Loading