diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2023-02-09 15:21:15 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2023-02-25 20:49:41 -0700 |
commit | 376e7243a95fa19c0f425a77d1cff648f9536647 (patch) | |
tree | 3d5b4557678c30074d0c0c1d20cee2c1f7e9c9a9 /Userland | |
parent | 9f5f6b38688eb3615a3a121d5ff43f718f64a005 (diff) | |
download | serenity-376e7243a95fa19c0f425a77d1cff648f9536647.zip |
LibGUI: Use full text width for Label's preferred width
A label would prefer to be exactly as wide as its contained text
requires. This makes min_width: "fit" work better.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/Label.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Label.h | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index 75f5e3df4e..8c01568377 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -111,7 +111,12 @@ void Label::paint_event(PaintEvent& event) void Label::size_to_fit() { - set_fixed_width(static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2); + set_fixed_width(text_calculated_preferred_width()); +} + +int Label::text_calculated_preferred_width() const +{ + return static_cast<int>(ceilf(font().width(m_text))) + m_autosize_padding * 2; } int Label::text_calculated_preferred_height() const @@ -121,6 +126,7 @@ int Label::text_calculated_preferred_height() const Optional<UISize> Label::calculated_preferred_size() const { - return GUI::UISize(SpecialDimension::Grow, text_calculated_preferred_height()); + return GUI::UISize(text_calculated_preferred_width(), text_calculated_preferred_height()); } + } diff --git a/Userland/Libraries/LibGUI/Label.h b/Userland/Libraries/LibGUI/Label.h index a80217ba30..a74c4037b8 100644 --- a/Userland/Libraries/LibGUI/Label.h +++ b/Userland/Libraries/LibGUI/Label.h @@ -40,6 +40,7 @@ public: virtual Optional<UISize> calculated_preferred_size() const override; int text_calculated_preferred_height() const; + int text_calculated_preferred_width() const; Gfx::IntRect text_rect() const; |