Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_recipe_access.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/recipe_state.hpp>
6#include <portals/detail/ui_recipe_context.hpp>
7#include <portals/ui_action.hpp>
8
9#include <format>
10
11namespace portals {
12struct SearchItem;
13
14namespace detail {
15struct FindExternalBinding;
16struct EditTextBinding;
17} // namespace detail
18} // namespace portals
19
20namespace portals::ui {
21struct FormFieldConfig;
22struct LineEditConfig;
23struct FindBarConfig;
25
26namespace detail {
28struct Access {
31 suggestions(TextSource source, std::shared_ptr<portals::detail::FindModelSource> model, SuggestionsConfig config);
32 static std::expected<TextSource, ManagedError> resolveSearchText(ManagedScene &, const TextSource &, MountContext &);
33 static std::expected<bool, ManagedError> readSearchText(ManagedScene &, const TextSource &, std::size_t,
34 std::string &, bool &);
35 static std::expected<void, ManagedError> configureSearchList(ManagedScene &, Node<VirtualList<SearchItem>>,
36 std::shared_ptr<void>, std::function<void(RowId)>,
37 CellStyle);
38 static std::expected<void, ManagedError> suppressSearchList(ManagedScene &, Node<VirtualList<SearchItem>>, bool);
39 static std::expected<void, ManagedError> configureChoiceList(ManagedScene &, Node<VirtualList<SearchItem>>,
40 std::shared_ptr<void>, std::function<void(RowId)>);
41 static std::expected<std::optional<ModelRow<SearchItem>>, ManagedError>
43 static std::expected<std::optional<RowId>, ManagedError> choiceFirstRow(ManagedScene &,
45 static std::expected<std::optional<RowId>, ManagedError>
46 choiceNavigationRow(ManagedScene &, Node<VirtualList<SearchItem>>, std::uint64_t, bool, std::int64_t);
47 static std::expected<std::optional<std::uint64_t>, ManagedError>
48 choiceMoveNavigation(ManagedScene &, Node<VirtualList<SearchItem>>, portals::Action, int pageDirection = 0);
49 static std::expected<void, ManagedError> choiceClickActivation(ManagedScene &, Node<VirtualList<SearchItem>>);
50 static std::expected<std::uint64_t, ManagedError> choiceDraftRevision(ManagedScene &, Node<LineEdit>);
51 static std::expected<void, ManagedError> bindChoiceTrigger(ManagedScene &, Node<Button>,
52 std::function<std::expected<void, ManagedError>()>);
53 static std::expected<Node<OverlayHost>, ManagedError> choiceLayerHost(ManagedScene &, Node<Widget>);
54 static std::expected<void, ManagedError> claimChoicePopup(ManagedScene &, std::shared_ptr<SceneActivity>);
55 static bool choicePopupOpened(ManagedScene &, Node<Dialog>);
56
57 static void requestChoicePopup(ManagedScene &scene, std::shared_ptr<SceneActivity> activity) {
58 scene.choiceIntent_ = std::move(activity);
59 }
60
61 static void cancelChoicePopup(ManagedScene &scene, const SceneActivity *activity) {
62 if (auto pending = scene.choiceIntent_.lock(); pending.get() == activity) {
63 scene.choiceIntent_.reset();
64 }
65 }
66
67 template <class T> static void retireChoiceModel(ManagedScene &scene, ManagedModel<T> &model) noexcept {
68 auto source = model.lock();
69 if (!source) {
70 return;
71 }
72 std::erase(scene.models_, *source);
73 model = {};
74 // Retiring a user preparation callback can destroy the scene. The source
75 // is already detached, and its strong local owner needs no scene access.
76 (*source)->retire();
77 }
78
79 static std::shared_ptr<portals::detail::ManagedOrigin>
80 exchangeModelOrigin(ManagedScene &scene, std::shared_ptr<portals::detail::ManagedOrigin> origin) {
81 return std::exchange(scene.rowOrigin_, std::move(origin));
82 }
83
84 static std::expected<void, TreeError>
85 validateModelOrigin(ManagedScene &scene, const std::shared_ptr<portals::detail::ManagedOrigin> &origin) {
86 auto live = origin->check();
87 if (!live) {
88 return live;
89 }
90 if (origin->tree != &scene.app_.tree() || !scene.app_.tree().contains(scene.root_, origin->node).value_or(false)) {
91 return std::unexpected(TreeError::WRONG_SESSION);
92 }
93 return {};
94 }
95
96 static bool modelSceneClosed(const ManagedScene &scene) noexcept {
97 return scene.closed_;
98 }
99
100 template <std::equality_comparable T> static ManagedState<T> valueState(const ManagedSource<T> &source) {
101 return source.state_;
102 }
103
104 template <std::equality_comparable T>
105 static std::expected<ManagedState<T>, ManagedError> createValueState(ManagedScene &scene, const T &initial) {
106 // Owning scalar records may contain containers whose Debug move allocates inside noexcept.
107 return scene.stateFrom<T>(initial, Invalidation::PAINT, {});
108 }
109
110 template <std::equality_comparable T>
111 static std::expected<void, TreeError> validateValueState(ManagedScene &scene, const ManagedState<T> &state) {
112 // lock preserves the original source's affinity, lifetime and origin qualification.
113 auto property = state.lock();
114 if (!property) {
115 return std::unexpected(property.error());
116 }
117 if (state.scene_ != scene.root_.id()) {
118 return std::unexpected(TreeError::WRONG_SESSION);
119 }
120
121 return {};
122 }
123
124 template <class T> static void editDeclaration(ManagedModel<T> model, std::shared_ptr<void> declaration) {
125 if (auto source = model.lock()) {
126 (*source)->editDeclaration = std::move(declaration);
127 }
128 }
129
130 template <class T> static void ownedModel(ManagedModel<T> model) {
131 if (auto source = model.lock()) {
132 (*source)->sinkOnly = true;
133 }
134 }
135
136 template <class T>
137 static std::expected<void, ManagedError> applyOwnedModel(ManagedScene &scene, ManagedModel<T> model,
138 std::shared_ptr<const ModelSnapshot<T>> snapshot) {
139 return scene.applyOwnedSnapshot(std::move(model), std::move(snapshot));
140 }
141
142 template <class T>
143 static std::expected<ManagedModel<T>, ManagedError> navigationModel(ManagedScene &scene,
144 const ManagedNavigation &navigation) {
145 auto record = navigation.lock();
146 auto source =
147 record ? std::dynamic_pointer_cast<portals::detail::ManagedModelSourceOf<T>>((*record)->model.lock()) : nullptr;
148 if (!source || source->retired || (*record)->scene != scene.root_.id()) {
149 return std::unexpected(ManagedError{
150 ManagedPhase::STATE, scene.root_.id(), record ? TreeError::INVALID_ARGUMENT : record.error(), {}, {}});
151 }
152 ManagedModel<T> result;
153 result.source_ = source;
154 result.owner_ = scene.owner_;
155 return result;
156 }
157
158 static void retireColdNavigation(ManagedScene &scene, ManagedNavigation navigation) noexcept {
159 auto record = navigation.record_.lock();
160 if (!record || !scene.navigation_) {
161 return;
162 }
163 auto current = record->current.model_.lock();
164 auto selection = record->selection.model_.lock();
165 auto reading = record->reading.model_.lock();
166 record->closed = true;
167 std::erase(scene.navigation_->contexts, record);
168 std::erase_if(scene.properties_, [&](const auto &property) {
169 return property == current || property == selection || property == reading;
170 });
171 record->close();
172 }
173
174 template <class T> static void retireChoiceState(ManagedScene &scene, ManagedState<T> &state) noexcept {
175 auto property = state.model_.lock();
176 if (property) {
177 std::erase(scene.properties_, std::shared_ptr<void>(std::move(property)));
178 }
179 state = {};
180 }
181
182 template <std::equality_comparable T>
183 static void retireValueState(ManagedScene &scene, ManagedState<T> &state) noexcept {
184 auto property = state.model_.lock();
185
186 // Detach every weak declaration handle before a last value destructor can reenter.
187 state = {};
188 if (property) {
189 std::erase(scene.properties_, std::shared_ptr<void>(property));
190 }
191 // Releasing the pinned property may destroy the scene. Do not access it again.
192 }
193
194 static void reportValueError(const std::shared_ptr<RefTarget> &target, ManagedError &failure,
195 std::source_location origin, const char *operation = "model.value",
196 const char *control = "Model") noexcept {
197 failure.operation = operation;
198 failure.operationOrigin = origin;
199
200 if (target && target->owner == std::this_thread::get_id() && target->scene && !target->lifetime.expired()) {
201 target->scene->reportShortError(failure, operation, {}, control, origin);
202 } else {
203 const auto ticket = SetupFailureScope::latch(failure);
204 }
205 }
206
207 template <class T>
208 static std::expected<ModelResource, TreeError> registeredModelResource(const ManagedModel<T> &model) {
209 auto source = model.lock();
210 if (!source || (*source)->retired || !(*source)->model) {
211 return std::unexpected(source ? TreeError::CLOSED : source.error());
212 }
213
214 return (*source)->navigationResource;
215 }
216
217 template <class T> static std::expected<std::string, TreeError> formatValueCaption(const T &value) {
218 if constexpr (std::same_as<T, GraphemeText>) {
219 return std::expected<std::string, TreeError>(std::in_place, value.bytes());
220 } else if constexpr (std::same_as<T, std::string>) {
221 return std::expected<std::string, TreeError>(std::in_place, value.data(), value.size());
222 } else {
223 const auto text = std::format("{}", value);
224
225 // Copy directly into the checked result: a debug string move can allocate inside noexcept.
226 return std::expected<std::string, TreeError>(std::in_place, text.data(), text.size());
227 }
228 }
229
230 // Optional ownership lives only on captions using value sources. Pins keep every erased callback/value
231 // alive until all scene containers are consistent; their final destructors may retire the scene.
232 struct ValueCaptionGraph {
233 ManagedScene *scene{};
234 std::weak_ptr<const void> lifetime;
235 std::shared_ptr<void> output;
236 std::vector<std::shared_ptr<ManagedScene::ObserverRecord>> observers =
237 std::vector<std::shared_ptr<ManagedScene::ObserverRecord>>(
238 std::initializer_list<std::shared_ptr<ManagedScene::ObserverRecord>>{});
239 std::shared_ptr<void> payload;
240
241 ~ValueCaptionGraph() {
242 if (lifetime.expired()) {
243 return;
244 }
245
246 for (const auto &observer : observers) {
247 observer->retired = true;
248 }
249
250 for (const auto &observer : observers) {
251 observer->subscription = {};
252 std::erase(scene->observers_, observer);
253 }
254
255 if (output) {
256 std::erase(scene->properties_, output);
257 }
258 // No scene access after member destruction starts releasing user captures.
259 }
260 };
261
262 static std::expected<ManagedState<std::string>, ManagedError>
263 valueTextState(ManagedScene &scene, const std::string &initial, const std::shared_ptr<ValueCaptionGraph> &graph) {
264 auto state = scene.state(initial);
265 if (!state) {
266 return std::unexpected(state.error());
267 }
268
269 graph->output = *state->lock();
270
271 return *state;
272 }
273
274 template <class Compute> static auto computeValueText(ManagedScene &scene, Compute &&compute) {
275 struct Computing {
276 std::size_t &count;
277
278 ~Computing() {
279 --count;
280 }
281 } guard{scene.observerCallbacks_};
282
283 ++scene.observerCallbacks_;
284
285 return std::invoke(std::forward<Compute>(compute));
286 }
287
288 template <std::equality_comparable T>
289 static std::expected<void, ManagedError> observeValueText(ManagedScene &scene, Node<Widget> node,
290 ManagedState<T> source,
291 std::function<std::expected<void, TreeError>()> callback,
292 const std::shared_ptr<ValueCaptionGraph> &graph) {
293 auto observed = scene.observe(node, source, [callback = std::move(callback)](const T &) {
294 return callback();
295 });
296 if (!observed) {
297 return observed;
298 }
299
300 const auto record = scene.observers_.back();
301 auto snapshot = source.snapshot();
302 if (!snapshot) {
303 record->retired = true;
304 record->subscription = {};
305 std::erase(scene.observers_, record);
306
307 return std::unexpected(ManagedError{ManagedPhase::BIND, node.id(), snapshot.error(), {}, {}});
308 }
309
310 record->successful = (*snapshot)->revision;
311 record->initialPending = false;
312 record->operation = "text.compute";
313 graph->observers.push_back(record);
314
315 return {};
316 }
317
318 static std::expected<void, ManagedError> admitValueTextObservers(ManagedScene &scene, Node<Widget> node,
319 std::size_t count) {
320 auto admitted = scene.observerAdmission(node);
321 if (!admitted) {
322 return admitted;
323 }
324
325 const auto boundModels = std::ranges::count_if(scene.models_, [](const auto &source) {
326 return source->bound();
327 });
328 const auto nodeObservers = std::ranges::count(scene.observers_, Node<Widget>(node), [](const auto &record) {
329 return record->node;
330 });
331 const auto captures = std::ranges::count_if(scene.liveText_, [&](const auto &record) {
332 return record->origin->node == node;
333 });
334 const auto used = scene.observers_.size() + scene.liveText_.size() + static_cast<std::size_t>(boundModels);
335 const auto nodeUsed = static_cast<std::size_t>(nodeObservers + captures);
336
337 if (count > scene.options_.maxObservers - used || count > scene.options_.maxObserversPerNode - nodeUsed) {
338 return std::unexpected(ManagedError{ManagedPhase::BIND, node.id(), TreeError::NODE_LIMIT, {}, {}});
339 }
340
341 return {};
342 }
343
344 struct ValueCaptionSlot {
345 const void *identity{};
346 std::shared_ptr<ValueCaptionBinding> source;
347 };
348
349 static std::expected<ValueCaptionSlot, ManagedError> valueCaptionSlot(ManagedScene &scene, Node<Widget> node) {
350 auto allowed = scene.boundary(ManagedPhase::BIND, node);
351 if (!allowed) {
352 return std::unexpected(allowed.error());
353 }
354
355 auto entry = scene.find(node);
356 if (!entry) {
357 return std::unexpected(ManagedError{ManagedPhase::BIND, node.id(), TreeError::INVALID_ARGUMENT, {}, {}});
358 }
359
360 return ValueCaptionSlot{entry->caption.get(), entry->caption ? entry->caption->source : nullptr};
361 }
362
363 template <class Receiver>
364 static std::expected<void, ManagedError>
365 installValueCaption(ManagedScene &scene, Node<Receiver> node, ManagedState<std::string> text,
366 std::shared_ptr<ValueCaptionBinding> source, const void *previous, MountContext &context) {
367 auto slot = valueCaptionSlot(scene, node);
368 if (!slot) {
369 return std::unexpected(slot.error());
370 }
371 if (slot->identity != previous) {
372 return std::unexpected(ManagedError{ManagedPhase::BIND, node.id(), TreeError::WOULD_BLOCK, {}, {}});
373 }
374
375 auto candidate = std::make_unique<ManagedScene::CaptionBinding>();
376
377 if constexpr (std::same_as<Receiver, Border>) {
378 candidate->node = node;
379 } else {
380 candidate->node = Node<Control>(node);
381 }
382 candidate->model = text;
383 candidate->source = std::move(source);
384
385 auto retired = std::make_shared<std::unique_ptr<ManagedScene::CaptionBinding>>();
386
387 context.release.emplace_back([retired] {
388 });
389
390 // syncCaption validates and allocates text before setControlText. Publication after that is a swap
391 // and has no allocation/callout. A failed candidate therefore cannot leave the old source detached.
392 auto synced = scene.syncCaption(node, *candidate, ManagedPhase::BIND);
393 if (!synced) {
394 return synced;
395 }
396
397 auto entry = scene.find(node);
398 entry->caption.swap(candidate);
399 retired->swap(candidate);
400
401 // The transaction keeps the previous graph until descriptor publication has finished. Its final
402 // callable destructor may destroy the scene, so retirement must follow the last scene access.
403
404 return {};
405 }
406
407 template <std::equality_comparable T, class Projection>
408 static std::expected<ManagedState<std::string>, ManagedError>
409 projectValueCaption(ManagedScene &scene, Node<Widget> node, ManagedState<T> source,
410 const std::shared_ptr<Projection> &projection, const std::shared_ptr<ValueCaptionGraph> &graph) {
411 auto admitted = scene.observerAdmission(node);
412 if (!admitted) {
413 return std::unexpected(admitted.error());
414 }
415
416 graph->observers.reserve(1);
417 // Only shared ownership is copied inside derive. Constructing the user's callable happens before
418 // entering it; its pure invocation follows the existing derive non-reentry contract.
419 auto text = scene.derive(source, [projection](const T &value) -> std::expected<std::string, TreeError> {
420 if constexpr (std::is_member_pointer_v<Projection> || std::is_pointer_v<Projection>) {
421 if (!*projection) {
422 return std::unexpected(TreeError::INVALID_ARGUMENT);
423 }
424 }
425
426 decltype(auto) projected = std::invoke(*projection, value);
427
428 if constexpr (portals::detail::IS_DERIVED_EXPECTED<std::remove_cvref_t<decltype(projected)>>) {
429 return projected ? formatValueCaption(*projected)
430 : std::expected<std::string, TreeError>(std::unexpected(projected.error()));
431 } else {
432 return formatValueCaption(projected);
433 }
434 });
435 if (!text) {
436 return std::unexpected(text.error());
437 }
438
439 graph->output = *text->state_.lock();
440 graph->observers.push_back(scene.observers_.back());
441 graph->observers.back()->node = node;
442
443 return text->state_;
444 }
445
446 static bool choiceWithin(ManagedScene &scene, Node<Widget> root, Node<Widget> node) {
447 return scene.choiceWithin(root, node);
448 }
449
450 template <class Callback>
451 static std::function<void(ChoiceSelection)> choiceHandler(ManagedScene &scene, Node<Widget> node, Callback callback,
452 std::source_location origin) {
453 return [&scene, node, lifetime = lifetime(scene),
454 adapter = scene.actionAdapter<ChoiceSelection>(std::move(callback), origin),
455 origin](ChoiceSelection value) mutable {
456 auto result = adapter(value);
457 if (!result && !lifetime.expired() && !scene.commandReported(result, lifetime)) {
458 scene.remember(ManagedError{ManagedPhase::INPUT, node.id(), result.result().error(), {}, {}}, origin);
459 }
460 };
461 }
462
463 static void choiceModels(ManagedScene &scene, MountContext &context) {
464 const auto count = scene.models_.size();
465 context.rollback.push_back([&scene, count] {
466 while (scene.models_.size() > count) {
467 scene.models_.back()->retire();
468 scene.models_.pop_back();
469 }
470 });
471 }
472
473 static std::expected<void, ManagedError> choiceCompanion(ManagedScene &scene, Node<Widget> owner,
474 Node<Widget> popup) {
475 auto entry = scene.find(owner);
476 if (!entry) {
477 return std::unexpected(error(owner, TreeError::STALE_NODE));
478 }
479 entry->companion = popup;
480 return {};
481 }
482
483 static Description<FindBar> findBar(std::string document, std::string query, FindBarConfig config,
484 std::shared_ptr<portals::detail::FindModelSource> source = {},
485 std::shared_ptr<portals::detail::FindExternalBinding> external = {});
486 static std::expected<std::size_t, ManagedError> findPreparedQueries(ManagedScene &scene, Node<Widget> node);
487 static std::expected<std::shared_ptr<portals::detail::FindRecord>, ManagedError> findRecord(ManagedScene &scene,
488 Node<Widget> node);
489 static std::expected<FindMatch, ManagedError> findNavigate(ManagedScene &scene, Node<Widget> node,
490 FindDirection direction);
491 static std::expected<FindMatch, ManagedError> findMatch(ManagedScene &scene, Node<Widget> node);
492 static std::expected<bool, ManagedError> findCurrent(ManagedScene &scene, Node<Widget> node, const FindMatch &match);
493 static std::expected<void, ManagedError> findDocument(ManagedScene &scene, Node<Widget> node,
494 std::string_view document);
495 static std::pair<std::expected<void, TreeError>, bool> findClear(ManagedScene &scene, Node<Widget> node,
496 std::source_location origin);
497 static Description<FormField> formFieldComposition(
498 std::string caption,
499 portals::detail::MoveOnlyFunction<std::expected<Description<Widget>, ManagedError>(const ControlSettings &)> editor,
500 FormFieldOptions options, std::shared_ptr<RecipeLayout> layout = {},
501 std::shared_ptr<std::weak_ptr<portals::detail::FormFieldRecord>> bridge = {},
502 std::function<Description<Label>(ControlStyle)> captionRecipe = {});
503 static std::expected<void, ManagedError> connectEditValidation(ManagedScene &, Node<FormField>,
504 std::shared_ptr<portals::detail::EditTextBinding>);
505 static std::expected<Subscription, TreeError> observeEditNavigation(ManagedNavigation, Node<LineEdit>,
506 std::function<void()>);
507 static std::expected<void, ManagedError>
508 bindEditText(ManagedScene &, Node<LineEdit>, std::shared_ptr<portals::detail::EditTextBinding>, LineEditConfig);
509 static Description<FormField> formField(std::string caption,
510 std::function<Description<Widget>(LineEditConfig, ControlSettings)> editor,
511 FormFieldConfig config);
512 static Description<FormField> formField(std::string caption, std::string initial, FormFieldConfig config);
513 static Description<FormField> formField(std::string caption, Description<Widget> editor, FormFieldOptions options,
514 std::function<Description<Label>(ControlStyle)> captionRecipe = {});
515 static std::expected<std::shared_ptr<portals::detail::FormFieldRecord>, ManagedError> fieldRecord(ManagedScene &scene,
516 Node<Widget> node);
517 static std::expected<FieldValidation, ManagedError> fieldValidation(ManagedScene &scene, Node<Widget> node);
518 static std::expected<bool, ManagedError> validateField(ManagedScene &scene, Node<Widget> node);
519 static std::expected<void, ManagedError> displayField(ManagedScene &scene, Node<Widget> node, FieldValidation value);
520
522
523 static void beginMount(ManagedScene &scene) noexcept {
524 if (scene.owner_ == std::this_thread::get_id()) {
525 ++scene.mountDepth_;
526 }
527 }
528
530 static void endMount(ManagedScene &scene) noexcept {
531 if (scene.owner_ == std::this_thread::get_id()) {
532 --scene.mountDepth_;
533 }
534 }
535
539 static std::weak_ptr<const void> lifetime(ManagedScene &scene) {
540 return scene.lifetime_;
541 }
542
544 // Keep the existing Column recipe metadata/children while using the cpp-owned dialog body adapter.
545 static Description<Column> dialogContent(Description<Column> description);
546
547 static std::expected<Node<Widget>, ManagedError> dialogPanel(ManagedScene &scene, Node<Dialog> node,
548 BorderOptions options) {
549 return scene.makeDialogPanel(node, options);
550 }
551
553
555 static std::expected<void, ManagedError> notifications(ManagedScene &scene, Node<Widget> wrapper, Node<Widget> body,
556 const NotificationCenter &center,
557 const NotificationOptions &options, MountContext &context) {
558 auto reserved = NotificationAccess::reserve(center);
559 if (!reserved) {
560 return reserved;
561 }
562 try {
563 context.release.emplace_back([center] {
564 NotificationAccess::release(center);
565 });
566 } catch (...) {
567 NotificationAccess::release(center);
568 throw;
569 }
570 auto made = scene.makeNotifications(wrapper, body, options, context.nodes);
571 if (!made) {
572 return std::unexpected(made.error());
573 }
574 context.finalize.emplace_back([&scene, record = *made] {
575 return scene.finalizeNotifications(record);
576 });
577 context.publish.emplace_back([center, record = *made] {
578 NotificationAccess::publish(center, record);
579 });
580 return {};
581 }
582
584
597 template <class T>
598 static std::expected<Node<T>, ManagedError> mount(Description<T> &&description, ManagedScene &scene,
599 Node<Widget> parent, MountContext &context);
603 template <class T> static bool needsGridContext(const Description<T> &description);
605 template <class T> static bool needsChoiceHost(const Description<T> &description);
606 template <class T> static std::expected<bool, ManagedError> prepareChoiceHost(Description<T> &, ControlContext);
607 template <class T, class Probe> static Description<T> choiceProbe(Description<T>, Probe);
608 template <class T> static Description<T> choiceHost(Description<T> description, bool explicitHost = false);
610
614 static Description<Widget> deferControlValidation(Description<Widget> description);
618 template <class T> static bool defersControlValidation(const Description<T> &description);
619
626 template <class T, class Factory> static Description<T> describe(Factory factory);
627
633 template <class T> static Description<T> intrinsicStyle(Description<T> description, StyleTarget identity);
639 template <class T> static void preparedControl(Description<T> &description, std::uint32_t alreadyMaterialized = 0);
645 template <class T>
646 static void preparedControlPresence(Description<T> &description, ControlPropertyPresence alreadyMaterialized);
651 static void preparedDialogHeading(Description<Label> &description, const TextValue &title);
655 template <class T> static void preparedThemeSelectorCaption(Description<T> &description, const TextValue &caption);
657 static Description<Dialog> themeSelectorControl(Description<Dialog> description);
659 static Description<Dialog> themeCatalogControl(Description<Dialog> description);
663 template <class T> static bool themeCatalogRecipient(const Description<T> &description) noexcept;
665 static Description<Dialog> messageControl(Description<Dialog> description);
667 static Description<Overlay> notificationControl(Description<Overlay> description);
673 template <class T>
674 static std::expected<void, ManagedError> messageSource(Description<T> &description, const ControlSettings &settings,
675 ControlPropertyPresence materialized,
676 ControlFactoryKind kind = ControlFactoryKind::MESSAGE_BINDING);
681 static Description<Dialog> internalDialog(Description<Dialog> description,
682 const TextValue *prechargedTitle = nullptr);
690 template <class T>
691 static Description<T> configuredControl(Description<T> description, std::string_view type, bool inherit = true);
698 template <class T> static Description<T> controlArguments(Description<T> description, ControlSettings arguments);
702 template <class T> static Description<T> failed(ManagedError failure);
707 template <class T> static void numericSettings(Description<T> &description, ControlSettings patch);
712 template <class Parent, class Child>
713 static void layoutChild(Description<Parent> &parent, Description<Child> &child, bool structural = false);
718 template <class... Children> static std::shared_ptr<RecipeLayout> captureLayouts(Children &...children);
723 template <class T> static Description<T> withLayout(Description<T> description, std::shared_ptr<RecipeLayout> layout);
727 template <class Child>
728 static void gridChild(Description<Grid> &parent, Child &&child, std::optional<GridRegion> region = {});
730 static void gridSection(Description<Grid> &parent, GridSection section);
731
736 static std::expected<void, ManagedError> gridOptions(ManagedScene &scene, Node<Grid> node,
737 const GridOptions &options) {
738 auto result = setDeclarativeGridOptions(scene.app_.tree(), node, options);
739
740 return result ? std::expected<void, ManagedError>{} : std::unexpected(error(node, result.error()));
741 }
742
749 template <class T, class Callback> static Description<T> controlSetup(Description<T> description, Callback callback);
753 static void switchSettings(Description<Switch> &description, ControlSettings patch);
768 template <class T> static void frameSettings(Description<T> &description, const ControlSettings &settings);
774 template <class T>
775 static std::expected<void, ManagedError> messageBody(Description<T> &description, Description<Widget> body);
784 static std::expected<void, ManagedError> applyScrollbarSkin(ManagedScene &scene, Node<Widget> node,
785 const ControlSettings &settings);
786
793 std::shared_ptr<ScrollController> controller, ControlStyle style);
801 static Description<ScrollBar> scrollBarControl(std::shared_ptr<ScrollController> controller, ScrollAxis axis,
802 ScrollBarOptions options, ControlStyle style, bool writer);
803
808 template <class T> static constexpr std::string_view controlType() {
809 if constexpr (std::same_as<T, Label>) {
810 return "Label";
811 } else if constexpr (std::same_as<T, Button>) {
812 return "Button";
813 } else if constexpr (std::same_as<T, CheckBox>) {
814 return "CheckBox";
815 } else if constexpr (std::same_as<T, Switch>) {
816 return "Switch";
817 } else if constexpr (std::same_as<T, ThreeState>) {
818 return "ThreeState";
819 } else if constexpr (std::same_as<T, FormField>) {
820 return "FormField";
821 } else if constexpr (std::same_as<T, FindBar>) {
822 return "FindBar";
823 } else if constexpr (std::same_as<T, LineEdit>) {
824 return "LineEdit";
825 } else if constexpr (std::same_as<T, Password>) {
826 return "Password";
827 } else if constexpr (std::same_as<T, Row>) {
828 return "HBox";
829 } else if constexpr (std::same_as<T, RadioGroup>) {
830 return "RadioGroup";
831 } else if constexpr (std::same_as<T, StatusBar>) {
832 return "StatusBar";
833 } else if constexpr (std::same_as<T, Column>) {
834 return "VBox";
835 } else if constexpr (std::same_as<T, Border>) {
836 return "Border";
837 } else if constexpr (std::same_as<T, Gauge>) {
838 return "Gauge";
839 } else if constexpr (std::same_as<T, Spinner>) {
840 return "Spinner";
841 } else if constexpr (std::same_as<T, SpinBox>) {
842 return "SpinBox";
843 } else if constexpr (std::same_as<T, Slider>) {
844 return "Slider";
845 } else if constexpr (std::same_as<T, ScrollArea>) {
846 return "ScrollArea";
847 } else if constexpr (std::same_as<T, DocumentView>) {
848 return "DocumentView";
849 } else if constexpr (std::same_as<T, LogView>) {
850 return "LogView";
851 } else if constexpr (std::same_as<T, ScrollBar>) {
852 return "ScrollBar";
853 } else if constexpr (std::same_as<T, HelpView>) {
854 return "HelpView";
855 } else if constexpr (std::same_as<T, KeyHints>) {
856 return "KeyHints";
857 } else if constexpr (IsVirtualList<T>::value) {
858 return "VirtualList";
859 } else if constexpr (IsVirtualTable<T>::value) {
860 return "VirtualTable";
861 } else if constexpr (IsChart<T>::value) {
862 return "Chart";
863 } else if constexpr (std::same_as<T, DataStateView>) {
864 return "DataStateView";
865 } else if constexpr (std::same_as<T, OverlayHost>) {
866 return "OverlayHost";
867 } else if constexpr (std::same_as<T, Dialog>) {
868 return "Dialog";
869 } else if constexpr (std::same_as<T, Overlay>) {
870 return "Overlay";
871 } else
872 return {};
873 }
874
880 mergeRecipeControlSettings(base, patch);
881 return base;
882 }
883
888 template <class T>
889 requires IsChart<T>::value
890 static void chartSettings(Description<T> &description, ControlSettings patch) {
891 (void)std::move(description).scalarSettings(std::move(patch));
892 }
893
899 static std::expected<void, ManagedError> finalizeStyleIdentity(ManagedScene &scene, Node<Widget> node,
900 const StyleTarget &identity) {
901 auto allowed = scene.boundary(ManagedPhase::STYLE, node);
902
903 if (!allowed) {
904 return allowed;
905 }
906
907 auto entry = scene.find(node);
908
909 if (!entry) {
910 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), TreeError::INVALID_ARGUMENT, {}, {}});
911 }
912
913 try {
914 // Retain the exact metadata owner across allocation and possible nested mutation.
915 const auto current = entry->target;
916
917 if (current && current->baseTypes.size() > MAX_STYLE_BASE_TYPES) {
918 return std::unexpected(
919 ManagedError{ManagedPhase::STYLE, node.id(), validateStyleTarget(*current).error(), {}, {}});
920 }
921
922 if (current && !current->type.empty() && (!identity.control || current->control)) {
923 const auto containsName = [&](const std::string &name) {
924 return name == current->type || std::ranges::find(current->baseTypes, name) != current->baseTypes.end();
925 };
926
927 if (containsName(identity.type) && std::ranges::all_of(identity.baseTypes, containsName)) {
928 auto valid = validateStyleTarget(*current);
929
930 if (!valid) {
931 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), valid.error(), {}, {}});
932 }
933
934 return {};
935 }
936 }
937
938 auto target = current ? *current : StyleTarget{};
939
940 if (target.type.empty()) {
941 target.type = identity.type;
942 }
943
944 const auto retainName = [&](const std::string &name) {
945 if (name != target.type && std::ranges::find(target.baseTypes, name) == target.baseTypes.end()) {
946 target.baseTypes.push_back(name);
947 }
948 };
949
950 retainName(identity.type);
951
952 for (const auto &name : identity.baseTypes) {
953 retainName(name);
954 }
955
956 target.control = target.control || identity.control;
957
958 auto valid = validateStyleTarget(target);
959
960 if (!valid) {
961 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), valid.error(), {}, {}});
962 }
963
964 return scene.style(node, std::move(target));
965 } catch (const std::bad_alloc &) {
966 return std::unexpected(ManagedError{ManagedPhase::STYLE, node.id(), TreeError::NO_MEMORY, {}, {}});
967 }
968 }
969
971 template <class T, class Factory> static Description<T> cold(Factory factory);
972
973 static void beginCold(ManagedScene &scene) noexcept {
974 ++scene.coldMountPending_;
975 }
976
977 struct ColdGraph {
978 ManagedScene *scene{};
979 std::shared_ptr<ManagedScene::LiveTextRecord> live;
980 std::shared_ptr<void> output;
981 std::shared_ptr<ManagedScene::ObserverRecord> observer;
982 std::shared_ptr<portals::detail::ManagedModelSource> model;
983 bool pending{};
984
985 void retire() noexcept {
986 // The complete logical mark precedes disconnect/destructor reentry.
987 if (pending) {
988 --scene->coldMountPending_;
989 pending = false;
990 }
991 if (observer) {
992 observer->retired = true;
993 }
994 if (observer) {
995 observer->subscription = {};
996 }
997 if (model) {
998 std::erase(scene->models_, model);
999 }
1000 if (observer) {
1001 std::erase(scene->observers_, observer);
1002 }
1003 if (output) {
1004 std::erase(scene->properties_, output);
1005 std::erase_if(scene->originProperties_, [&](const auto &record) {
1006 return record.property.lock() == output;
1007 });
1008 }
1009 if (live) {
1010 live->origin->retired = true;
1011 scene->pruneLiveText();
1012 }
1013 }
1014 };
1015
1016 static std::shared_ptr<RefTarget> captionIdentity(const TextSource &source) {
1017 return source.target_;
1018 }
1019
1020 static std::shared_ptr<RefTarget> captionTarget(std::shared_ptr<RefTarget> target, MountContext &context) {
1021 for (const auto &pending : context.pending) {
1022 if (pending.identity == target.get()) {
1023 return std::make_shared<RefTarget>(pending.target);
1024 }
1025 }
1026 return target;
1027 }
1028
1029 static std::expected<void, ManagedError> finishCaptions(MountContext &context) {
1030 if (std::ranges::all_of(context.captions, &MountContext::CaptionFinalizer::completed)) {
1031 return {};
1032 }
1033 // Resolve dependencies once; iterative completion never consumes one stack frame per control.
1034 std::vector<std::optional<std::size_t>> dependencies(context.captions.size());
1035 for (std::size_t index = 0; index < context.captions.size(); ++index) {
1036 auto target = captionTarget(context.captions[index].source, context);
1037 if (!target) {
1038 return std::unexpected(error(context.captions[index].receiver, TreeError::CLOSED));
1039 }
1040 if (target->owner != std::this_thread::get_id()) {
1041 return std::unexpected(error(context.captions[index].receiver, TreeError::WRONG_THREAD));
1042 }
1043 for (std::size_t source = 0; source < context.captions.size(); ++source) {
1044 if (context.captions[source].receiver == target->node) {
1045 dependencies[index] = source;
1046 break;
1047 }
1048 }
1049 }
1050 auto remaining = std::ranges::count(context.captions, false, &MountContext::CaptionFinalizer::completed);
1051 while (remaining) {
1052 bool progressed{};
1053 for (std::size_t index = 0; index < context.captions.size(); ++index) {
1054 auto &caption = context.captions[index];
1055 if (caption.completed || (dependencies[index] && !context.captions[*dependencies[index]].completed)) {
1056 continue;
1057 }
1058 auto completed = caption.complete();
1059 if (!completed) {
1060 return completed;
1061 }
1062 caption.completed = true;
1063 --remaining;
1064 progressed = true;
1065 }
1066 if (!progressed) {
1067 const auto cycle = std::ranges::find(context.captions, false, &MountContext::CaptionFinalizer::completed);
1068 return std::unexpected(error(cycle->receiver, TreeError::INVALID_ARGUMENT));
1069 }
1070 }
1071 return {};
1072 }
1073
1074 static std::expected<void, ManagedError> completeCaption(ManagedScene &scene, Node<Control> node,
1075 const TextSource &source, MountContext &context,
1076 const std::shared_ptr<ColdGraph> &graph) {
1077 auto target = captionTarget(source.target_, context);
1078 if (!target) {
1079 return std::unexpected(error(node, TreeError::CLOSED));
1080 }
1081 if (target->owner != std::this_thread::get_id()) {
1082 return std::unexpected(error(node, TreeError::WRONG_THREAD));
1083 }
1084 auto owner = eventScene(target);
1085 if (!owner) {
1086 return std::unexpected(owner.error());
1087 }
1088 if (*owner != &scene) {
1089 return std::unexpected(error(node, TreeError::INVALID_ARGUMENT));
1090 }
1091 const bool existed = std::ranges::any_of(scene.liveText_, [&](const auto &record) {
1092 return record->origin->node == target->node && record->kind == static_cast<int>(source.kind_);
1093 });
1094 auto live =
1095 scene.attachLiveText(TextSource(target, source.kind_), PropertyOptions{}, std::source_location::current(), false);
1096 if (!live) {
1097 return std::unexpected(live.error());
1098 }
1099 if (!existed) {
1100 const auto created = std::ranges::find_if(scene.liveText_, [&](const auto &record) {
1101 return record->origin == live->state_.origin_;
1102 });
1103 if (created != scene.liveText_.end()) {
1104 graph->live = *created;
1105 }
1106 }
1107 // A shared capture can precede this mount; read the original identity for a fresh initial caption.
1108 auto initial = TextSource(target, source.kind_).snapshot();
1109 if (!initial) {
1110 return std::unexpected(initial.error());
1111 }
1112 auto applied = setControlText(scene.app_.tree(), node, std::move(*initial));
1113 if (!applied) {
1114 return std::unexpected(error(node, applied.error()));
1115 }
1116 auto observed = scene.observe(node, *live, [&scene, node](const GraphemeText &text) {
1117 return setControlText(scene.app_.tree(), node, text);
1118 });
1119 if (!observed) {
1120 return observed;
1121 }
1122 graph->observer = scene.observers_.back();
1123 graph->observer->operation = "text.caption";
1124 if (graph->pending) {
1125 --scene.coldMountPending_;
1126 graph->pending = false;
1127 }
1128 return {};
1129 }
1130
1131 static std::expected<void, ManagedError> completeTextList(ManagedScene &scene, Node<VirtualList<TextSegment>> node,
1132 const TextSource &source, bool splitWords,
1133 TextSplitOptions options, MountContext &context,
1134 const std::shared_ptr<ColdGraph> &graph,
1136 auto target = source.target_;
1137 for (const auto &pending : context.pending) {
1138 if (pending.identity == target.get()) {
1139 target = std::make_shared<RefTarget>(pending.target);
1140 break;
1141 }
1142 }
1143 if (target && target->owner != std::this_thread::get_id()) {
1144 return std::unexpected(error({}, TreeError::WRONG_THREAD));
1145 }
1146 if (!target) {
1147 return std::unexpected(error({}, TreeError::CLOSED));
1148 }
1149 const bool existed = std::ranges::any_of(scene.liveText_, [&](const auto &record) {
1150 return record->origin->node == target->node && record->kind == static_cast<int>(source.kind_);
1151 });
1152 auto resolved = TextSource(target, source.kind_);
1153 auto live = scene.attachLiveText(resolved, PropertyOptions{}, std::source_location::current(), false);
1154 if (!live) {
1155 return std::unexpected(live.error());
1156 }
1157 const auto existing = std::ranges::find_if(scene.liveText_, [&](const auto &record) {
1158 return record->origin == live->state_.origin_;
1159 });
1160 // Ownership is assigned by the finalizer that created the bridge, not by every shared consumer.
1161 if (!existed && existing != scene.liveText_.end()) {
1162 graph->live = *existing;
1163 }
1164 auto initialText = live->snapshot();
1165 if (!initialText) {
1166 return std::unexpected(error(target->node, initialText.error()));
1167 }
1168 if ((*initialText)->value.policy() != scene.widthPolicy()) {
1169 return std::unexpected(error(target->node, TreeError::INVALID_ARGUMENT));
1170 }
1171 auto admitted = scene.observerAdmission(node);
1172 if (!admitted) {
1173 return std::unexpected(admitted.error());
1174 }
1175 auto textFailure = std::make_shared<std::optional<TextError>>();
1176 auto derived = scene.derive(*live, [splitWords, options, textFailure](const GraphemeText &text) {
1177 *textFailure = portals::detail::textSplitLimit(text, options.limits);
1178 return splitWords ? portals::words(text, options) : portals::graphemes(text, options);
1179 });
1180 if (!derived) {
1181 auto failure = derived.error();
1182 failure.node = target->node.id();
1183 failure.text = *textFailure;
1184 return std::unexpected(failure);
1185 }
1186 graph->output = *derived->state_.lock();
1187 graph->observer = scene.observers_.back();
1188 graph->observer->textFailure = std::move(textFailure);
1189 graph->observer->operation = splitWords ? "text.words" : "text.graphemes";
1190 graph->observer->node = node;
1191 scene.originProperties_.push_back({live->state_.origin_, graph->output, node});
1192 // Private cold edges share origin retirement; ordinary public derived outputs remain independent.
1193 derived->state_.origin_ = live->state_.origin_;
1194 auto model =
1195 scene.collectionModel<TextSegment>(derived->state_, CollectionModelOptions{}, portals::detail::segmentRows);
1196 if (!model) {
1197 return std::unexpected(model.error());
1198 }
1199 auto owned = model->lock();
1200 if (!owned) {
1201 return std::unexpected(error(node, owned.error()));
1202 }
1203 graph->model = *owned;
1204 graph->model->receiver = node;
1205 auto range = (*owned)->model->openRange();
1206 if (!range) {
1207 return std::unexpected(error(node, range.error()));
1208 }
1209 auto installed = scene.app_.tree().edit(node, [&](VirtualList<TextSegment> &view) {
1210 view.consumer_ = std::move(*range);
1211 });
1212 if (!installed) {
1213 return std::unexpected(error(node, installed.error()));
1214 }
1215 auto attached = scene.attachView(node, *owned, std::move(prepared));
1216 if (attached && graph->pending) {
1217 --scene.coldMountPending_;
1218 graph->pending = false;
1219 }
1220 return attached ? std::expected<void, ManagedError>{} : std::unexpected(attached.error());
1221 }
1222
1224
1234 template <class Content, class Initial>
1235 static Description<DataStateView> dataState(Initial initial, Description<Content> content, DataStateConfig config,
1236 bool automatic);
1237
1242 template <class Factory> static Description<Widget> transaction(Factory factory);
1243
1249 template <class T> static Description<Widget> erase(Description<T> description);
1253 static Description<Widget> forwardOuter(Description<Widget> description);
1254
1260 static std::expected<void, ManagedError> resize(ManagedScene &scene, Node<SizedWidget> node, SizeChange change) {
1261 const auto allowed = scene.boundary(ManagedPhase::MOUNT, node);
1262
1263 if (!allowed) {
1264 return allowed;
1265 }
1266
1267 SizePolicy policy;
1268 auto &tree = scene.app_.tree();
1269 const auto read = tree.read(node, [&](const SizedWidget &widget) {
1270 policy = widget.sizePolicy();
1271 });
1272
1273 if (!read) {
1274 return std::unexpected(error(node, read.error()));
1275 }
1276
1277 if (change.dimension == SizeDimension::WIDTH) {
1278 policy.width = {change.extent, change.extent, change.extent, SizeMode::FIXED, 1};
1279 } else if (change.dimension == SizeDimension::HEIGHT) {
1280 policy.height = {change.extent, change.extent, change.extent, SizeMode::FIXED, 1};
1281 } else {
1282 if (change.dimension != SizeDimension::FLEX_Y) {
1283 policy.width.mode = SizeMode::FLEX;
1284 policy.width.preferred = 0;
1285 policy.width.weight = change.weight;
1286 }
1287
1288 if (change.dimension != SizeDimension::FLEX_X) {
1289 policy.height.mode = SizeMode::FLEX;
1290 policy.height.preferred = 0;
1291 policy.height.weight = change.weight;
1292 }
1293 }
1294
1295 const auto changed = setSizePolicy(tree, node, policy);
1296
1297 return changed ? std::expected<void, ManagedError>{} : std::unexpected(error(node, changed.error()));
1298 }
1299
1301 template <class T> static void sizingSettings(Description<T> &description, const RecipeSizing &sizing);
1302
1309 static std::expected<void, ManagedError> finishSizing(ManagedScene &scene, Node<SizedWidget> source,
1310 Node<SizedWidget> target, const RecipeSizing *sizing) {
1311 SizePolicy policy;
1312 auto &tree = scene.app_.tree();
1313 const auto read = tree.read(target, [&](const SizedWidget &widget) {
1314 policy = widget.sizePolicy();
1315 });
1316
1317 if (!read) {
1318 return std::unexpected(error(target, read.error()));
1319 }
1320
1321 if (source != target) {
1322 SizePolicy content;
1323 const auto inspected = tree.read(source, [&](const SizedWidget &widget) {
1324 content = widget.sizePolicy();
1325 });
1326
1327 if (!inspected) {
1328 return std::unexpected(error(source, inspected.error()));
1329 }
1330
1331 const auto inherit = [](AxisSize &outer, AxisSize inner) {
1332 if (outer == AxisSize{} && (inner.mode == SizeMode::CONTENT || inner.mode == SizeMode::FLEX)) {
1333 // Numeric content bounds describe another box; only its layout preference crosses the frame.
1334 outer.mode = inner.mode;
1335 outer.preferred = inner.preferred;
1336 outer.weight = inner.weight;
1337 }
1338 };
1339 inherit(policy.width, content.width);
1340 inherit(policy.height, content.height);
1341 }
1342
1343 if (sizing) {
1344 policy = sizing->apply(policy);
1345 }
1346
1347 const auto changed = setSizePolicy(tree, target, policy);
1348 return changed ? std::expected<void, ManagedError>{} : std::unexpected(error(target, changed.error()));
1349 }
1350
1358 static std::expected<void, ManagedError> instanceState(ManagedScene &scene, Node<Widget> node,
1359 std::optional<bool> visible, std::optional<bool> enabled) {
1360 const auto allowed = scene.boundary(ManagedPhase::MOUNT, node);
1361
1362 if (!allowed) {
1363 return allowed;
1364 }
1365
1366 auto &tree = scene.app_.tree();
1367
1368 if (visible) {
1369 const auto changed = tree.setVisible(node, *visible);
1370
1371 if (!changed) {
1372 return std::unexpected(error(node, changed.error()));
1373 }
1374 }
1375
1376 if (enabled) {
1377 const auto changed = tree.setEnabled(node, *enabled);
1378
1379 if (!changed) {
1380 return std::unexpected(error(node, changed.error()));
1381 }
1382 }
1383
1384 return {};
1385 }
1386
1394 static std::expected<void, ManagedError> check(ManagedScene &scene, Node<Widget> node) {
1395 return scene.boundary(ManagedPhase::MOUNT, node);
1396 }
1397
1402 static std::expected<Node<OverlayHost>, ManagedError> layerHost(ManagedScene &scene, Node<Widget> root);
1403
1408 static std::expected<void, ManagedError> checkLayer(ManagedScene &scene, Node<Widget> node);
1409};
1410} // namespace detail
1411
1412} // namespace portals::ui
Owning accepted row identity and bounded label, independent of editor draft and source lifetime.
Definition combo_box.hpp:19
Owning immutable selected range; retains original data, never a scene or widget. Empty handles repres...
Definition find_bar.hpp:64
Weak UI handle to a model owned by one ManagedScene. Handles may be copied and destroyed on any threa...
Definition managed_model.hpp:120
Weak UI-affine navigation handle owned by an existing scene/model scope. Removing a view does not rem...
Definition managed_navigation.hpp:119
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
Read-only weak scene-owned derived value; no writable alias or subscription escapes.
Definition managed.hpp:484
Weak UI handle to a scene-owned Property, never an owning alias. Copies and destruction of the handle...
Definition managed.hpp:367
Immutable list/table provider storage, independent of view/source lifetime. Implement read as bounded...
Definition model.hpp:94
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Node()=default
Empty observer; checked access fails.
NodeId id() const noexcept
Copy the stable diagnostic identity.
Definition widget.hpp:109
Widget with owning policies, changed only through setSizePolicy on UI.
Definition layout.hpp:68
SizePolicy sizePolicy() const override
Copy current policy without borrowing storage.
One UI-owned view with bounded owning row text and one independent model consumer....
Definition virtual_list.hpp:133
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Copyable weak UI-affine semantic handle; the scene owns all queue, action and timer storage....
Definition toast.hpp:311
Copyable read-only source observing one caption, visible draft or accepted editor model....
Definition ui_ref.hpp:302
std::expected< GraphemeText, ManagedError > snapshot() const
static SetupFailureTicket latch(ManagedError &failure, const void *attempt=nullptr) noexcept
Definition setup_failure.hpp:87
auto live(ManagedScene &scene, const S &description)
Definition style_static.hpp:1703
Public Portals API.
Definition action.hpp:8
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
constexpr std::size_t MAX_STYLE_BASE_TYPES
Maximum owned ancestor names per style target, excluding its immediate type.
Definition style.hpp:37
Action
Frontend-independent commands; text and paste remain distinct data events.
Definition action.hpp:10
std::expected< TextSegments, TreeError > graphemes(const GraphemeText &input, TextSplitOptions options={})
Return one token for every existing extended grapheme, including whitespace.
@ CONTENT
Prefer intrinsic size, shrink towards minimum, and never grow to consume spare cells.
Definition layout.hpp:16
@ FIXED
Keep the bounded preferred/intrinsic extent even when it overflows the available space.
Definition layout.hpp:14
@ FLEX
Share spare main-axis cells by weight; allow shrinking towards minimum.
Definition layout.hpp:15
std::expected< void, TreeError > setSizePolicy(WidgetTree &tree, Node< SizedWidget > node, SizePolicy policy)
Validate and edit policies between frames on the tree's UI owner; tree errors propagate....
FindDirection
Direction through the stored bounded prefix; both directions wrap.
Definition find_bar.hpp:26
@ STYLE
Register or apply styles, including a theme change.
Definition managed_diagnostics.hpp:52
@ STATE
Create and retain a scene-owned property.
Definition managed_diagnostics.hpp:50
@ MOUNT
Create the scene root or attach and register a managed widget.
Definition managed_diagnostics.hpp:49
@ BIND
Register a managed callback, binding or presentation adapter.
Definition managed_diagnostics.hpp:51
@ INPUT
Dispatch input or deliver a managed control/property callback.
Definition managed_diagnostics.hpp:54
ScrollAxis
Logical scrolling axis; X increases right and Y increases down.
Definition scroll_geometry.hpp:15
std::expected< void, TreeError > setDeclarativeGridOptions(WidgetTree &tree, Node< Grid > node, const GridOptions &options)
Atomically replace resolved declarative settings between frames on the UI owner.
std::expected< TextSegments, TreeError > words(const GraphemeText &input, TextSplitOptions options={})
Split on whole graphemes consisting only of scalars in Unicode White_Space.
std::expected< void, StyleError > validateStyleTarget(const StyleTarget &target) noexcept
Validate bounded ancestor metadata without allocation or retaining input.
@ PAINT
Painting is required; arranged geometry remains usable.
Definition widget_types.hpp:43
std::expected< void, TreeError > setControlText(WidgetTree &tree, Node< Control > node, GraphemeText text)
Replace owning text between frames; equal bytes/policy are a no-op, changes invalidate layout.
std::function< std::expected< void, TreeError >(const ModelFrame< T > &, const std::optional< ModelRequest< T > > &)> ManagedViewHandler
Owning callback after each successful virtual-view preparation, including layout retries....
Definition managed_model.hpp:25
@ CLOSED
The owning tree or source is closed.
Definition widget_types.hpp:31
@ NODE_LIMIT
The configured live node, observer or consumer limit was reached.
Definition widget_types.hpp:35
@ WRONG_THREAD
Operation requires the tree's UI thread.
Definition widget_types.hpp:28
@ WRONG_SESSION
An identity or scope belongs to another tree/scheduler.
Definition widget_types.hpp:29
@ STALE_NODE
The observed node or model consumer is absent or retired.
Definition widget_types.hpp:30
@ WOULD_BLOCK
The current frame/reentry boundary or finite queue/work budget rejects this operation.
Definition widget_types.hpp:32
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
@ NO_MEMORY
Allocation failed inside the operation boundary.
Definition widget_types.hpp:33
Owning per-axis bounds; preferred=-1 or CONTENT uses intrinsic measurement.
Definition layout.hpp:23
SizeMode mode
Fixed does not shrink; flex shares spare cells.
Definition layout.hpp:27
std::uint32_t weight
Positive flex weight.
Definition layout.hpp:28
std::int32_t preferred
Intrinsic when -1, otherwise requested size.
Definition layout.hpp:25
Owning frame decoration and finite paint-work policy.
Definition primitives.hpp:27
Small owning paint value, independent of themes and text metrics.
Definition cell_buffer.hpp:35
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
Owning validation presentation; messages remain meaningful without color.
Definition form_field.hpp:25
Owning composition settings for an explicitly supplied custom editor.
Definition form_field.hpp:55
Owning advanced frame settings; legacy BorderOptions remains a literal value type.
Definition primitives.hpp:62
Owning sparse grid configuration; no implicit tracks or automatic placement.
Definition grid.hpp:127
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
std::optional< std::source_location > operationOrigin
Original entered operation site, before facade propagation.
Definition managed_diagnostics.hpp:84
const char * operation
Library static-storage operation label, independent of allocated diagnostic contexts.
Definition managed_diagnostics.hpp:82
NodeId node
Definition managed_diagnostics.hpp:64
std::optional< TextError > text
Original text-validation category and byte offset, when present.
Definition managed_diagnostics.hpp:69
Fixed host budgets and explicit localization; no borrowed option spans.
Definition toast.hpp:81
Owning overlay alignment and insets; all children share the content rectangle.
Definition grid.hpp:227
Provider-assigned row identity, independent of position; increment generation on reuse.
Definition row_id.hpp:9
Owning ordinary-area settings; content is retained rather than automatically virtualized....
Definition scroll_options.hpp:36
Owning standalone bar settings, validated before mounting or replacement. No callbacks,...
Definition scroll_options.hpp:17
Immutable copied top-K item. It never owns the source corpus or worker index.
Definition search.hpp:70
Owning independent policies for width and height.
Definition layout.hpp:35
AxisSize width
Horizontal policy.
Definition layout.hpp:36
AxisSize height
Vertical policy.
Definition layout.hpp:37
Owned subject metadata, supplied explicitly for built-in or custom widget types.
Definition style.hpp:40
std::vector< std::string > baseTypes
Nearest-base-first owning names, at most MAX_STYLE_BASE_TYPES; no empty, wildcard,...
Definition style.hpp:51
bool control
Also match Control selectors; explicit targets opt in independently of their type name.
Definition style.hpp:50
std::string type
Case-sensitive type name, for example Button or Table.
Definition style.hpp:46
Owning sparse literals only; never contains IDs, models, handlers or live history.
Definition ui_control_context.hpp:391
Owning bounded literal search configuration; the normal editor owns query admission/history.
Definition ui_find_bar.hpp:11
Standard text editor configuration; validation observes the normal publication boundaries.
Definition ui_form_field.hpp:26
Owning optional editor customization and confirmation policy.
Definition ui_description.hpp:34
Ordinary list/editor composition settings; search never commits or replaces editor text.
Definition ui_suggestions.hpp:57
Internal bridge for checked access to managed scene and recipe state.
Definition ui_recipe_access.hpp:28
static void preparedControl(Description< T > &description, std::uint32_t alreadyMaterialized=0)
Mark resource-resolved settings without budgeting the same fields twice.
Definition ui_description.hpp:3267
static Description< Overlay > notificationControl(Description< Overlay > description)
Definition ui_description.hpp:3356
static Description< T > describe(Factory factory)
Wrap a checked managed factory without exposing recipe construction publicly.
Definition ui_description.hpp:3467
static Description< ScrollArea > scrollAreaControl(ScrollAreaOptions options, std::shared_ptr< ScrollController > controller, ControlStyle style)
Definition ui_layout.hpp:825
static std::expected< void, ManagedError > finalizeStyleIdentity(ManagedScene &scene, Node< Widget > node, const StyleTarget &identity)
Definition ui_recipe_access.hpp:899
static Description< Widget > deferControlValidation(Description< Widget > description)
Definition ui_description.hpp:3141
static Description< T > withLayout(Description< T > description, std::shared_ptr< RecipeLayout > layout)
Definition ui_description.hpp:3229
static Description< Dialog > themeSelectorControl(Description< Dialog > description)
Definition ui_description.hpp:3339
static std::expected< Node< T >, ManagedError > mount(Description< T > &&description, ManagedScene &scene, Node< Widget > parent, MountContext &context)
Mount a root or child inside the same transaction.
Definition ui_description.hpp:3560
static ControlSettings mergeControlSettings(ControlSettings base, const ControlSettings &patch)
Definition ui_recipe_access.hpp:879
static std::expected< Node< OverlayHost >, ManagedError > layerHost(ManagedScene &scene, Node< Widget > root)
static Description< ScrollBar > scrollBarControl(std::shared_ptr< ScrollController > controller, ScrollAxis axis, ScrollBarOptions options, ControlStyle style, bool writer)
Definition ui_layout.hpp:889
static Description< T > controlSetup(Description< T > description, Callback callback)
Attach binding setup after node creation within the mount transaction.
Definition ui_description.hpp:3460
static void chartSettings(Description< T > &description, ControlSettings patch)
Definition ui_recipe_access.hpp:890
static void gridSection(Description< Grid > &parent, GridSection section)
Definition ui_description.hpp:3181
static void frameSettings(Description< T > &description, const ControlSettings &settings)
Stage precharged frame settings on the exact typed source recipe.
Definition ui_layout.hpp:997
static Description< Dialog > themeCatalogControl(Description< Dialog > description)
Definition ui_description.hpp:3326
static Description< Border > borderControl(BorderOptions options, ControlStyle style)
Definition ui_layout.hpp:1043
static Description< DataStateView > dataState(Initial initial, Description< Content > content, DataStateConfig config, bool automatic)
Build the shared checked data-presentation recipe for public overloads.
Definition ui_virtual.hpp:133
static Description< T > controlArguments(Description< T > description, ControlSettings arguments)
Retain explicit constructor properties above inherited defaults.
Definition ui_description.hpp:3417
static std::expected< void, ManagedError > gridOptions(ManagedScene &scene, Node< Grid > node, const GridOptions &options)
Definition ui_recipe_access.hpp:736
static Description< T > intrinsicStyle(Description< T > description, StyleTarget identity)
Definition ui_description.hpp:3471
static std::expected< void, ManagedError > messageBody(Description< T > &description, Description< Widget > body)
Attach an owning custom body to a resultful dialog recipe.
Definition ui_description.hpp:3384
static Description< Widget > forwardOuter(Description< Widget > description)
Definition ui_description.hpp:3498
static std::weak_ptr< const void > lifetime(ManagedScene &scene)
Definition ui_recipe_access.hpp:539
static Description< Border > framedControl(FrameOptions options, ControlStyle style)
Definition ui_layout.hpp:1015
static std::shared_ptr< RecipeLayout > captureLayouts(Children &...children)
Definition ui_description.hpp:3202
static Description< Dialog > internalDialog(Description< Dialog > description, const TextValue *prechargedTitle=nullptr)
Definition ui_description.hpp:3395
static void preparedDialogHeading(Description< Label > &description, const TextValue &title)
Definition ui_description.hpp:3302
static void preparedThemeSelectorCaption(Description< T > &description, const TextValue &caption)
Definition ui_description.hpp:3313
static void layoutChild(Description< Parent > &parent, Description< Child > &child, bool structural=false)
Definition ui_description.hpp:3238
static void preparedControlPresence(Description< T > &description, ControlPropertyPresence alreadyMaterialized)
Mark all resource-resolved fields without truncating the canonical vocabulary.
Definition ui_description.hpp:3286
static void numericSettings(Description< T > &description, ControlSettings patch)
Definition ui_description.hpp:3506
static void endMount(ManagedScene &scene) noexcept
Definition ui_recipe_access.hpp:530
static void beginMount(ManagedScene &scene) noexcept
Definition ui_recipe_access.hpp:523
static Description< Dialog > messageControl(Description< Dialog > description)
Definition ui_description.hpp:3348
static std::expected< void, ManagedError > checkLayer(ManagedScene &scene, Node< Widget > node)
static Description< T > configuredControl(Description< T > description, std::string_view type, bool inherit=true)
Attach a builtin configuration identity to an owning recipe.
Definition ui_description.hpp:3409
static Description< Widget > erase(Description< T > description)
Erase only the observer type while preserving one mount transaction.
Definition ui_description.hpp:3534
static bool themeCatalogRecipient(const Description< T > &description) noexcept
Definition ui_description.hpp:3334
static Description< T > failed(ManagedError failure)
Definition ui_description.hpp:3424
static std::expected< void, ManagedError > check(ManagedScene &scene, Node< Widget > node)
Verify a created node remains accessible before publishing references.
Definition ui_recipe_access.hpp:1394
static bool defersControlValidation(const Description< T > &description)
Definition ui_description.hpp:3149
static std::expected< void, ManagedError > finishSizing(ManagedScene &scene, Node< SizedWidget > source, Node< SizedWidget > target, const RecipeSizing *sizing)
Commit final cold bounds and transparent frame preferences in one checked update.
Definition ui_recipe_access.hpp:1309
static constexpr std::string_view controlType()
Identify builtin recipe types without allocating runtime metadata.
Definition ui_recipe_access.hpp:808
static std::expected< void, ManagedError > messageSource(Description< T > &description, const ControlSettings &settings, ControlPropertyPresence materialized, ControlFactoryKind kind=ControlFactoryKind::MESSAGE_BINDING)
Definition ui_description.hpp:3366
static Description< Widget > transaction(Factory factory)
Definition ui_description.hpp:3489
static void switchSettings(Description< Switch > &description, ControlSettings patch)
Definition ui_description.hpp:3433
static std::expected< void, ManagedError > applyScrollbarSkin(ManagedScene &scene, Node< Widget > node, const ControlSettings &settings)
Definition ui_layout.hpp:798
static std::expected< void, ManagedError > instanceState(ManagedScene &scene, Node< Widget > node, std::optional< bool > visible, std::optional< bool > enabled)
Apply final local instance flags through the existing managed mount boundary.
Definition ui_recipe_access.hpp:1358
static void gridChild(Description< Grid > &parent, Child &&child, std::optional< GridRegion > region={})
Definition ui_description.hpp:3154
static std::expected< void, ManagedError > resize(ManagedScene &scene, Node< SizedWidget > node, SizeChange change)
Definition ui_recipe_access.hpp:1260
static bool needsGridContext(const Description< T > &description)
Definition ui_description.hpp:3086
static void sizingSettings(Description< T > &description, const RecipeSizing &sizing)
Stage sizing.
Definition ui_description.hpp:3271
static Description< Overlay > overlayControl(OverlayOptions options, SizePolicy policy)
Definition ui_layout.hpp:25
Recognize exact native chart recipes without admitting arbitrary subclasses.
Definition ui_recipe_context.hpp:61
Recognize exact provider-bound list recipes, excluding arbitrary derived controls.
Definition ui_recipe_context.hpp:45
Recognize exact provider-bound table recipes, excluding arbitrary derived controls.
Definition ui_recipe_context.hpp:53
bool completed
True after source-first initial synchronization and observation registration succeed.
Definition ui_recipe_context.hpp:587
Stack-owned transaction bookkeeping, discarded after one description mount.
Definition ui_recipe_context.hpp:554
std::vector< portals::detail::MoveOnlyFunction< void()> > release
Nonthrowing releases of temporary ref reservations.
Definition ui_recipe_context.hpp:572
std::vector< portals::detail::MoveOnlyFunction< void()> > rollback
Explicit attempt-owned resources, never numeric checkpoints.
Definition ui_recipe_context.hpp:596