7#include "selection_delegate.hpp"
8#include "../observable.hpp"
25 template<
typename OptionList,
typename Value,
typename OffValue>
27 options(std::forward<OptionList>(option_list)),
28 value(std::forward<Value>(value)),
29 off_value(std::forward<OffValue>(off_value))
33 template<
typename OptionList,
typename Value>
35 options(std::forward<OptionList>(option_list)), value(std::forward<Value>(value)), off_value(value_type{})
54 auto options_ = *options;
55 if (index == -1 || index >= std::ssize(options_)) {
58 value = options_[index].first;
64 ttlet value_ = *value;
65 auto options_ = *options;
68 labels.
reserve(std::size(options_));
71 auto selected_index = -1_z;
72 for (
auto &&option : options_) {
73 if (value_ == option.first) {
74 selected_index = index;
76 labels.push_back(
std::move(option.second));
80 return {
std::move(labels), selected_index};
84template<
typename OptionList,
typename Value,
typename... Args>
85default_selection_delegate(OptionList &&, Value &&, Args &&...)
86 -> default_selection_delegate<observable_argument_t<std::remove_cvref_t<Value>>>;
88template<
typename OptionList,
typename Value,
typename... Args>
90make_unique_default_selection_delegate(OptionList &&option_list, Value &&value, Args &&...args)
noexcept
92 using value_type = observable_argument_t<std::remove_cvref_t<Value>>;
93 return std::make_unique<default_selection_delegate<value_type>>(
94 std::forward<OptionList>(option_list), std::forward<Value>(value), std::forward<Args>(args)...);
An observable value.
Definition observable.hpp:280
void unsubscribe(callback_ptr_type const &callback_ptr) noexcept
Unsubscribe a callback function.
Definition observable.hpp:468
callback_ptr_type subscribe(Callback &&callback) noexcept
Subscribe a callback function.
Definition observable.hpp:442
Definition default_selection_delegate.hpp:17
std::pair< std::vector< label >, ssize_t > options_and_selected(selection_widget const &sender) const noexcept override
Retrieve the label of an option.
Definition default_selection_delegate.hpp:62
callback_ptr_type subscribe(selection_widget &sender, callback_ptr_type const &callback_ptr) noexcept override
Subscribe a callback for notifying the widget of a data change.
Definition default_selection_delegate.hpp:39
void unsubscribe(selection_widget &sender, callback_ptr_type const &callback_ptr) noexcept override
Unsubscribe a callback.
Definition default_selection_delegate.hpp:46
void set_selected(selection_widget &sender, ssize_t index) noexcept override
Called when an option is selected by the user.
Definition default_selection_delegate.hpp:52
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