74 hi_assert_not_null(this->delegate);
80 this->delegate->init(*
this);
81 _delegate_cbt = this->delegate->subscribe([&] {
82 set_value(this->delegate->state(*
this));
88 [[nodiscard]] box_constraints update_constraints() noexcept
override
91 _on_label_constraints = _on_label_widget->update_constraints();
92 _off_label_constraints = _off_label_widget->update_constraints();
93 _other_label_constraints = _other_label_widget->update_constraints();
94 return max(_on_label_constraints, _off_label_constraints, _other_label_constraints);
97 void set_layout(widget_layout
const& context)
noexcept override
103 _on_label_widget->set_layout(context.transform(_on_label_shape));
104 _off_label_widget->set_layout(context.transform(_off_label_shape));
105 _other_label_widget->set_layout(context.transform(_other_label_shape));
108 [[nodiscard]] generator<widget_intf&> children(
bool include_invisible)
noexcept override
110 co_yield *_on_label_widget;
111 co_yield *_off_label_widget;
112 co_yield *_other_label_widget;
115 [[nodiscard]] color background_color() const noexcept
override
117 hi_axiom(loop::main().on_thread());
118 if (phase() == widget_phase::pressed) {
119 return theme().color(semantic_color::fill, _layout.layer + 2);
121 return super::background_color();
125 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
127 hi_axiom(loop::main().on_thread());
130 return {
id, _layout.elevation, hitbox_type::button};
136 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
138 hi_axiom(loop::main().on_thread());
142 void activate() noexcept
150 bool handle_event(gui_event
const& event)
noexcept override
152 hi_axiom(loop::main().on_thread());
154 switch (event.type()) {
155 case gui_event_type::gui_activate:
162 case gui_event_type::mouse_down:
169 case gui_event_type::mouse_up:
174 handle_event(gui_event_type::gui_activate);
188 box_constraints _on_label_constraints;
189 box_shape _on_label_shape;
192 box_constraints _off_label_constraints;
193 box_shape _off_label_shape;
196 box_constraints _other_label_constraints;
197 box_shape _other_label_shape;
199 callback<void()> _delegate_cbt;
202 void set_attributes() noexcept
206 template<
size_t I, button_widget_attribute First, button_widget_attribute... Rest>
207 void set_attributes(First&& first, Rest&&...rest)
noexcept
209 if constexpr (forward_of<First, observer<hi::label>>) {
210 if constexpr (I == 0) {
214 }
else if constexpr (I == 1) {
218 }
else if constexpr (I == 2) {
221 hi_static_no_default();
223 set_attributes<I + 1>(std::forward<Rest>(rest)...);
225 }
else if constexpr (forward_of<First, observer<hi::alignment>>) {
227 set_attributes<I>(std::forward<Rest>(rest)...);
229 }
else if constexpr (forward_of<First, observer<hi::semantic_text_style>>) {
231 set_attributes<I>(std::forward<Rest>(rest)...);
234 hi_static_no_default();
238 void draw_button(draw_context
const& context)
noexcept
240 _on_label_widget->draw(context);
241 _off_label_widget->draw(context);
242 _other_label_widget->draw(context);