38 constexpr static auto prefix = Prefix;
60 ~abstract_button_widget()
75 _delegate_cbt = this->delegate->subscribe([&] {
76 ++global_counter<
"abstract_button_widget:delegate:redraw">;
78 state = this->delegate->state(
this);
81 this->delegate->init(*
this);
85 [[nodiscard]] box_constraints update_constraints() noexcept
override
87 _on_label_constraints = _on_label_widget->update_constraints();
88 _off_label_constraints = _off_label_widget->update_constraints();
89 _other_label_constraints = _other_label_widget->update_constraints();
90 return max(_on_label_constraints, _off_label_constraints, _other_label_constraints);
93 void set_layout(widget_layout
const& context)
noexcept override
99 _on_label_widget->set_layout(context.transform(_on_label_shape));
100 _off_label_widget->set_layout(context.transform(_off_label_shape));
101 _other_label_widget->set_layout(context.transform(_other_label_shape));
104 [[nodiscard]] generator<widget const&> children(
bool include_invisible)
const noexcept override
106 co_yield *_on_label_widget;
107 co_yield *_off_label_widget;
108 co_yield *_other_label_widget;
111 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept final
116 return {
id, layout.elevation, hitbox_type::button};
122 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
128 void activate() noexcept
132 this->_state_changed();
135 bool handle_event(gui_event
const& event)
noexcept override
139 switch (event.type()) {
140 case gui_event_type::gui_activate:
147 case gui_event_type::mouse_down:
155 case gui_event_type::mouse_up:
159 if (layout.rectangle().contains(event.mouse().position)) {
160 handle_event(gui_event_type::gui_activate);
174 std::unique_ptr<label_widget<prefix /
"on">> _on_label_widget;
175 box_constraints _on_label_constraints;
176 box_shape _on_label_shape;
178 std::unique_ptr<label_widget<prefix /
"off">> _off_label_widget;
179 box_constraints _off_label_constraints;
180 box_shape _off_label_shape;
182 std::unique_ptr<label_widget<prefix /
"other">> _other_label_widget;
183 box_constraints _other_label_constraints;
184 box_shape _other_label_shape;
186 bool _pressed =
false;
187 notifier<>::callback_token _delegate_cbt;
190 void set_attributes() noexcept
195 void set_attributes(button_widget_attribute
auto&& first, button_widget_attribute
auto&&...rest)
noexcept
197 if constexpr (forward_of<
decltype(first), observer<hi::label>>) {
198 if constexpr (I == 0) {
202 }
else if constexpr (I == 1) {
206 }
else if constexpr (I == 2) {
213 }
else if constexpr (forward_of<
decltype(first), observer<hi::alignment>>) {
222 void draw_button(widget_draw_context& context)
noexcept
224 _on_label_widget->draw(context);
225 _off_label_widget->draw(context);
226 _other_label_widget->draw(context);
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:323
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253