summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2023-04-14 08:54:12 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-15 15:24:50 +0200
commit5294ef918ec73d2258bfca61446be04da0d77bfe (patch)
tree4cadf7fa264d85bbcb890f50e212b5dfda1b29bd /Userland
parent479e67212a1074bc76a6790186d1d05e2c421ee6 (diff)
downloadserenity-5294ef918ec73d2258bfca61446be04da0d77bfe.zip
LibGUI: Implement calculated_min_size() for Label
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/Label.cpp12
-rw-r--r--Userland/Libraries/LibGUI/Label.h1
2 files changed, 12 insertions, 1 deletions
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<UISize> Label::calculated_preferred_size() const
return GUI::UISize(text_calculated_preferred_width(), text_calculated_preferred_height());
}
+Optional<UISize> 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<UISize> calculated_min_size() const override;
virtual Optional<UISize> calculated_preferred_size() const override;
int text_calculated_preferred_height() const;
int text_calculated_preferred_width() const;