24 template <std::predicate<
int> Predicate>
29 bool operator()(
int slot)
const {
return _predicate ? _predicate(slot) : _fixed; }
32 std::function<bool(
int slot)> _predicate;
39 { row.ToItem() } -> std::same_as<MenuItem>;
56 std::function<bool(
int slot)>
Get;
57 std::function<void(
int slot)>
Flip;
75 std::function<int(
int slot)>
Get;
76 std::function<void(
int slot,
int index)>
Set;
83 std::function<
void(
int slot,
int index)> commit, std::optional<ChoiceIndex> bind,
int index,
94 std::function<void(
int slot,
const T& value)>
Commit;
96 std::optional<ChoiceIndex>
Bind;
104 std::vector<std::string> labels;
105 std::vector<T> values;
106 for (
const auto& [label, value] :
Choices)
108 labels.push_back(label);
109 values.push_back(value);
112 std::function<void(
int slot,
int index)> commitIndex;
115 commitIndex = [values = std::move(values), commit =
Commit](
int slot,
int index) {
116 commit(slot, values[
static_cast<std::size_t
>(index)]);
131 std::function<std::string(
int slot)>
Get;
132 std::function<bool(
int slot, std::string_view text)>
Set;
143 std::function<std::shared_ptr<Menu>(
int slot)>
Build;
163 explicit MenuBuilder(std::string title) { _menu.Title = std::move(title); }
168 _menu.
Subtitle = std::move(subtitle);
175 _menu.Items.push_back(std::move(item));
185 return Add(
ButtonRow{.Label = std::move(label), .Activate = std::move(activate)});
191 return Add(
SubmenuRow{.Label = std::move(label), .Build = std::move(build)});
200 _emptyText = std::move(label);
207 if (_menu.Items.empty() && !_emptyText.empty())
209 Text(std::move(_emptyText));
212 return std::make_shared<Menu>(std::move(_menu));
217 std::string _emptyText;
bool operator()(int slot) const
EnabledCondition(bool value)
EnabledCondition()=default
EnabledCondition(Predicate predicate)
MenuItem ChoiceItem(std::string label, std::vector< std::string > choices, std::function< void(int slot, int index)> commit, std::optional< ChoiceIndex > bind, int index, EnabledCondition enabled, ChoiceApply apply)
std::function< void(int slot, int index)> Set
std::function< int(int slot)> Get
std::vector< Labeled< T > > Choices
std::function< void(int slot, const T &value)> Commit
std::optional< ChoiceIndex > Bind
std::function< bool(int slot)> Get
std::function< void(int slot)> Flip