Skip to content

Commit 2b9ffe2

Browse files
mattco98awesomekling
authored andcommitted
LibGUI: Add optional autosize padding
1 parent baac720 commit 2b9ffe2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Userland/Libraries/LibGUI/Label.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ Label::Label(String text)
3434
REGISTER_STRING_PROPERTY("icon", icon, set_icon_from_path);
3535
}
3636

37-
void Label::set_autosize(bool autosize)
37+
void Label::set_autosize(bool autosize, size_t padding)
3838
{
39-
if (m_autosize == autosize)
39+
if (m_autosize == autosize && m_autosize_padding == padding)
4040
return;
4141
m_autosize = autosize;
42+
m_autosize_padding = padding;
4243
if (m_autosize)
4344
size_to_fit();
4445
}
@@ -108,7 +109,7 @@ void Label::paint_event(PaintEvent& event)
108109

109110
void Label::size_to_fit()
110111
{
111-
set_fixed_width(font().width(m_text));
112+
set_fixed_width(font().width(m_text) + m_autosize_padding * 2);
112113
}
113114

114115
int Label::preferred_height() const

Userland/Libraries/LibGUI/Label.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Label : public Frame {
3737
void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
3838

3939
bool is_autosize() const { return m_autosize; }
40-
void set_autosize(bool);
40+
void set_autosize(bool, size_t padding = 0);
4141

4242
int preferred_height() const;
4343

@@ -58,6 +58,7 @@ class Label : public Frame {
5858
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
5959
bool m_should_stretch_icon { false };
6060
bool m_autosize { false };
61+
size_t m_autosize_padding { 0 };
6162
};
6263

6364
}

0 commit comments

Comments
 (0)