diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2022-03-31 18:14:36 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-04 14:59:37 +0200 |
commit | 2b9ffe2989f668f241973b07a05a01c43a1b18a2 (patch) | |
tree | 535c739366cb3abdde209ca1186b4dd208c965d7 /Userland/Libraries | |
parent | baac720e13640f3809499b46227f2d281905279a (diff) | |
download | serenity-2b9ffe2989f668f241973b07a05a01c43a1b18a2.zip |
LibGUI: Add optional autosize padding
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/Label.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Label.h | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/Label.cpp b/Userland/Libraries/LibGUI/Label.cpp index d41237803a..17045c5e04 100644 --- a/Userland/Libraries/LibGUI/Label.cpp +++ b/Userland/Libraries/LibGUI/Label.cpp @@ -34,11 +34,12 @@ Label::Label(String text) REGISTER_STRING_PROPERTY("icon", icon, set_icon_from_path); } -void Label::set_autosize(bool autosize) +void Label::set_autosize(bool autosize, size_t padding) { - if (m_autosize == autosize) + if (m_autosize == autosize && m_autosize_padding == padding) return; m_autosize = autosize; + m_autosize_padding = padding; if (m_autosize) size_to_fit(); } @@ -108,7 +109,7 @@ void Label::paint_event(PaintEvent& event) void Label::size_to_fit() { - set_fixed_width(font().width(m_text)); + set_fixed_width(font().width(m_text) + m_autosize_padding * 2); } int Label::preferred_height() const diff --git a/Userland/Libraries/LibGUI/Label.h b/Userland/Libraries/LibGUI/Label.h index dac18da10b..d899231911 100644 --- a/Userland/Libraries/LibGUI/Label.h +++ b/Userland/Libraries/LibGUI/Label.h @@ -37,7 +37,7 @@ public: void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; } bool is_autosize() const { return m_autosize; } - void set_autosize(bool); + void set_autosize(bool, size_t padding = 0); int preferred_height() const; @@ -58,6 +58,7 @@ private: Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap }; bool m_should_stretch_icon { false }; bool m_autosize { false }; + size_t m_autosize_padding { 0 }; }; } |