4#include "../dispatch/dispatch.hpp"
5#include "../observer/observer.hpp"
6#include "../GUI/GUI.hpp"
7#include "../utility/utility.hpp"
9hi_export_module(hikogui.widgets.radio_delegate);
11hi_export
namespace hi {
inline namespace v1 {
20 virtual void init(
widget_intf const& sender)
noexcept {}
22 virtual void deinit(
widget_intf const& sender)
noexcept {}
32 return widget_value::off;
37 template<forward_of<
void()> Func>
38 [[nodiscard]]
callback<void()>
subscribe(Func&& func, callback_flags flags = callback_flags::synchronous)
noexcept
40 return _notifier.subscribe(std::forward<Func>(func), flags);
44 notifier<void()> _notifier;
55template<std::equality_comparable T>
68 template<forward_of<observer<value_type>> Value, forward_of<observer<value_type>> OnValue>
71 OnValue&& on_value) noexcept :
72 value(std::forward<Value>(value)), on_value(std::forward<OnValue>(on_value))
75 _value_cbt = this->value.
subscribe([&](
auto...){ this->_notifier(); });
76 _on_value_cbt = this->on_value.
subscribe([&](
auto...){ this->_notifier(); });
81 [[nodiscard]] widget_value state(
widget_intf const& sender)
const noexcept override
83 if (*value == *on_value) {
84 return widget_value::on;
86 return widget_value::off;
90 void activate(widget_intf
const& sender)
noexcept override
96 callback<void(value_type)> _value_cbt;
97 callback<void(value_type)> _on_value_cbt;
100template<
typename Value,
typename OnValue>
101default_radio_delegate(Value&&, OnValue&&) -> default_radio_delegate<observer_decay_t<Value>>;
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition callback.hpp:77
Definition widget_intf.hpp:24
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
callback< void(value_type)> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback to this observer.
Definition observer_intf.hpp:456
A radio delegate controls the state of a radio button widget.
Definition radio_delegate.hpp:16
virtual widget_value state(widget_intf const &sender) const noexcept
Used by the widget to check the state of the button.
Definition radio_delegate.hpp:30
callback< void()> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition radio_delegate.hpp:38
virtual void activate(widget_intf const &sender) noexcept
Called when the button is pressed by the user.
Definition radio_delegate.hpp:26
A default radio button delegate.
Definition radio_delegate.hpp:56
default_radio_delegate(Value &&value, OnValue &&on_value) noexcept
Construct a delegate.
Definition radio_delegate.hpp:69