5#include <portals/combo_box.hpp>
6#include <portals/ui_scene_pipeline.hpp>
7#include <portals/ui_suggestions.hpp>
14 .options = {.limits = {4096, 4096, 4096,
35 template <std::derived_from<ComboBox> T>
37 return std::move(description).fuzzy(modifier.
enabled);
44inline ChoiceSearchModifier fuzzy(
bool enabled =
true) {
55Description<ComboBox> comboBoxRecipe(std::shared_ptr<portals::detail::FindModelSource>, ComboBoxConfig);
56Description<DropDown> dropDownRecipe(std::shared_ptr<portals::detail::FindModelSource>, ComboBoxConfig);
57std::shared_ptr<portals::detail::FindModelSource> choiceStrings(std::initializer_list<std::string_view>);
58std::expected<void, ManagedError> choiceSelectHandler(
const std::shared_ptr<RefTarget> &,
59 std::function<
void(ChoiceSelection)>, std::source_location);
61template <
class Projection>
struct ChoiceProjection {
62 Projection projection;
63 std::size_t maxBytes{4096};
66 requires(std::same_as<std::remove_cvref_t<std::invoke_result_t<const Projection &, const T &>>, std::string> ||
67 std::same_as<std::invoke_result_t<const Projection &, const T &>, std::string_view> ||
68 (std::is_lvalue_reference_v<std::invoke_result_t<const Projection &, const T &>> &&
69 std::convertible_to<std::invoke_result_t<const Projection &, const T &>, std::string_view>))
70 auto operator()(
const T &row)
const {
71 using Result = std::invoke_result_t<const Projection &, const T &>;
72 if constexpr (std::same_as<std::remove_cvref_t<Result>, std::string> && !std::is_lvalue_reference_v<Result>) {
73 auto text = std::invoke(projection, row);
74 if (
text.size() > maxBytes) {
75 throw portals::detail::ProjectionLimit{};
79 return std::string_view(std::invoke(projection, row));
84template <
class Projection,
class T>
85concept ChoiceProjectionFor = std::is_nothrow_move_constructible_v<Projection> &&
86 (std::same_as<std::invoke_result_t<const Projection &, const T &>, std::string_view> ||
87 std::same_as<std::invoke_result_t<const Projection &, const T &>, std::string>);
89template <
class T,
class Projection>
90 requires ChoiceProjectionFor<Projection, T>
91auto choiceSource(ManagedModel<T> source, Projection projection) {
92 return std::make_shared<FindModelSourceOf<T, Projection>>(std::move(source), std::move(projection));
95template <
class T,
class Projection>
96 requires ChoiceProjectionFor<Projection, T>
97auto choiceSource(std::shared_ptr<
const ModelSnapshot<T>> source, Projection projection) {
98 return std::make_shared<FindModelSourceOf<T, Projection>>(std::move(source), std::move(projection));
101template <
class T,
class Projection>
102 requires ChoiceProjectionFor<Projection, T>
103auto choiceSource(std::expected<RowCollection<T>,
TreeError> source, Projection projection) {
104 return std::make_shared<FindCollectionSourceOf<T, Projection>>(std::move(source), std::move(projection));
107template <
class T,
class Projection>
108 requires ChoiceProjectionFor<Projection, T>
109auto choiceSource(RowCollection<T> source, Projection projection) {
110 return choiceSource(std::expected<RowCollection<T>,
TreeError>(std::move(source)), std::move(projection));
113template <
class Source,
class Projection>
114concept ChoiceSource =
requires(Source source, Projection projection) {
115 choiceSource(std::move(source), ChoiceProjection<Projection>{std::move(projection)});
128template <
class Source,
class Projection>
129 requires detail::ChoiceSource<Source, Projection>
131 auto binding = detail::choiceSource(
132 std::move(source), detail::ChoiceProjection<Projection>{std::move(projection), config.search.maxRowBytes});
133 return detail::comboBoxRecipe(std::move(binding), std::move(config));
137template <
class Source,
class Projection>
138 requires detail::ChoiceSource<Source, Projection>
140 auto binding = detail::choiceSource(
141 std::move(source), detail::ChoiceProjection<Projection>{std::move(projection), config.search.maxRowBytes});
142 return detail::dropDownRecipe(std::move(binding), std::move(config));
150 return detail::comboBoxRecipe(detail::choiceStrings(values), std::move(config));
155 return detail::dropDownRecipe(detail::choiceStrings(values), std::move(config));
162template <
class Source,
class Projection>
163 requires detail::ChoiceSource<Source, Projection>
166 return comboBox(std::move(source), std::move(projection), std::move(config)).reference(std::move(reference));
170template <
class Source,
class Projection>
171 requires detail::ChoiceSource<Source, Projection>
174 return dropDown(std::move(source), std::move(projection), std::move(config)).reference(std::move(reference));
182 return comboBox(values, std::move(config)).reference(std::move(reference));
188 return dropDown(values, std::move(config)).reference(std::move(reference));
196template <std::derived_from<ComboBox> T,
class Callback = detail::QuitCommand>
197 requires portals::detail::ManagedAction<Callback, ChoiceSelection>
198auto onSelect(
Ref<T> reference, Callback callback, std::source_location origin = std::source_location::current()) {
199 detail::commandOrigin(callback, origin);
201 origin](ManagedScene &scene)
mutable -> std::expected<void, ManagedError> {
202 auto adapter = detail::Access::choiceHandler(scene,
reference.node(), std::move(callback), origin);
206 origin](
Scene &owner)
mutable {
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Single-use lazy owner of one Application and ManagedScene; no second runtime. Construct and operate o...
Definition ui_scene.hpp:253
auto reference(ui::Ref< T > value)
Definition ui_static.hpp:572
SearchError
Search/provider errors, separate from scheduler and UI delivery errors.
Definition search.hpp:12
@ PREFIX
Exact normalized prefix of the complete label or a whitespace token.
Definition search.hpp:25
ui::ValueText text(std::format_string< const ui::detail::TextArgumentValue< Args > &... > pattern, Args &&...args)
Declare live formatted text over explicit scalar roots, fields or value properties.
Definition ui_value_text.hpp:567
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
Configurable finite source, index, query and result budgets.
Definition search.hpp:30
Owning choice matching stage, preserving every worker budget.
Definition ui_combo_box.hpp:28
bool enabled
True selects FUZZY_PREFIX; false selects PREFIX.
Definition ui_combo_box.hpp:29
friend Description< T > operator|(Description< T > &&description, ChoiceSearchModifier modifier)
Definition ui_combo_box.hpp:36
Independent finite browse, popup and indexed-completion settings.
Definition ui_combo_box.hpp:11
bool searchable
DropDown popup offers a separate ordinary query editor.
Definition ui_combo_box.hpp:20
std::size_t pageRows
Positive browse page cap, at most256.
Definition ui_combo_box.hpp:17
std::size_t browseScratchBytes
Transient projection pins/range metadata; output has row/text caps.
Definition ui_combo_box.hpp:23
std::function< void(SearchError)> failed
Newest provider failure; draft and accepted value survive.
Definition ui_combo_box.hpp:22
std::optional< std::uint64_t > initial
Optional source ordinal resolved asynchronously after mount.
Definition ui_combo_box.hpp:21
LineEditConfig editor
Normal editor modes, validation and history; protected display is rejected.
Definition ui_combo_box.hpp:13
std::int32_t popupWidth
Positive maximum panel width in terminal cells.
Definition ui_combo_box.hpp:19
SearchOptions search
Finite search budgets; PREFIX by default.
Definition ui_combo_box.hpp:16
std::int32_t popupRows
Positive visible list height in terminal rows.
Definition ui_combo_box.hpp:18
Owning optional editor customization and confirmation policy.
Definition ui_description.hpp:34
static std::shared_ptr< RefTarget > target(const DynamicRef &reference)
Definition ui_ref.hpp:2704
static void onEditing(Scene &owner, Callback &callback, std::source_location origin)
Definition ui_scene.hpp:1289
Owning minimal pipe adapter forwarding to the same facade method.
Definition ui_scene_pipeline.hpp:29