7#include "selection_delegate.hpp"
8#include "../observable.hpp"
14namespace hi::inline v1 {
29 _options_cbt = this->options.subscribe([&](
auto...){ this->_notifier(); });
30 _value_cbt = this->value.subscribe([&](
auto...){ this->_notifier(); });
31 _off_value_cbt = this->off_value.subscribe([&](
auto...){ this->_notifier(); });
40 void set_selected(
selection_widget &sender, ptrdiff_t index)
noexcept override
42 if (index == -1 || index >= std::ssize(*options)) {
45 value = (*options)[index].first;
52 labels.
reserve(options->size());
55 auto selected_index = -1_z;
56 for (
auto &&option : *options) {
57 if (*value == option.first) {
58 selected_index = index;
60 labels.push_back(option.second);
64 return {
std::move(labels), selected_index};
68 typename decltype(options)::token_type _options_cbt;
69 typename decltype(value)::token_type _value_cbt;
70 typename decltype(off_value)::token_type _off_value_cbt;
73template<
typename OptionList,
typename Value,
typename... Args>
74default_selection_delegate(OptionList &&, Value &&, Args &&...)
75 -> default_selection_delegate<observable_argument_t<std::remove_cvref_t<Value>>>;
77template<
typename OptionList,
typename Value,
typename... Args>
79make_unique_default_selection_delegate(OptionList &&option_list, Value &&value, Args &&...args)
noexcept
81 using value_type = observable_argument_t<std::remove_cvref_t<Value>>;
82 return std::make_unique<default_selection_delegate<value_type>>(
83 std::forward<OptionList>(option_list), std::forward<Value>(value), std::forward<Args>(args)...);
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition required.hpp:29
An observable value.
Definition observable.hpp:359
Definition default_selection_delegate.hpp:17
std::pair< std::vector< label >, ptrdiff_t > options_and_selected(selection_widget const &sender) const noexcept override
Retrieve the label of an option.
Definition default_selection_delegate.hpp:49
Definition selection_delegate.hpp:15
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:37