mirror of
https://github.com/RGBCube/serenity
synced 2025-07-08 06:27:35 +00:00
LibGUI: Make GUI::Label auto-sizing declarative
You can now set the "autosize" property on a GUI::Label and it will automatically update its width preference to fit the text.
This commit is contained in:
parent
de08e7b8c9
commit
64ba41ea13
4 changed files with 18 additions and 5 deletions
|
@ -42,12 +42,22 @@ Label::Label(const StringView& text)
|
|||
set_foreground_role(Gfx::ColorRole::WindowText);
|
||||
|
||||
REGISTER_STRING_PROPERTY("text", text, set_text);
|
||||
REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize);
|
||||
}
|
||||
|
||||
Label::~Label()
|
||||
{
|
||||
}
|
||||
|
||||
void Label::set_autosize(bool autosize)
|
||||
{
|
||||
if (m_autosize == autosize)
|
||||
return;
|
||||
m_autosize = autosize;
|
||||
if (m_autosize)
|
||||
size_to_fit();
|
||||
}
|
||||
|
||||
void Label::set_icon(const Gfx::Bitmap* icon)
|
||||
{
|
||||
if (m_icon == icon)
|
||||
|
@ -61,6 +71,8 @@ void Label::set_text(const StringView& text)
|
|||
if (text == m_text)
|
||||
return;
|
||||
m_text = text;
|
||||
if (m_autosize)
|
||||
size_to_fit();
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue