From 4bd569be95f0e8ba34813b0d8fc53bab1125ccaa Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 19 Sep 2023 18:03:10 +0200 Subject: Replace flat buttons with flat-styled buttons with a visible pressed state --- scene/gui/file_dialog.cpp | 10 +++++----- scene/gui/graph_edit.cpp | 14 +++++++------- scene/theme/default_theme.cpp | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) (limited to 'scene') diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index d27a40779e..7af7b2cf7e 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -1084,13 +1084,13 @@ FileDialog::FileDialog() { HBoxContainer *hbc = memnew(HBoxContainer); dir_prev = memnew(Button); - dir_prev->set_flat(true); + dir_prev->set_theme_type_variation("FlatButton"); dir_prev->set_tooltip_text(RTR("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(RTR("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(RTR("Go to parent folder.")); hbc->add_child(dir_prev); hbc->add_child(dir_next); @@ -1114,13 +1114,13 @@ FileDialog::FileDialog() { 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(RTR("Refresh files.")); refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); hbc->add_child(refresh); 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(RTR("Toggle the visibility of hidden files.")); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 6b5e3486ac..7269ed516d 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1988,28 +1988,28 @@ GraphEdit::GraphEdit() { _update_zoom_label(); zoom_minus_button = memnew(Button); - zoom_minus_button->set_flat(true); + zoom_minus_button->set_theme_type_variation("FlatButton"); menu_hbox->add_child(zoom_minus_button); zoom_minus_button->set_tooltip_text(RTR("Zoom Out")); zoom_minus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus)); zoom_minus_button->set_focus_mode(FOCUS_NONE); zoom_reset_button = memnew(Button); - zoom_reset_button->set_flat(true); + zoom_reset_button->set_theme_type_variation("FlatButton"); menu_hbox->add_child(zoom_reset_button); zoom_reset_button->set_tooltip_text(RTR("Zoom Reset")); zoom_reset_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset)); zoom_reset_button->set_focus_mode(FOCUS_NONE); zoom_plus_button = memnew(Button); - zoom_plus_button->set_flat(true); + zoom_plus_button->set_theme_type_variation("FlatButton"); menu_hbox->add_child(zoom_plus_button); zoom_plus_button->set_tooltip_text(RTR("Zoom In")); zoom_plus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus)); zoom_plus_button->set_focus_mode(FOCUS_NONE); show_grid_button = memnew(Button); - show_grid_button->set_flat(true); + show_grid_button->set_theme_type_variation("FlatButton"); show_grid_button->set_toggle_mode(true); show_grid_button->set_tooltip_text(RTR("Toggle the visual grid.")); show_grid_button->connect("pressed", callable_mp(this, &GraphEdit::_show_grid_toggled)); @@ -2018,7 +2018,7 @@ GraphEdit::GraphEdit() { menu_hbox->add_child(show_grid_button); toggle_snapping_button = memnew(Button); - toggle_snapping_button->set_flat(true); + toggle_snapping_button->set_theme_type_variation("FlatButton"); toggle_snapping_button->set_toggle_mode(true); toggle_snapping_button->set_tooltip_text(RTR("Toggle snapping to the grid.")); toggle_snapping_button->connect("pressed", callable_mp(this, &GraphEdit::_snapping_toggled)); @@ -2036,7 +2036,7 @@ GraphEdit::GraphEdit() { menu_hbox->add_child(snapping_distance_spinbox); minimap_button = memnew(Button); - minimap_button->set_flat(true); + minimap_button->set_theme_type_variation("FlatButton"); minimap_button->set_toggle_mode(true); minimap_button->set_tooltip_text(RTR("Toggle the graph minimap.")); minimap_button->connect("pressed", callable_mp(this, &GraphEdit::_minimap_toggled)); @@ -2045,7 +2045,7 @@ GraphEdit::GraphEdit() { menu_hbox->add_child(minimap_button); layout_button = memnew(Button); - layout_button->set_flat(true); + layout_button->set_theme_type_variation("FlatButton"); menu_hbox->add_child(layout_button); layout_button->set_tooltip_text(RTR("Automatically arrange selected nodes.")); layout_button->connect("pressed", callable_mp(this, &GraphEdit::arrange_nodes)); diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 7efbc74bf3..2ec12fb45d 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -360,6 +360,28 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_constant("check_v_offset", "CheckButton", 0); theme->set_constant("outline_size", "CheckButton", 0); + // Button variations + + theme->set_type_variation("FlatButton", "Button"); + theme->set_type_variation("FlatMenuButton", "MenuButton"); + + Ref flat_button_normal = make_empty_stylebox(); + for (int i = 0; i < 4; i++) { + flat_button_normal->set_content_margin((Side)i, button_normal->get_margin((Side)i) + button_normal->get_border_width((Side)i)); + } + Ref flat_button_pressed = button_pressed->duplicate(); + flat_button_pressed->set_bg_color(style_pressed_color * Color(1, 1, 1, 0.85)); + + theme->set_stylebox("normal", "FlatButton", flat_button_normal); + theme->set_stylebox("hover", "FlatButton", flat_button_normal); + theme->set_stylebox("pressed", "FlatButton", flat_button_pressed); + theme->set_stylebox("disabled", "FlatButton", flat_button_normal); + + theme->set_stylebox("normal", "FlatMenuButton", flat_button_normal); + theme->set_stylebox("hover", "FlatMenuButton", flat_button_normal); + theme->set_stylebox("pressed", "FlatMenuButton", flat_button_pressed); + theme->set_stylebox("disabled", "FlatMenuButton", flat_button_normal); + // Label theme->set_stylebox("normal", "Label", memnew(StyleBoxEmpty)); -- cgit v1.2.3