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.
This commit is contained in:
thankyouverycool 2023-04-14 08:54:06 -04:00 committed by Andreas Kling
parent 5181fafce6
commit 479e67212a
2 changed files with 14 additions and 1 deletions

View file

@ -291,4 +291,14 @@ Optional<UISize> Button::calculated_min_size() const
return UISize(width, height);
}
Optional<UISize> 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);
}
}

View file

@ -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<UISize> calculated_min_size() const override;
};
}