From 5294ef918ec73d2258bfca61446be04da0d77bfe Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:54:12 -0400 Subject: LibGUI: Implement calculated_min_size() for Label --- Userland/Libraries/LibGUI/Label.cpp | 12 +++++++++++- Userland/Libraries/LibGUI/Label.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index 37b106b58a..ca9f6e026e 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -23,7 +23,7 @@ Label::Label(DeprecatedString text) REGISTER_TEXT_WRAPPING_PROPERTY("text_wrapping", text_wrapping, set_text_wrapping); set_preferred_size({ SpecialDimension::OpportunisticGrow }); - set_min_height(22); + set_min_size({ SpecialDimension::Shrink }); set_frame_thickness(0); set_frame_shadow(Gfx::FrameShadow::Plain); @@ -129,4 +129,14 @@ Optional Label::calculated_preferred_size() const return GUI::UISize(text_calculated_preferred_width(), text_calculated_preferred_height()); } +Optional Label::calculated_min_size() const +{ + int frame = frame_thickness() * 2; + int width = font().width_rounded_up("..."sv) + frame; + int height = font().pixel_size_rounded_up() + frame; + height = max(height, 22); + + return UISize(width, height); +} + } diff --git a/Userland/Libraries/LibGUI/Label.h b/Userland/Libraries/LibGUI/Label.h index a74c4037b8..796574d514 100644 --- a/Userland/Libraries/LibGUI/Label.h +++ b/Userland/Libraries/LibGUI/Label.h @@ -38,6 +38,7 @@ public: bool is_autosize() const { return m_autosize; } void set_autosize(bool, size_t padding = 0); + virtual Optional calculated_min_size() const override; virtual Optional calculated_preferred_size() const override; int text_calculated_preferred_height() const; int text_calculated_preferred_width() const; -- cgit v1.2.3