14#include "radio_delegate.hpp"
15#include "../telemetry/telemetry.hpp"
16#include "../macros.hpp"
18hi_export_module(hikogui.widgets.radio_widget);
20hi_export
namespace hi {
23template<
typename Context>
52 keyboard_focus_group focus_group = keyboard_focus_group::normal;
62 set_attributes(std::forward<Attributes>(attributes)...);
65 void set_attributes()
noexcept {}
68 void set_attributes(First&& first, Rest&&...rest)
noexcept
74 focus_group = std::forward<First>(first);
77 hi_static_no_default();
80 set_attributes(std::forward<Rest>(rest)...);
91 hi_call_left_arguments(
static, make_default_delegate, make_shared_ctad<default_radio_delegate>);
96 this->delegate->deinit(*
this);
110 hi_axiom_not_null(this->delegate);
111 this->delegate->init(*
this);
112 _delegate_cbt = this->delegate->subscribe([&] {
113 set_value(this->delegate->state(*
this));
124 template<
typename... Args>
126 requires(num_default_delegate_arguments<Args...>() != 0)
130 make_attributes<num_default_delegate_arguments<Args...>()>(std::forward<Args>(args)...),
131 make_default_delegate<num_default_delegate_arguments<Args...>()>(std::forward<Args>(args)...))
138 _button_size = {theme().size(), theme().size()};
139 return box_constraints{_button_size, _button_size, _button_size, *attributes.alignment, theme().margin()};
142 void set_layout(widget_layout
const& context)
noexcept override
145 _button_rectangle =
align(context.rectangle(), _button_size, os_settings::alignment(*attributes.alignment));
147 _button_circle = circle{_button_rectangle};
149 _pip_circle =
align(_button_rectangle, circle{theme().size() * 0.5f - 3.0f}, alignment::middle_center());
154 void draw(draw_context
const& context)
noexcept override
157 if (attributes.focus_group != keyboard_focus_group::menu) {
160 _button_circle * 1.02f,
163 theme().border_width(),
167 switch (_animated_value.update(value() == widget_value::on ? 1.0f : 0.0f, context.display_time_point)) {
168 case animator_state::idle:
170 case animator_state::running:
173 case animator_state::end:
181 auto float_value = _animated_value.current_value();
182 if (float_value > 0.0) {
183 context.draw_circle(
layout(), _pip_circle * 1.02f * float_value, accent_color());
188 [[nodiscard]] color background_color() const noexcept
override
190 hi_axiom(loop::main().on_thread());
191 if (phase() == widget_phase::pressed) {
192 return theme().color(semantic_color::fill, _layout.layer + 2);
194 return super::background_color();
198 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
200 hi_axiom(loop::main().on_thread());
203 return {
id, _layout.elevation, hitbox_type::button};
209 [[nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
211 hi_axiom(loop::main().on_thread());
215 bool handle_event(gui_event
const& event)
noexcept override
217 hi_axiom(loop::main().on_thread());
219 switch (event.type()) {
220 case gui_event_type::gui_activate:
228 case gui_event_type::mouse_down:
235 case gui_event_type::mouse_up:
242 if (event.mouse().hitbox.widget_id ==
id) {
244 handle_event(gui_event_type::gui_activate_stay);
261 extent2 _button_size;
262 aarectangle _button_rectangle;
264 circle _button_circle;
266 animator<float> _animated_value = _animation_duration;
269 callback<void()> _delegate_cbt;
272using radio_with_label_widget = with_label_widget<radio_widget>;
273using radio_menu_button_widget = menu_button_widget<radio_widget>;
Defines with_label_widget.
Defines menu_button_widget.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
The HikoGUI namespace.
Definition array_generic.hpp:20
@ inside
The border is drawn inside the edge of a quad.
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
Definition widget_intf.hpp:24
notifier< void()> notifier
Notifier which is called after an action is completed by a widget.
Definition widget_intf.hpp:39
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:30
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
2D constraints.
Definition box_constraints.hpp:25
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
A radio delegate controls the state of a radio button widget.
Definition radio_delegate.hpp:16
A default radio button delegate.
Definition radio_delegate.hpp:56
A GUI widget that permits the user to make a binary choice.
Definition radio_widget.hpp:45
std::shared_ptr< delegate_type > delegate
The delegate that controls the button widget.
Definition radio_widget.hpp:88
radio_widget(widget_intf const *parent, attributes_type attributes, std::shared_ptr< delegate_type > delegate) noexcept
Construct a radio widget.
Definition radio_widget.hpp:104
radio_widget(widget_intf const *parent, Args &&...args)
Construct a radio widget with a default button delegate.
Definition radio_widget.hpp:125
Definition radio_widget.hpp:50
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
void set_layout(widget_layout const &context) noexcept override
Update the internal layout of the widget.
Definition widget.hpp:121
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:141
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:150
True if T is a forwarded type of Forward.
Definition concepts.hpp:137
Definition radio_widget.hpp:24