summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2023-03-04 00:12:19 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-04 00:29:38 +0100
commitbb4b74742483c88f564b8ae599737184bcf8361b (patch)
treef581a6c45f214dc15df45aeb985b4c9e0177f452 /Userland/Libraries/LibGUI
parent5979ce8316f876b4713ad63902ec6bd85ad2e138 (diff)
downloadserenity-bb4b74742483c88f564b8ae599737184bcf8361b.zip
LibGUI: Make Button height adapt to the current font size
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/Button.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp
index 254fa2d0db..30da20f9f7 100644
--- a/Userland/Libraries/LibGUI/Button.cpp
+++ b/Userland/Libraries/LibGUI/Button.cpp
@@ -23,8 +23,8 @@ namespace GUI {
Button::Button(String text)
: AbstractButton(move(text))
{
- set_min_size({ 40, 22 });
- set_preferred_size({ SpecialDimension::OpportunisticGrow, 22 });
+ set_min_size({ 40, SpecialDimension::Shrink });
+ set_preferred_size({ SpecialDimension::OpportunisticGrow, SpecialDimension::Shrink });
set_focus_policy(GUI::FocusPolicy::StrongFocus);
on_focus_change = [this](bool has_focus, auto) {
@@ -275,24 +275,26 @@ void Button::timer_event(Core::TimerEvent&)
Optional<UISize> Button::calculated_min_size() const
{
- int horizontal = 0, vertical = 0;
+ int width = 0;
+ int height = 0;
if (!text().is_empty()) {
auto& font = this->font();
- horizontal = static_cast<int>(ceilf(font.width(text()))) + 2;
- vertical = font.pixel_size_rounded_up() + 4; // FIXME: Use actual maximum total height
+ width = static_cast<int>(ceilf(font.width(text()))) + 2;
+ height = font.pixel_size_rounded_up() + 4; // FIXME: Use actual maximum total height
}
if (m_icon) {
- vertical = max(vertical, m_icon->height());
-
- horizontal += m_icon->width() + icon_spacing();
+ height += max(height, m_icon->height());
+ width += m_icon->width() + icon_spacing();
}
- horizontal += 8;
- vertical += 4;
+ width += 8;
+ height += 4;
+
+ height = max(22, height);
- return UISize(horizontal, vertical);
+ return UISize(width, height);
}
}