14#include "../algorithm/module.hpp"
15#include "../l10n/l10n.hpp"
16#include "../observer/module.hpp"
17#include "../macros.hpp"
24namespace hi {
inline namespace v1 {
26template<
typename Context>
62 notifier<
void()> pressed;
73 hi_assert_not_null(this->delegate);
78 _delegate_cbt = this->delegate->subscribe([&] {
79 ++global_counter<
"abstract_button_widget:delegate:relayout">;
82 this->delegate->init(*
this);
90 hi_axiom(loop::main().on_thread());
99 _on_label_constraints = _on_label_widget->update_constraints();
100 _off_label_constraints = _off_label_widget->update_constraints();
101 _other_label_constraints = _other_label_widget->update_constraints();
102 return max(_on_label_constraints, _off_label_constraints, _other_label_constraints);
105 void set_layout(widget_layout
const&
context)
noexcept override
112 _on_label_widget->set_layout(
context.transform(_on_label_shape));
113 _off_label_widget->set_layout(
context.transform(_off_label_shape));
114 _other_label_widget->set_layout(
context.transform(_other_label_shape));
119 co_yield *_on_label_widget;
120 co_yield *_off_label_widget;
121 co_yield *_other_label_widget;
126 hi_axiom(loop::main().on_thread());
130 return super::background_color();
134 [[
nodiscard]] hitbox hitbox_test(point2 position)
const noexcept final
136 hi_axiom(loop::main().on_thread());
139 return {
id, _layout.elevation, hitbox_type::button};
145 [[
nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
147 hi_axiom(loop::main().on_thread());
159 bool handle_event(gui_event
const&
event)
noexcept override
161 hi_axiom(loop::main().on_thread());
163 switch (
event.type()) {
164 case gui_event_type::gui_activate:
171 case gui_event_type::mouse_down:
179 case gui_event_type::mouse_up:
184 handle_event(gui_event_type::gui_activate);
199 box_constraints _on_label_constraints;
200 box_shape _on_label_shape;
203 box_constraints _off_label_constraints;
204 box_shape _off_label_shape;
207 box_constraints _other_label_constraints;
208 box_shape _other_label_shape;
210 bool _pressed =
false;
211 notifier<>::callback_token _delegate_cbt;
219 void set_attributes(button_widget_attribute
auto&& first, button_widget_attribute
auto&&...
rest)
noexcept
222 if constexpr (I == 0) {
226 }
else if constexpr (I == 1) {
230 }
else if constexpr (I == 2) {
233 hi_static_no_default();
246 hi_static_no_default();
250 void draw_button(draw_context
const&
context)
noexcept
252 _on_label_widget->draw(
context);
253 _off_label_widget->draw(
context);
254 _other_label_widget->draw(
context);
Defines button_delegate and some default button delegates.
@ window_relayout
Request that widgets get laid out on the next frame.
@ rectangle
The gui_event has rectangle data.
button_state
The state of a button.
Definition button_delegate.hpp:23
@ off
The 'off' state of a button.
@ other
The other state of a button.
@ on
The 'on' state of a button.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
@ display
The widget is in display-only mode.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:23
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
A localizable message.
Definition txt.hpp:100
2D constraints.
Definition box_constraints.hpp:25
Base class for implementing button widgets.
Definition abstract_button_widget.hpp:33
observer< semantic_text_style > text_style
The text style to button's label.
Definition abstract_button_widget.hpp:60
observer< label > other_label
The label to show when the button is in the 'other' state.
Definition abstract_button_widget.hpp:52
std::shared_ptr< delegate_type > delegate
The delegate that controls the button widget.
Definition abstract_button_widget.hpp:40
button_state state() const noexcept
Get the current state of the button.
Definition abstract_button_widget.hpp:88
observer< label > on_label
The label to show when the button is in the 'on' state.
Definition abstract_button_widget.hpp:44
observer< label > off_label
The label to show when the button is in the 'off' state.
Definition abstract_button_widget.hpp:48
observer< alignment > alignment
The alignment of the button and on/off/other label.
Definition abstract_button_widget.hpp:56
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:45
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget_layout const & layout() const noexcept override
Get the current layout for this widget.
Definition widget.hpp:169
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:66
widget(widget *parent) noexcept
Definition widget.hpp:87
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:189
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:178
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:198
Definition abstract_button_widget.hpp:27
Definition label_widget.hpp:27