Merge pull request #89693 from Calinou/dialogs-add-button-minimum-size

Add minimum width/height to dialog buttons
This commit is contained in:
Rémi Verschelde 2024-04-18 12:24:20 +02:00
commit 0dfb48e58d
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 28 additions and 0 deletions

View file

@ -100,6 +100,12 @@
</signal>
</signals>
<theme_items>
<theme_item name="buttons_min_height" data_type="constant" type="int" default="0">
The minimum height of each button in the bottom row (such as OK/Cancel) in pixels. This can be increased to make buttons with short texts easier to click/tap.
</theme_item>
<theme_item name="buttons_min_width" data_type="constant" type="int" default="0">
The minimum width of each button in the bottom row (such as OK/Cancel) in pixels. This can be increased to make buttons with short texts easier to click/tap.
</theme_item>
<theme_item name="buttons_separation" data_type="constant" type="int" default="10">
The size of the vertical space between the dialog's content and the button row.
</theme_item>

View file

@ -356,20 +356,25 @@ EditorThemeManager::ThemeConfiguration EditorThemeManager::_create_theme_config(
if (config.spacing_preset != "Custom") {
int preset_base_spacing = 0;
int preset_extra_spacing = 0;
Size2 preset_dialogs_buttons_min_size;
if (config.spacing_preset == "Compact") {
preset_base_spacing = 0;
preset_extra_spacing = 4;
preset_dialogs_buttons_min_size = Size2(90, 26);
} else if (config.spacing_preset == "Spacious") {
preset_base_spacing = 6;
preset_extra_spacing = 2;
preset_dialogs_buttons_min_size = Size2(112, 36);
} else { // Default
preset_base_spacing = 4;
preset_extra_spacing = 0;
preset_dialogs_buttons_min_size = Size2(105, 34);
}
config.base_spacing = preset_base_spacing;
config.extra_spacing = preset_extra_spacing;
config.dialogs_buttons_min_size = preset_dialogs_buttons_min_size;
EditorSettings::get_singleton()->set_initial_value("interface/theme/base_spacing", config.base_spacing);
EditorSettings::get_singleton()->set_initial_value("interface/theme/additional_spacing", config.extra_spacing);
@ -1271,6 +1276,9 @@ void EditorThemeManager::_populate_standard_styles(const Ref<EditorTheme> &p_the
// AcceptDialog.
p_theme->set_stylebox("panel", "AcceptDialog", p_config.dialog_style);
p_theme->set_constant("buttons_separation", "AcceptDialog", 8 * EDSCALE);
// Make buttons with short texts such as "OK" easier to click/tap.
p_theme->set_constant("buttons_min_width", "AcceptDialog", p_config.dialogs_buttons_min_size.x * EDSCALE);
p_theme->set_constant("buttons_min_height", "AcceptDialog", p_config.dialogs_buttons_min_size.y * EDSCALE);
// FileDialog.
p_theme->set_icon("folder", "FileDialog", p_theme->get_icon(SNAME("Folder"), EditorStringName(EditorIcons)));

View file

@ -62,6 +62,7 @@ class EditorThemeManager {
int base_spacing = 4;
int extra_spacing = 0;
Size2 dialogs_buttons_min_size = Size2(105, 34);
int border_width = 0;
int corner_radius = 3;

View file

@ -210,6 +210,15 @@ void AcceptDialog::_update_child_rects() {
bg_panel->set_position(Point2());
bg_panel->set_size(dlg_size);
for (int i = 0; i < buttons_hbox->get_child_count(); i++) {
Button *b = Object::cast_to<Button>(buttons_hbox->get_child(i));
if (!b) {
continue;
}
b->set_custom_minimum_size(Size2(theme_cache.buttons_min_width, theme_cache.buttons_min_height));
}
// Place the buttons from the bottom edge to their minimum required size.
Size2 buttons_minsize = buttons_hbox->get_combined_minimum_size();
Size2 buttons_size = Size2(dlg_size.x - h_margins, buttons_minsize.y);
@ -389,6 +398,8 @@ void AcceptDialog::_bind_methods() {
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, AcceptDialog, panel_style, "panel");
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_separation);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_min_width);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_min_height);
}
bool AcceptDialog::swap_cancel_ok = false;

View file

@ -57,6 +57,8 @@ class AcceptDialog : public Window {
struct ThemeCache {
Ref<StyleBox> panel_style;
int buttons_separation = 0;
int buttons_min_width = 0;
int buttons_min_height = 0;
} theme_cache;
void _custom_action(const String &p_action);