mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibGUI: Add autosize to CheckBox
This commit is contained in:
parent
8afe013069
commit
e8c1288e2c
2 changed files with 25 additions and 1 deletions
|
@ -37,10 +37,13 @@ namespace GUI {
|
|||
|
||||
static const int s_box_width = 13;
|
||||
static const int s_box_height = 13;
|
||||
static const int s_horizontal_padding = 4;
|
||||
|
||||
CheckBox::CheckBox(String text)
|
||||
: AbstractButton(move(text))
|
||||
{
|
||||
REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize);
|
||||
|
||||
set_min_width(32);
|
||||
set_fixed_height(22);
|
||||
}
|
||||
|
@ -55,7 +58,7 @@ void CheckBox::paint_event(PaintEvent& event)
|
|||
painter.add_clip_rect(event.rect());
|
||||
|
||||
auto text_rect = rect();
|
||||
text_rect.set_left(s_box_width + 4);
|
||||
text_rect.set_left(s_box_width + s_horizontal_padding);
|
||||
text_rect.set_width(font().width(text()));
|
||||
text_rect.set_top(height() / 2 - font().glyph_height() / 2);
|
||||
text_rect.set_height(font().glyph_height());
|
||||
|
@ -86,4 +89,18 @@ void CheckBox::click(unsigned)
|
|||
set_checked(!is_checked());
|
||||
}
|
||||
|
||||
void CheckBox::set_autosize(bool autosize)
|
||||
{
|
||||
if (m_autosize == autosize)
|
||||
return;
|
||||
m_autosize = autosize;
|
||||
if (m_autosize)
|
||||
size_to_fit();
|
||||
}
|
||||
|
||||
void CheckBox::size_to_fit()
|
||||
{
|
||||
set_fixed_width(s_box_width + font().width(text()) + s_horizontal_padding * 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue