MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Picker.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @brief Receives the chosen index, or nullopt when the window was closed without a choice.
7 */
8using PickCallback = std::function<void(std::optional<size_t>)>;
9
10/**
11 * @brief Open a window of clickable rows, one per label, and report the choice.
12 *
13 * Requires Portal::Forma to be initialized and the engine running. The
14 * callback fires exactly once, on the event thread, so it must not block.
15 * Selecting a row hides the window and delivers its index. Closing the
16 * window delivers nullopt. Lists longer than ten rows scroll with the mouse
17 * wheel. An empty list delivers nullopt immediately.
18 *
19 * @param title Window title.
20 * @param labels Row captions, in display order.
21 * @param callback Invoked once with the chosen index or nullopt.
22 */
23MAYAFLUX_API void pick(
24 std::string title,
25 std::vector<std::string> labels,
27
28/**
29 * @brief Typed form of pick: list @p items by @p label and receive the chosen item.
30 *
31 * Same behaviour as pick. The callback receives a copy of the
32 * chosen item, or nullopt if the window was closed without a choice.
33 *
34 * @tparam T Item type, deduced from @p items.
35 * @param title Window title.
36 * @param items Candidates, in display order.
37 * @param label Maps an item to its row caption.
38 * @param callback Invoked once with the chosen item or nullopt.
39 */
40template <typename T>
41void pick(
42 std::string title,
43 std::vector<T> items,
44 std::type_identity_t<std::function<std::string(const T&)>> label,
45 std::type_identity_t<std::function<void(std::optional<T>)>> callback)
46{
47 std::vector<std::string> labels;
48 labels.reserve(items.size());
49 for (const auto& item : items) {
50 labels.push_back(label(item));
51 }
52
53 pick(std::move(title), std::move(labels),
54 [items = std::move(items), callback = std::move(callback)](std::optional<size_t> index) {
55 callback(index ? std::optional<T>(items.at(*index)) : std::nullopt);
56 });
57}
58
59} // namespace MayaFlux::Portal::Forma
uint32_t label
Definition Contours.cpp:16
PickCallback callback
Definition Picker.cpp:22
uint32_t index
Definition VKDevice.cpp:122
std::function< void(std::optional< size_t >)> PickCallback
Receives the chosen index, or nullopt when the window was closed without a choice.
Definition Picker.hpp:8
void pick(std::string title, std::vector< std::string > labels, PickCallback callback)
Open a window of clickable rows, one per label, and report the choice.
Definition Picker.cpp:46