mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-12 02:30:30 +09:00
LibGUI: Add optional autosize padding
This commit is contained in:
parent
baac720e13
commit
2b9ffe2989
Notes:
sideshowbarker
2024-07-17 14:27:22 +09:00
Author: https://github.com/mattco98
Commit: 2b9ffe2989
Pull-request: https://github.com/SerenityOS/serenity/pull/13394
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/nico
2 changed files with 6 additions and 4 deletions
|
@ -34,11 +34,12 @@ Label::Label(String text)
|
||||||
REGISTER_STRING_PROPERTY("icon", icon, set_icon_from_path);
|
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;
|
return;
|
||||||
m_autosize = autosize;
|
m_autosize = autosize;
|
||||||
|
m_autosize_padding = padding;
|
||||||
if (m_autosize)
|
if (m_autosize)
|
||||||
size_to_fit();
|
size_to_fit();
|
||||||
}
|
}
|
||||||
|
@ -108,7 +109,7 @@ void Label::paint_event(PaintEvent& event)
|
||||||
|
|
||||||
void Label::size_to_fit()
|
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
|
int Label::preferred_height() const
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
|
void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
|
||||||
|
|
||||||
bool is_autosize() const { return m_autosize; }
|
bool is_autosize() const { return m_autosize; }
|
||||||
void set_autosize(bool);
|
void set_autosize(bool, size_t padding = 0);
|
||||||
|
|
||||||
int preferred_height() const;
|
int preferred_height() const;
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ private:
|
||||||
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
|
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
|
||||||
bool m_should_stretch_icon { false };
|
bool m_should_stretch_icon { false };
|
||||||
bool m_autosize { false };
|
bool m_autosize { false };
|
||||||
|
size_t m_autosize_padding { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue