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 {}
74 focus_group = std::forward<First>(first);
77 hi_static_no_default();
80 set_attributes(std::forward<Rest>(
rest)...);
96 this->delegate->deinit(*
this);
110 this->delegate->init(*
this);
111 _delegate_cbt = this->delegate->subscribe([&] {
112 set_value(this->delegate->state(*
this));
123 template<
typename...
Args>
125 requires(num_default_delegate_arguments<
Args...>() != 0)
137 _button_size = {theme().size(), theme().size()};
138 return box_constraints{_button_size, _button_size, _button_size, *attributes.alignment, theme().margin()};
141 void set_layout(widget_layout
const&
context)
noexcept override
144 _button_rectangle =
align(
context.rectangle(), _button_size, os_settings::alignment(*attributes.alignment));
146 _button_circle = circle{_button_rectangle};
148 _pip_circle =
align(_button_rectangle, circle{theme().size() * 0.5f - 3.0f}, alignment::middle_center());
153 void draw(draw_context
const&
context)
noexcept override
156 if (attributes.focus_group != keyboard_focus_group::menu) {
159 _button_circle * 1.02f,
162 theme().border_width(),
166 switch (_animated_value.update(value() == widget_value::on ? 1.0f : 0.0f,
context.display_time_point)) {
167 case animator_state::idle:
169 case animator_state::running:
172 case animator_state::end:
180 auto float_value = _animated_value.current_value();
189 hi_axiom(loop::main().on_thread());
190 if (phase() == widget_phase::pressed) {
191 return theme().color(semantic_color::fill, _layout.layer + 2);
193 return super::background_color();
197 [[
nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
199 hi_axiom(loop::main().on_thread());
202 return {
id, _layout.elevation, hitbox_type::button};
208 [[
nodiscard]]
bool accepts_keyboard_focus(keyboard_focus_group group)
const noexcept override
210 hi_axiom(loop::main().on_thread());
214 bool handle_event(gui_event
const&
event)
noexcept override
216 hi_axiom(loop::main().on_thread());
218 switch (
event.type()) {
219 case gui_event_type::gui_activate:
227 case gui_event_type::mouse_down:
234 case gui_event_type::mouse_up:
241 if (
event.mouse().hitbox.widget_id ==
id) {
243 handle_event(gui_event_type::gui_activate_stay);
260 extent2 _button_size;
261 aarectangle _button_rectangle;
263 circle _button_circle;
268 callback<
void()> _delegate_cbt;
Defines with_label_widget.
Defines menu_button_widget.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
@ 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
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
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
Definition not_null.hpp:22
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
radio_widget(not_null< widget * > parent, attributes_type attributes, not_null< std::shared_ptr< delegate_type > > delegate) noexcept
Construct a radio widget.
Definition radio_widget.hpp:104
radio_widget(not_null< widget_intf const * > parent, Args &&...args)
Construct a radio widget with a default button delegate.
Definition radio_widget.hpp:124
not_null< std::shared_ptr< delegate_type > > delegate
The delegate that controls the button widget.
Definition radio_widget.hpp:88
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:115
void request_redraw() const noexcept override
Request the widget to be redrawn on the next frame.
Definition widget.hpp:135
widget(widget_intf const *parent) noexcept
Definition widget.hpp:49
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:144
True if T is a forwarded type of Forward.
Definition concepts.hpp:136
Definition radio_widget.hpp:24