5#include "../dispatch/dispatch.hpp"
6#include "../observer/observer.hpp"
7#include "../GUI/GUI.hpp"
8#include "../utility/utility.hpp"
10hi_export_module(hikogui.widgets.toggle_delegate);
12hi_export
namespace hi {
34 return widget_value::off;
39 template<forward_of<
void()> Func>
42 return _notifier.subscribe(std::forward<Func>(
func), flags);
46 notifier<
void()> _notifier;
57template<std::equality_comparable T>
61 constexpr static bool can_make_defaults =
62 std::is_same_v<value_type, bool>
or std::is_integral_v<value_type>
or std::is_enum_v<value_type>;
79 value(std::forward<Value>(value)), on_value(std::forward<OnValue>(on_value)), off_value(std::forward<OffValue>(off_value))
82 _value_cbt = this->value.
subscribe([&](
auto...){ this->_notifier(); });
83 _on_value_cbt = this->on_value.
subscribe([&](
auto...){ this->_notifier(); });
84 _off_value_cbt = this->off_value.
subscribe([&](
auto...){ this->_notifier(); });
93 template<forward_of<observer<value_type>> Value, forward_of<observer<value_type>> OnValue>
96 OnValue&& on_value)
noexcept requires can_make_defaults
105 template<forward_of<observer<value_type>> Value>
112 [[
nodiscard]] widget_value state(widget_intf
const&
sender)
const noexcept override
114 if (*value == *on_value) {
115 return widget_value::on;
116 }
else if (*value == *off_value) {
117 return widget_value::off;
119 return widget_value::other;
123 void activate(widget_intf
const&
sender)
noexcept override
125 if (*value == *off_value) {
133 callback<
void(value_type)> _value_cbt;
134 callback<
void(value_type)> _on_value_cbt;
135 callback<
void(value_type)> _off_value_cbt;
138template<
typename Value>
141template<
typename Value,
typename OnValue>
144template<
typename Value,
typename OnValue,
typename OffValue>
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
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 button delegate controls the state of a button widget.
Definition toggle_delegate.hpp:18
virtual widget_value state(widget_intf const &sender) const noexcept
Used by the widget to check the state of the button.
Definition toggle_delegate.hpp:32
callback< void()> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition toggle_delegate.hpp:40
virtual void activate(widget_intf const &sender) noexcept
Called when the button is pressed by the user.
Definition toggle_delegate.hpp:28
A default toggle button delegate.
Definition toggle_delegate.hpp:58
default_toggle_delegate(Value &&value) noexcept
Construct a delegate.
Definition toggle_delegate.hpp:106
default_toggle_delegate(Value &&value, OnValue &&on_value) noexcept
Construct a delegate.
Definition toggle_delegate.hpp:94
default_toggle_delegate(Value &&value, OnValue &&on_value, OffValue &&off_value) noexcept
Construct a delegate.
Definition toggle_delegate.hpp:78