From 479e67212a1074bc76a6790186d1d05e2c421ee6 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:54:06 -0400 Subject: [PATCH] LibGUI: Implement calculated_min_size() for DialogButton Dialog buttons now scale based on presentation size to accomodate larger fonts while retaining uniform widths. Scaling by 8 is arbitrary but preserves the historical 80 pixel width with Katica 10. This needs improvement but works well for most fonts as a start. --- Userland/Libraries/LibGUI/Button.cpp | 10 ++++++++++ Userland/Libraries/LibGUI/Button.h | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp index 10874bd0e4..90168754da 100644 --- a/Userland/Libraries/LibGUI/Button.cpp +++ b/Userland/Libraries/LibGUI/Button.cpp @@ -291,4 +291,14 @@ Optional Button::calculated_min_size() const return UISize(width, height); } +Optional DialogButton::calculated_min_size() const +{ + int constexpr scale = 8; + int constexpr padding = 6; + int width = max(80, font().presentation_size() * scale); + int height = max(22, font().pixel_size_rounded_up() + padding); + + return UISize(width, height); +} + } diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h index 6936517963..8dd50fa675 100644 --- a/Userland/Libraries/LibGUI/Button.h +++ b/Userland/Libraries/LibGUI/Button.h @@ -95,8 +95,11 @@ public: explicit DialogButton(String text = {}) : Button(move(text)) { - set_fixed_width(80); + set_min_size({ SpecialDimension::Shrink }); + set_preferred_size({ SpecialDimension::Shrink }); } + + virtual Optional calculated_min_size() const override; }; }