mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +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
|
@ -27,9 +27,10 @@ Defines a GUI checkbox widget.
|
|||
|
||||
## Registered Properties
|
||||
|
||||
| Property | Type | Possible values | Description |
|
||||
|----------|------|-----------------|--------------------------|
|
||||
| autosize | bool | true or false | Determines if auto-sized |
|
||||
| Property | Type | Possible values | Description |
|
||||
|-------------------|--------|-------------------|--------------------------------------------------------------------|
|
||||
| autosize | bool | true or false | Determines if auto-sized |
|
||||
| checkbox_position | String | "Left" or "Right" | Place the checkbox itself on either the left or right of its label |
|
||||
|
||||
## See also
|
||||
- [GML Button](help://man/5/GML-Widget-Button)
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -22,6 +22,13 @@ public:
|
|||
bool is_autosize() const { return m_autosize; }
|
||||
void set_autosize(bool);
|
||||
|
||||
enum class CheckBoxPosition {
|
||||
Left,
|
||||
Right,
|
||||
};
|
||||
CheckBoxPosition checkbox_position() const { return m_checkbox_position; }
|
||||
void set_checkbox_position(CheckBoxPosition value) { m_checkbox_position = value; }
|
||||
|
||||
private:
|
||||
explicit CheckBox(String = {});
|
||||
|
||||
|
@ -34,6 +41,7 @@ private:
|
|||
virtual void paint_event(PaintEvent&) override;
|
||||
|
||||
bool m_autosize { false };
|
||||
CheckBoxPosition m_checkbox_position { CheckBoxPosition::Left };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue