mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibGUI: Add ability to position checkboxes to the right of their text
This uses the new `checkbox_position` property, which can be "Left" or "Right".
This commit is contained in:
parent
0ef3c15822
commit
aadb35ff46
3 changed files with 21 additions and 4 deletions
|
@ -25,6 +25,11 @@ CheckBox::CheckBox(String text)
|
|||
{
|
||||
REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize);
|
||||
|
||||
REGISTER_ENUM_PROPERTY(
|
||||
"checkbox_position", checkbox_position, set_checkbox_position, CheckBoxPosition,
|
||||
{ CheckBoxPosition::Left, "Left" },
|
||||
{ CheckBoxPosition::Right, "Right" });
|
||||
|
||||
set_min_width(32);
|
||||
set_fixed_height(22);
|
||||
}
|
||||
|
@ -35,7 +40,8 @@ void CheckBox::paint_event(PaintEvent& event)
|
|||
painter.add_clip_rect(event.rect());
|
||||
|
||||
auto text_rect = rect();
|
||||
text_rect.set_left(s_box_width + s_horizontal_padding);
|
||||
if (m_checkbox_position == CheckBoxPosition::Left)
|
||||
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());
|
||||
|
@ -50,6 +56,8 @@ void CheckBox::paint_event(PaintEvent& event)
|
|||
0, height() / 2 - s_box_height / 2 - 1,
|
||||
s_box_width, s_box_height
|
||||
};
|
||||
if (m_checkbox_position == CheckBoxPosition::Right)
|
||||
box_rect.set_right_without_resize(rect().right());
|
||||
|
||||
Gfx::StylePainter::paint_check_box(painter, box_rect, palette(), is_enabled(), is_checked(), is_being_pressed());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue