33 using super = abstract_button_widget;
34 using delegate_type =
typename super::delegate_type;
52 set_attributes<0>(hi_forward(attributes)...);
79 hi_forward(attributes)...)
89 _check_size = {theme().size(), theme().size()};
90 _short_cut_size = {theme().size(), theme().size()};
93 hilet extra_size = extent2{
94 theme().margin<
float>() * 4.0f + _check_size.width() + _short_cut_size.width(), theme().margin<
float>() * 2.0f};
96 auto constraints = _label_constraints + extra_size;
97 constraints.margins = 0;
101 void set_layout(widget_layout
const& context)
noexcept override
104 hilet inside_rectangle = context.rectangle() - theme().margin<
float>();
106 if (os_settings::left_to_right()) {
107 _check_rectangle =
align(inside_rectangle, _check_size, alignment::middle_left());
108 _short_cut_rectangle =
align(inside_rectangle, _short_cut_size, alignment::middle_right());
109 hilet label_rectangle = aarectangle{
110 point2{_check_rectangle.right() + theme().margin<
float>(), 0.0f},
111 point2{_short_cut_rectangle.left() - theme().margin<
float>(), context.height()}};
112 _on_label_shape = _off_label_shape = _other_label_shape =
113 box_shape{_label_constraints, label_rectangle, theme().baseline_adjustment()};
116 _short_cut_rectangle =
align(inside_rectangle, _short_cut_size, alignment::middle_left());
117 _check_rectangle =
align(inside_rectangle, _check_size, alignment::middle_right());
118 hilet label_rectangle = aarectangle{
119 point2{_short_cut_rectangle.right() + theme().margin<
float>(), 0.0f},
120 point2{_check_rectangle.left() - theme().margin<
float>(), context.height()}};
121 _on_label_shape = _off_label_shape = _other_label_shape =
122 box_shape{_label_constraints, label_rectangle, theme().baseline_adjustment()};
126 hilet check_glyph_bb = _check_glyph.get_metrics().bounding_rectangle * theme().icon_size();
127 _check_glyph_rectangle =
align(_check_rectangle, check_glyph_bb, alignment::middle_center());
130 super::set_layout(context);
133 void draw(draw_context
const& context)
noexcept override
136 draw_menu_button(context);
137 draw_check_mark(context);
138 draw_button(context);
142 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
147 bool handle_event(gui_event
const& event)
noexcept override
151 switch (event.type()) {
155 nullptr, keyboard_focus_group::menu, keyboard_focus_direction::forward));
163 nullptr, keyboard_focus_group::menu, keyboard_focus_direction::backward));
172 nullptr, keyboard_focus_group::normal, keyboard_focus_direction::forward));
174 nullptr, keyboard_focus_group::normal, keyboard_focus_direction::backward));
182 return super::handle_event(event);
186 box_constraints _label_constraints;
188 font_book::font_glyph_type _check_glyph;
190 aarectangle _check_rectangle;
191 aarectangle _check_glyph_rectangle;
192 extent2 _short_cut_size;
193 aarectangle _short_cut_rectangle;
195 void draw_menu_button(draw_context
const& context)
noexcept
197 hilet border_color = *
focus ? focus_color() : color::transparent();
201 void draw_check_mark(draw_context
const& context)
noexcept
203 auto state_ =
state();
206 if (state_ == hi::button_state::on) {
207 context.draw_glyph(
layout(), translate_z(0.1f) * _check_glyph_rectangle, _check_glyph, accent_color());