61 ~abstract_button_widget()
70 hi_assert_not_null(this->delegate);
73 _on_label_widget->set_parent(
this);
75 _off_label_widget->set_parent(
this);
77 _other_label_widget->set_parent(
this);
79 this->delegate->init(*
this);
80 _delegate_cbt = this->delegate->subscribe([&] {
81 set_value(this->delegate->state(*
this));
90 _on_label_constraints = _on_label_widget->update_constraints();
91 _off_label_constraints = _off_label_widget->update_constraints();
92 _other_label_constraints = _other_label_widget->update_constraints();
93 return max(_on_label_constraints, _off_label_constraints, _other_label_constraints);
96 void set_layout(widget_layout
const& context)
noexcept override
102 _on_label_widget->set_layout(context.transform(_on_label_shape));
103 _off_label_widget->set_layout(context.transform(_off_label_shape));
104 _other_label_widget->set_layout(context.transform(_other_label_shape));
107 [[nodiscard]] generator<widget_intf&> children(
bool include_invisible)
noexcept override
109 co_yield *_on_label_widget;
110 co_yield *_off_label_widget;
111 co_yield *_other_label_widget;
114 [[nodiscard]]
color background_color() const noexcept
override
116 hi_axiom(loop::main().on_thread());
117 if (phase() == widget_phase::pressed) {
118 return theme().fill_color(_layout.layer + 2);
120 return super::background_color();
124 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
126 hi_axiom(loop::main().on_thread());
129 return {
id, _layout.elevation, hitbox_type::button};
135 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
137 hi_axiom(loop::main().on_thread());
141 void activate() noexcept
149 bool handle_event(gui_event
const& event)
noexcept override
151 hi_axiom(loop::main().on_thread());
153 switch (event.type()) {
154 case gui_event_type::gui_activate:
161 case gui_event_type::mouse_down:
168 case gui_event_type::mouse_up:
173 handle_event(gui_event_type::gui_activate);
186 std::unique_ptr<label_widget> _on_label_widget;
187 box_constraints _on_label_constraints;
188 box_shape _on_label_shape;
190 std::unique_ptr<label_widget> _off_label_widget;
191 box_constraints _off_label_constraints;
192 box_shape _off_label_shape;
194 std::unique_ptr<label_widget> _other_label_widget;
195 box_constraints _other_label_constraints;
196 box_shape _other_label_shape;
198 callback<void()> _delegate_cbt;
201 void set_attributes() noexcept
205 template<
size_t I, button_widget_attribute First, button_widget_attribute... Rest>
206 void set_attributes(First&& first, Rest&&...rest)
noexcept
208 if constexpr (forward_of<First, observer<hi::label>>) {
209 if constexpr (I == 0) {
213 }
else if constexpr (I == 1) {
217 }
else if constexpr (I == 2) {
220 hi_static_no_default();
224 }
else if constexpr (forward_of<First, observer<hi::alignment>>) {
229 hi_static_no_default();
233 void draw_button(draw_context
const& context)
noexcept
235 _on_label_widget->draw(context);
236 _off_label_widget->draw(context);
237 _other_label_widget->draw(context);