Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
ui_description.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/ui_event_access.hpp>
6#include <portals/detail/ui_recipe_access.hpp>
7#include <portals/ui_key_info.hpp>
8
9#include <cmath>
10#include <limits>
11
12namespace portals::ui {
19template <detail::DescriptionInput Child>
20Description<Border> border(Child &&child, BorderOptions options = {}, ControlStyle style = {});
21
29template <detail::DescriptionInput Child>
30Description<ScrollArea> scrollArea(Child &&child, ScrollAreaOptions options = {},
31 std::shared_ptr<ScrollController> controller = {}, ControlStyle style = {});
32
35 std::function<std::expected<void, TreeError>(LineEditResult)> result{};
38 std::shared_ptr<Clipboard> clipboard{};
39 std::function<bool(std::string_view)> validate{};
40};
41
48template <class T> class Description {
49public:
51 Description() = default;
52
54 Description(Description &&) noexcept = default;
55
59 Description &operator=(Description &&) noexcept = default;
60
61 Description(const Description &) = delete;
62
63 Description &operator=(const Description &) = delete;
64
70 if (state_) {
71 detail::freezeControlDocumentSettings(patch);
72 state_->controlPatch = std::move(patch);
73 state_->settingsRequested = true;
74
75 if constexpr (std::same_as<T, Grid>) {
76 if (state_->layout && state_->layout->gridContainer) {
77 gridControl().patch = state_->controlPatch;
78 gridControl().settingsRequested = true;
79 declarativeOptions();
80 }
81 }
82 }
83 return std::move(*this);
84 }
85
88 requires std::same_as<T, DocumentView>
89 {
90 ControlSettings patch;
91 auto document = std::make_shared<ControlDocumentSettings>();
92
93 document->mode = value;
94 patch.document = std::move(document);
95
96 return std::move(*this).scalarSettings(std::move(patch));
97 }
98
101 requires std::same_as<T, DocumentView>
102 {
103 ControlSettings patch;
104 auto document = std::make_shared<ControlDocumentSettings>();
105
106 document->mode = DocumentViewMode::HEX;
107 document->hexBytesPerRow = options.bytesPerRow;
108 document->hexGroupSize = options.groupSize;
109 document->hexUppercase = options.uppercase;
110 document->hexShowAscii = options.showAscii;
111 document->hexAutoFit = options.autoFit;
112 patch.document = std::move(document);
113
114 return std::move(*this).scalarSettings(std::move(patch));
115 }
116
121 requires std::same_as<T, DocumentView>
122 {
123 ControlSettings patch;
124 auto document = std::make_shared<ControlDocumentSettings>();
125 document->language = value;
126 patch.document = std::move(document);
127
128 return std::move(*this).scalarSettings(std::move(patch));
129 }
130
134 Description &&language(std::string_view name) &&
135 requires std::same_as<T, DocumentView>
136 {
137 return std::move(*this).language(documentLanguageFromName(name));
138 }
139
144 requires std::same_as<T, DocumentView>
145 {
146 ControlSettings patch;
147 auto document = std::make_shared<ControlDocumentSettings>();
148 document->syntax = value;
149 patch.document = std::move(document);
150
151 return std::move(*this).scalarSettings(std::move(patch));
152 }
153
156 requires std::same_as<T, DocumentView>
157 {
158 return std::move(*this).setup([enabled](ManagedScene &scene, Node<T> node) {
159 return setDocumentLineNumbers(scene, node, enabled);
160 });
161 }
162
167 Description &&fastScroll(std::uint64_t step = 8, key::Modifier keyboard = key::CTRL,
168 key::Modifier wheel = key::ALT) &&
169 requires std::same_as<T, DocumentView>
170 {
171 ControlSettings patch;
172 auto document = std::make_shared<ControlDocumentSettings>();
173 document->fastScroll = step;
174 document->fastKeyModifier = keyboard;
175 document->fastWheelModifier = wheel;
176 patch.document = std::move(document);
177
178 return std::move(*this).scalarSettings(std::move(patch));
179 }
180
184 Description &&scrollStep(std::uint64_t rows) &&
185 requires std::same_as<T, DocumentView>
186 {
187 return std::move(*this)
188 .scalarSettings({.wheelStep = static_cast<double>(rows), .keyStep = rows})
189 .setup([rows](ManagedScene &, Node<T> node) -> std::expected<void, ManagedError> {
190 if (rows > static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max())) {
191 return std::unexpected(detail::error(node, TreeError::INVALID_ARGUMENT));
192 }
193 return {};
194 });
195 }
196
198 Description &&wrap(bool enabled = true) &&
199 requires std::same_as<T, DocumentView>
200 {
201 return std::move(*this).setup([enabled](ManagedScene &scene, Node<T> node) {
202 return setDocumentWrap(scene, node, enabled);
203 });
204 }
205
208 requires std::same_as<T, DocumentView>
209 {
210 return std::move(*this).setup([value](ManagedScene &scene, Node<T> node) {
211 return setDocumentEncoding(scene, node, value);
212 });
213 }
214
219 requires std::same_as<T, CheckBox>
220 {
221 return std::move(*this).scalarSettings({.cycle = CheckCycle::THREE_STATE});
222 }
223
228 requires std::same_as<T, Button>
229 {
230 return std::move(*this).scalarSettings({.chrome = value});
231 }
232
237 requires std::derived_from<T, SizedWidget>
238 {
239 return std::move(*this).scalarSettings({.glyphProfile = value});
240 }
241
245 Description &&glyphProfile(std::string_view value) &&
246 requires std::derived_from<T, SizedWidget>
247 {
248 return std::move(*this).glyphProfile(detail::glyphProfile(value));
249 }
250
255 requires std::derived_from<T, SizedWidget>
256 {
257 return std::move(*this).scalarSettings({.glyphFallback = value});
258 }
259
261 Description &&glyphFallback(std::string_view value) &&
262 requires std::derived_from<T, SizedWidget>
263 {
264 return std::move(*this).glyphFallback(detail::glyphFallback(value));
265 }
266
271 requires(std::same_as<T, Border> || std::same_as<T, Gauge> || std::same_as<T, Spinner> ||
272 std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
273 {
274 return std::move(*this).scalarSettings({.glyphs = value});
275 }
276
280 Description &&maxPaintCells(std::size_t cells) &&
281 requires(std::same_as<T, Border> || std::same_as<T, Gauge> || std::same_as<T, Spinner> ||
282 std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
283 {
284 return std::move(*this).scalarSettings({.maxPaintCells = cells});
285 }
286
291 requires(std::same_as<T, Gauge> || std::same_as<T, Slider> || std::same_as<T, SpinBox>)
292 {
293 return std::move(*this).scalarSettings({.value = value});
294 }
295
300 requires(std::same_as<T, Gauge> || std::same_as<T, Slider> || std::same_as<T, SpinBox>)
301 {
302 return std::move(*this).scalarSettings({.minimum = value});
303 }
304
309 requires(std::same_as<T, Gauge> || std::same_as<T, Slider> || std::same_as<T, SpinBox>)
310 {
311 return std::move(*this).scalarSettings({.maximum = value});
312 }
313
318 Description &&range(double minimum, double maximum) &&
319 requires(std::same_as<T, Gauge> || std::same_as<T, Slider> || std::same_as<T, SpinBox>)
320 {
321 return std::move(*this).scalarSettings({.minimum = minimum, .maximum = maximum});
322 }
323
327 Description &&preferredWidth(std::int32_t cells) &&
328 requires(std::same_as<T, Gauge> || std::same_as<T, Slider> || std::same_as<T, SpinBox>)
329 {
330 return std::move(*this).scalarSettings({.preferredWidth = cells});
331 }
332
336 Description &&step(double amount) &&
337 requires(std::same_as<T, Slider> || std::same_as<T, SpinBox>)
338 {
339 return std::move(*this).scalarSettings({.step = amount});
340 }
341
345 Description &&skin(std::string_view name) &&
346 requires(std::same_as<T, Slider> || std::same_as<T, SpinBox>)
347 {
348 return std::move(*this).scalarSettings({.sliderSkin = std::string(name)});
349 }
350
355 requires std::same_as<T, Slider>
356 {
357 constexpr std::array<std::string_view, 4> SKIN_NAMES{"ascii", "line", "rounded", "blocks"};
358 const auto index = static_cast<std::size_t>(value);
359 return std::move(*this).skin(index < SKIN_NAMES.size() ? SKIN_NAMES[index] : std::string_view{});
360 }
361
366 requires std::same_as<T, SpinBox>
367 {
368 constexpr std::array<std::string_view, 3> SKIN_NAMES{"standard", "compact", "arrows"};
369 const auto index = static_cast<std::size_t>(value);
370
371 return std::move(*this).skin(index < SKIN_NAMES.size() ? SKIN_NAMES[index] : std::string_view{});
372 }
373
378 requires std::same_as<T, Slider>
379 {
380 return std::move(*this).scalarSettings({.sliderTrack = std::move(value.track),
381 .sliderFill = std::move(value.fill),
382 .sliderThumb = std::move(value.thumb)});
383 }
384
388 Description &&pageSteps(std::uint64_t count) &&
389 requires(std::same_as<T, Slider> || std::same_as<T, SpinBox>)
390 {
391 return std::move(*this).scalarSettings({.pageSteps = count});
392 }
393
397 Description &&wheelStep(double cells) &&
398 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
399 {
400 return std::move(*this).scalarSettings({.wheelStep = cells});
401 }
402
406 Description &&keyStep(std::uint64_t cells) &&
407 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
408 {
409 return std::move(*this).scalarSettings({.keyStep = cells});
410 }
411
415 Description &&pageOverlap(std::uint64_t cells) &&
416 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar> || std::same_as<T, DocumentView>)
417 {
418 return std::move(*this).scalarSettings({.pageOverlap = cells});
419 }
420
424 Description &&arrows(bool enabled = true) &&
425 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
426 {
427 return std::move(*this).scalarSettings({.arrows = enabled});
428 }
429
433 Description &&minimumThumb(std::int32_t cells) &&
434 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
435 {
436 return std::move(*this).scalarSettings({.minimumThumb = cells});
437 }
438
442 Description &&focusable(bool value = true) &&
443 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
444 {
445 return std::move(*this).scalarSettings({.focusable = value});
446 }
447
451 Description &&readOnly(bool value = true) &&
452 requires(std::same_as<T, LineEdit> || std::same_as<T, Password> || std::same_as<T, ScrollArea> ||
453 std::same_as<T, ScrollBar> || std::same_as<T, Slider> || std::same_as<T, RadioGroup> ||
454 std::same_as<T, SpinBox>)
455 {
456 return std::move(*this).scalarSettings({.readOnly = value});
457 }
458
461 requires std::same_as<T, RadioGroup>
462 {
463 return std::move(*this).scalarSettings({.radioSelectionMode = value});
464 }
465
469 Description &&immediate(bool enabled = true) &&
470 requires std::same_as<T, RadioGroup>
471 {
472 return std::move(*this).selectionMode(enabled ? RadioSelectionMode::IMMEDIATE : RadioSelectionMode::ON_ACTIVATION);
473 }
474
478 Description &&fuzzy(bool enabled = true) &&
479 requires std::derived_from<T, ComboBox>
480 {
481 return std::move(*this).scalarSettings(
482 {.searchStrategy = enabled ? SearchStrategy::FUZZY_PREFIX : SearchStrategy::PREFIX});
483 }
484
487 requires std::derived_from<T, ComboBox>
488 {
489 return std::move(*this).fuzzy(false);
490 }
491
495 Description &&noEcho(bool enabled = true) &&
496 requires(std::same_as<T, LineEdit> || std::same_as<T, Password> || std::same_as<T, SpinBox>)
497 {
499 : std::same_as<T, Password> ? LineEditDisplayMode::PASSWORD
501
502 return std::move(*this).scalarSettings({.displayMode = mode});
503 }
504
507 requires(std::same_as<T, LineEdit> || std::same_as<T, Password> || std::same_as<T, SpinBox>)
508 {
509 return std::move(*this).scalarSettings({.editMode = value});
510 }
511
515 requires(std::same_as<T, LineEdit> || std::same_as<T, Password> || std::same_as<T, SpinBox>)
516 {
517 return std::move(*this).scalarSettings({.placeholder = std::move(value)});
518 }
519
521 Description &&placeholder(std::string_view value) &&
522 requires(std::same_as<T, LineEdit> || std::same_as<T, Password> || std::same_as<T, SpinBox>)
523 {
524 return std::move(*this).placeholder(TextValue(value));
525 }
526
531 requires std::same_as<T, ScrollArea>
532 {
533 return std::move(*this).scalarSettings({.horizontal = policy});
534 }
535
540 requires std::same_as<T, ScrollArea>
541 {
542 return std::move(*this).scalarSettings({.vertical = policy});
543 }
544
549 requires std::same_as<T, ScrollArea>
550 {
551 return std::move(*this).scalarSettings({.placement = placement});
552 }
553
558 requires std::same_as<T, ScrollArea>
559 {
560 return std::move(*this).placement(ScrollPlacement::ON_FRAME);
561 }
562
566 Description &&scrollbar(std::string_view pattern) &&
567 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
568 {
569 return std::move(*this).scrollbar(detail::scrollbarPattern(pattern));
570 }
571
576 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
577 {
578 return std::move(*this).scalarSettings({.scrollbar = {.pattern = pattern}});
579 }
580
584 Description &&scrollTrack(std::string_view pattern) &&
585 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
586 {
587 return std::move(*this).scrollTrack(detail::scrollbarPattern(pattern));
588 }
589
592 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
593 {
594 return std::move(*this).scalarSettings({.scrollbar = {.trackPattern = pattern}});
595 }
596
600 Description &&scrollThumb(std::string_view pattern) &&
601 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
602 {
603 return std::move(*this).scrollThumb(detail::scrollbarThumbPattern(pattern));
604 }
605
608 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
609 {
610 return std::move(*this).scalarSettings({.scrollbar = {.thumbPattern = pattern}});
611 }
612
616 Description &&scrollArrows(std::string_view pattern) &&
617 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
618 {
619 return std::move(*this).scrollArrows(detail::scrollbarArrowPattern(pattern));
620 }
621
624 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
625 {
626 return std::move(*this).scalarSettings({.scrollbar = {.arrowPattern = pattern}});
627 }
628
634 requires(std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar>)
635 {
636 return std::move(*this).scalarSettings({.scrollbar = {.pattern = skin.pattern,
637 .ends = skin.ends,
638 .maxGlyphBytes = skin.maxGlyphBytes,
639 .horizontal = skin.horizontal,
640 .vertical = skin.vertical,
641 .corner = skin.corner,
642 .trackPattern = skin.trackPattern,
643 .thumbPattern = skin.thumbPattern,
644 .arrowPattern = skin.arrowPattern},
645 .glyphProfile = skin.glyphSelection.profile,
646 .glyphFallback = skin.glyphSelection.fallback});
647 }
648
653 requires std::same_as<T, ScrollArea>
654 {
655 return std::move(*this).scalarSettings({.frame = {.enabled = enabled}});
656 }
657
662 requires std::same_as<T, ScrollArea>
663 {
664 return std::move(*this).scalarSettings({.frame = {.glyphs = glyphs}});
665 }
666
670 Description &&frameMaxPaintCells(std::size_t cells) &&
671 requires std::same_as<T, ScrollArea>
672 {
673 return std::move(*this).scalarSettings({.frame = {.maxPaintCells = cells}});
674 }
675
680 requires std::same_as<T, ScrollBar>
681 {
682 return std::move(*this).scalarSettings({.axis = axis});
683 }
684
688 Description &&rowHeight(std::int32_t value) &&
690 {
691 return std::move(*this).scalarSettings({.rowHeight = value});
692 }
693
698 requires requires { typename T::VirtualRow; }
699 {
700 return std::move(*this).setup([enabled](ManagedScene &scene, Node<T> node) {
701 return setVirtualRowsAutoRowHeight(scene, node, enabled);
702 });
703 }
704
710 {
711 return std::move(*this).scalarSettings({.overscanRows = value});
712 }
713
717 Description &&maxColumns(std::size_t value) &&
719 {
720 return std::move(*this).scalarSettings({.maxColumns = value});
721 }
722
728 {
729 return std::move(*this).scalarSettings({.maxPreparedCells = value});
730 }
731
737 {
738 return std::move(*this).scalarSettings({.maxPreparedTextBytes = value});
739 }
740
746 {
747 return std::move(*this).scalarSettings({.mode = value});
748 }
749
755 {
756 return std::move(*this).scalarSettings({.chartGlyphSet = value});
757 }
758
762 Description &&candleGap(std::int32_t cells) &&
764 {
765 return std::move(*this).scalarSettings({.candleGap = cells});
766 }
767
771 Description &&yRange(std::optional<ChartRange> range) &&
773 {
774 ControlChartRangeSettings patch{.enabled = range.has_value()};
775
776 if (range) {
777 patch.minimum = range->minimum;
778 patch.maximum = range->maximum;
779 }
780
781 return std::move(*this).scalarSettings({.yRange = patch});
782 }
783
787 Description &&showStatus(bool value = true) &&
788 requires std::same_as<T, DataStateView>
789 {
790 return std::move(*this).scalarSettings({.showStatus = value});
791 }
792
796 Description &&statusRows(std::int32_t value) &&
797 requires std::same_as<T, DataStateView>
798 {
799 return std::move(*this).scalarSettings({.statusRows = value});
800 }
801
806 requires std::same_as<T, DataStateView>
807 {
808 return std::move(*this).scalarSettings({.contentPolicy = value});
809 }
810
815 requires std::same_as<T, DataStateView>
816 {
817 return std::move(*this).scalarSettings({.spinnerInterval = value});
818 }
819
824 requires std::same_as<T, DataStateView>
825 {
826 return std::move(*this).scalarSettings({.labels = std::move(values)});
827 }
828
832 Description &&maxLayers(std::size_t value) &&
833 requires std::same_as<T, OverlayHost>
834 {
835 return std::move(*this).scalarSettings({.maxLayers = value});
836 }
837
842 requires std::same_as<T, Dialog>
843 {
844 return std::move(*this).scalarSettings({.title = std::move(value)});
845 }
846
850 Description &&title(std::string_view value) &&
851 requires std::same_as<T, Dialog>
852 {
853 return std::move(*this).title(TextValue(value));
854 }
855
860 requires std::same_as<T, Dialog>
861 {
862 return std::move(*this).scalarSettings({.dialog = {.mode = value}});
863 }
864
871 requires std::same_as<T, Dialog>
872 {
873 return std::move(*this).mode(DialogMode::NON_MODAL);
874 }
875
880 requires std::same_as<T, Dialog>
881 {
882 return std::move(*this).scalarSettings({.dialog = {.placement = value}});
883 }
884
889 requires std::same_as<T, Dialog>
890 {
891 return std::move(*this).scalarSettings({.dialog = {.viewportMargin = value}});
892 }
893
897 Description &&anchorGap(std::int32_t value) &&
898 requires std::same_as<T, Dialog>
899 {
900 return std::move(*this).scalarSettings({.dialog = {.anchorGap = value}});
901 }
902
907 requires std::same_as<T, Dialog>
908 {
909 return std::move(*this).scalarSettings({.dialog = {.closeOnEscape = value}});
910 }
911
916 requires std::same_as<T, Dialog>
917 {
918 return std::move(*this).scalarSettings(
919 {.dialog = {
920 .closeButton = {.enabled = options.enabled, .placement = options.placement, .focusable = options.focusable}}});
921 }
922
927 requires std::same_as<T, Dialog>
928 {
929 return std::move(*this).scalarSettings(
930 {.dialog = {.maximumPanelSize = {.width = caps.width, .height = caps.height}}});
931 }
932
937 requires std::same_as<T, Dialog>
938 {
939 return std::move(*this).scalarSettings(
940 {.dialog = {.frame = {.glyphs = options.glyphs, .maxPaintCells = options.maxPaintCells}}});
941 }
942
947 requires std::same_as<T, Dialog>
948 {
949 return std::move(*this).scalarSettings({.dialog = values});
950 }
951
956 requires std::same_as<T, Dialog>
957 {
958 return std::move(*this).scalarSettings({.body = std::move(value)});
959 }
960
962 Description &&body(std::string_view value) &&
963 requires std::same_as<T, Dialog>
964 {
965 return std::move(*this).body(TextValue(value));
966 }
967
972 requires std::same_as<T, Dialog>
973 {
974 if (state_) {
975 state_->messageSettingsRequested = true;
976 }
977
978 return std::move(*this).scalarSettings({.message = std::move(values)});
979 }
980
985 requires std::same_as<T, Dialog>
986 {
987 if (state_) {
988 state_->themeCatalogSettingsRequested = true;
989 }
990 return std::move(*this).scalarSettings({.themeCatalog = std::move(values)});
991 }
992
997 requires std::same_as<T, Dialog>
998 {
999 if (state_) {
1000 state_->themeSelectorSettingsRequested = true;
1001 }
1002
1003 return std::move(*this).scalarSettings({.themeSelector = std::move(values)});
1004 }
1005
1010 requires std::same_as<T, Overlay>
1011 {
1012 if (state_) {
1013 state_->notificationSettingsRequested = true;
1014 }
1015
1016 return std::move(*this).scalarSettings({.notification = values});
1017 }
1018
1022 Description &&initiallyOpen(bool opened = true) &&
1023 requires std::same_as<T, HelpView>
1024 {
1025 return std::move(*this).scalarSettings({.initiallyOpen = opened});
1026 }
1027
1032 requires(std::same_as<T, HelpView> || std::same_as<T, KeyHints>)
1033 {
1034 return std::move(*this).scalarSettings({.format = std::move(values)});
1035 }
1036
1040 Description &&emptyText(std::string value) &&
1041 requires(std::same_as<T, HelpView> || std::same_as<T, KeyHints>)
1042 {
1043 return std::move(*this).scalarSettings({.emptyText = std::move(value)});
1044 }
1045
1050 requires(std::same_as<T, HelpView> || std::same_as<T, KeyHints>)
1051 {
1052 return std::move(*this).scalarSettings({.unavailableText = std::move(value)});
1053 }
1054
1059 requires std::same_as<T, KeyHints>
1060 {
1061 return std::move(*this).scalarSettings({.entrySeparator = std::move(value)});
1062 }
1063
1068 requires std::same_as<T, KeyHints>
1069 {
1070 return std::move(*this).scalarSettings({.overflowMarker = std::move(value)});
1071 }
1072
1077 requires std::same_as<T, Overlay>
1078 {
1079 return std::move(*this).scalarSettings({.grid = {.paddingLeft = insets.left,
1080 .paddingTop = insets.top,
1081 .paddingRight = insets.right,
1082 .paddingBottom = insets.bottom}});
1083 }
1084
1089 requires std::same_as<T, Spinner>
1090 {
1091 return std::move(*this).scalarSettings({.spinnerPreset = value});
1092 }
1093
1098 template <typename Name>
1099 requires(std::same_as<T, Spinner> && std::convertible_to<Name, std::string_view>)
1100 Description &&preset(Name &&value) && {
1101 return std::move(*this).preset(spinnerPreset(std::string_view(value)));
1102 }
1103
1107 Description &&frames(std::initializer_list<std::string_view> values) &&
1108 requires std::same_as<T, Spinner>
1109 {
1110 return std::move(*this).frames(::portals::detail::spinnerFrames(values));
1111 }
1112
1116 Description &&frames(std::string_view value) &&
1117 requires std::same_as<T, Spinner>
1118 {
1119 return std::move(*this).scalarSettings({.spinnerFrames = std::string(value)});
1120 }
1121
1126 requires std::same_as<T, Spinner>
1127 {
1128 return std::move(*this).scalarSettings({.spinnerTick = value});
1129 }
1130
1135 requires std::same_as<T, Spinner>
1136 {
1137 return std::move(*this).scalarSettings({.spinnerDirection = value});
1138 }
1139
1144 requires std::same_as<T, Spinner>
1145 {
1146 return std::move(*this).scalarSettings({.spinnerAlignment = value});
1147 }
1148
1153 requires std::same_as<T, Spinner>
1154 {
1155 return std::move(*this).scalarSettings({.spinnerActive = value});
1156 }
1157
1162 requires std::same_as<T, Spinner>
1163 {
1164 return std::move(*this).scalarSettings({.spinnerReducedMotion = value});
1165 }
1166
1170 Description &&label(std::string_view value) &&
1171 requires std::same_as<T, Spinner>
1172 {
1173 return std::move(*this).label(TextValue(value));
1174 }
1175
1180 requires std::same_as<T, Spinner>
1181 {
1182 return std::move(*this).scalarSettings({.spinnerLabel = std::move(value)});
1183 }
1184
1188 Description &&maxFrames(std::size_t value) &&
1189 requires std::same_as<T, Spinner>
1190 {
1191 return std::move(*this).scalarSettings({.spinnerMaxFrames = value});
1192 }
1193
1198 requires std::same_as<T, Spinner>
1199 {
1200 return std::move(*this).scalarSettings({.spinnerMaxFrameBytes = value});
1201 }
1202
1207 requires std::same_as<T, Spinner>
1208 {
1209 return std::move(*this).scalarSettings({.spinnerMaxFrameCells = value});
1210 }
1211
1216 requires std::same_as<T, Overlay>
1217 {
1218 return std::move(*this).scalarSettings({.horizontalAlign = align});
1219 }
1220
1225 requires std::same_as<T, Overlay>
1226 {
1227 return std::move(*this).scalarSettings({.verticalAlign = align});
1228 }
1229
1234 Description &&variant(std::string_view type) && {
1235 if (state_) {
1236 state_->controlVariant.emplace(type);
1237
1238 if constexpr (std::same_as<T, Grid>) {
1239 if (state_->layout && state_->layout->gridContainer) {
1240 gridControl().variant.emplace(type);
1241 declarativeOptions();
1242 }
1243 }
1244 }
1245 return std::move(*this);
1246 }
1247
1252 return std::move(*this).storeReference(std::move(reference));
1253 }
1254
1260 template <class U>
1262 requires std::same_as<T, Dialog>
1263 {
1264 if (state_) {
1265 state_->anchor = reference.target();
1266 state_->placement = placement;
1267 state_->anchorRequested = true;
1268 }
1269 return std::move(*this);
1270 }
1271
1276 template <class Callback>
1277 Description &&onDismiss(Callback callback) &&
1278 requires std::same_as<T, Dialog>
1279 {
1280 return std::move(*this).setup([callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1281 return scene.onDismiss(node, std::move(callback));
1282 });
1283 }
1284
1289 if (state_ && state_->id) {
1290 if (target.id.empty()) {
1291 target.id = *state_->id;
1292 } else if (!target.id.empty()) {
1293 state_->id = target.id;
1294 }
1295 }
1296
1297 return std::move(*this).setup([target = std::move(target)](ManagedScene &scene, Node<T> node) mutable {
1298 return scene.style(node, std::move(target));
1299 });
1300 }
1301
1306 Description &&id(std::string_view value) && {
1307 if (state_) {
1308 state_->id.emplace(value);
1309 }
1310
1311 return std::move(*this).setup([value = detail::captureText(value)](ManagedScene &scene, Node<T> node) {
1312 return scene.id(node, detail::captionView(value));
1313 });
1314 }
1315
1320 Description &&classes(std::string_view value) && {
1321 return std::move(*this).setup([values = detail::splitClasses(value)](ManagedScene &scene, Node<T> node) mutable {
1322 return scene.classes(node, values.values);
1323 });
1324 }
1325
1330 template <class Callback = detail::QuitCommand>
1331 requires(std::same_as<T, Button> && portals::detail::ManagedAction<Callback, ClickEvent>)
1332 Description &&onClick(Callback callback) && {
1333 if constexpr (std::same_as<Callback, ActionRef>) {
1334 return std::move(*this).setup([declaration = detail::retainAction(callback),
1335 callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1336 (void)declaration;
1337
1338 return scene.onClick(node, std::move(callback));
1339 });
1340 }
1341
1342 return std::move(*this).setup([callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1343 return scene.onClick(node, std::move(callback));
1344 });
1345 }
1346
1353 template <std::equality_comparable Value, class Callback>
1354 requires std::copy_constructible<Callback> &&
1355 (std::same_as<std::invoke_result_t<Callback &, const Value &>, void> ||
1356 std::same_as<std::invoke_result_t<Callback &, const Value &>, std::expected<void, TreeError>>)
1357 Description &&observe(ManagedState<Value> model, Callback callback) && {
1358 return std::move(*this).setup([model, callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1359 return scene.observe(node, model, std::move(callback));
1360 });
1361 }
1362
1370 template <std::equality_comparable Value, class Callback>
1371 requires std::copy_constructible<Callback> &&
1372 (std::same_as<std::invoke_result_t<Callback &, const Value &>, void> ||
1373 std::same_as<std::invoke_result_t<Callback &, const Value &>, std::expected<void, TreeError>>)
1374 Description &&observe(ManagedSource<Value> source, Callback callback) && {
1375 return std::move(*this).setup([source, callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1376 return scene.observe(node, source, std::move(callback));
1377 });
1378 }
1379
1384 return std::move(*this).setup([callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1385 return scene.onEvent(node, std::move(callback));
1386 });
1387 }
1388
1393 return std::move(*this).setup([callback = std::move(callback)](ManagedScene &scene, Node<T> node) mutable {
1394 return scene.onPrepare(node, std::move(callback));
1395 });
1396 }
1397
1402 template <class Callback>
1403 requires std::copy_constructible<Callback> &&
1405 (!std::same_as<std::invoke_result_t<Callback &, T &, Node<Widget>>, std::expected<void, TreeError>>)
1406 Description &&onPrepare(Callback callback) && {
1407 ManagedPrepareHandler<T> normalized;
1408 bool present = true;
1409
1410 if constexpr (std::is_pointer_v<Callback> || requires { callback.operator bool(); }) {
1411 present = static_cast<bool>(callback);
1412 }
1413
1414 if (present) {
1415 normalized = [callback = std::move(callback)](T &widget, Node<Widget> focused) mutable {
1416 return portals::detail::invokeIgnoringValue(callback, widget, focused);
1417 };
1418 }
1419
1420 return std::move(*this).onPrepare(std::move(normalized));
1421 }
1422
1426 Description &&visible(bool value = true) && {
1427 if (state_) {
1428 state_->visible = value;
1429 }
1430
1431 return std::move(*this);
1432 }
1433
1437 Description &&enabled(bool value = true) && {
1438 if (state_) {
1439 state_->enabled = value;
1440 }
1441
1442 return std::move(*this);
1443 }
1444
1451 requires std::derived_from<T, SizedWidget>
1452 {
1453 if (state_) {
1454 auto &frame = frameRecipe();
1455
1456 frame.options = std::move(options);
1457 frame.hasOptions = true;
1458 frame.invalidPattern = false;
1459 frame.titleBinding = {};
1460 }
1461
1462 return std::move(*this);
1463 }
1464
1469 requires std::derived_from<T, SizedWidget>
1470 {
1471 if (state_) {
1472 auto &frame = frameRecipe();
1473 frame.hasOptions = true;
1474 frame.options.titleDecoration = decoration;
1475 frame.options.customTitleDecoration.reset();
1476 }
1477
1478 return std::move(*this);
1479 }
1480
1484 Description &&titleDecoration(std::string_view name) &&
1485 requires std::derived_from<T, SizedWidget>
1486 {
1487 return std::move(*this).titleDecoration(detail::titleDecorationPreset(name));
1488 }
1489
1494 requires std::derived_from<T, SizedWidget>
1495 {
1496 if (state_) {
1497 auto &frame = frameRecipe();
1498 frame.hasOptions = true;
1499 frame.options.customTitleDecoration = decoration;
1500 }
1501
1502 return std::move(*this);
1503 }
1504
1508 Description &&framed(std::string_view pattern) &&
1509 requires std::derived_from<T, SizedWidget>
1510 {
1511 if (state_) {
1512 auto &frame = frameRecipe();
1513 const auto selected = detail::framePattern(pattern);
1514
1515 frame.options = {};
1516 frame.hasOptions = true;
1517 frame.invalidPattern = !selected;
1518 frame.titleBinding = {};
1519
1520 if (selected) {
1521 frame.options.pattern = *selected;
1522 }
1523 }
1524
1525 return std::move(*this);
1526 }
1527
1532 Description &&framed(std::string_view pattern, std::string_view title) &&
1533 requires std::derived_from<T, SizedWidget>
1534 {
1535 (void)std::move(*this).framed(pattern);
1536
1537 if (state_) {
1538 frameRecipe().options.title = title;
1539 }
1540
1541 return std::move(*this);
1542 }
1543
1550 template <class Title>
1551 requires std::same_as<Title, ValueText>
1552 Description &&framed(std::string_view pattern, Title title) &&
1553 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>);
1554
1559 template <class Value>
1560 requires std::formattable<Value, char> && std::equality_comparable<Value> &&
1561 std::copy_constructible<Value>
1562 Description &&framed(std::string_view pattern, Model<Value> title) &&
1563 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>);
1564
1570 Description &&framed(Ref<Border> outer, FrameOptions options = {}) &&
1571 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>)
1572 {
1573 (void)std::move(*this).framed(std::move(options));
1574
1575 if (state_) {
1576 frameRecipe().reference = std::move(outer);
1577 }
1578
1579 return std::move(*this);
1580 }
1581
1586 Description &&framed(Ref<Border> outer, std::string_view pattern) &&
1587 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>)
1588 {
1589 (void)std::move(*this).framed(pattern);
1590
1591 if (state_) {
1592 frameRecipe().reference = std::move(outer);
1593 }
1594
1595 return std::move(*this);
1596 }
1597
1603 Description &&framed(Ref<Border> outer, std::string_view pattern, std::string_view title) &&
1604 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>)
1605 {
1606 (void)std::move(*this).framed(std::move(outer), pattern);
1607
1608 if (state_) {
1609 frameRecipe().options.title = title;
1610 }
1611
1612 return std::move(*this);
1613 }
1614
1620 template <class Title>
1621 requires std::same_as<Title, ValueText>
1622 Description &&framed(Ref<Border> outer, std::string_view pattern, Title title) &&
1623 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>);
1624
1630 template <class Value>
1631 requires std::formattable<Value, char> && std::equality_comparable<Value> &&
1632 std::copy_constructible<Value>
1633 Description &&framed(Ref<Border> outer, std::string_view pattern, Model<Value> title) &&
1634 requires(std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>);
1635
1639 Description &&width(std::int32_t cells) &&
1640 requires std::derived_from<T, SizedWidget>
1641 {
1642 return std::move(*this).resize({detail::SizeDimension::WIDTH, cells});
1643 }
1644
1648 Description &&height(std::int32_t cells) &&
1649 requires std::derived_from<T, SizedWidget>
1650 {
1651 return std::move(*this).resize({detail::SizeDimension::HEIGHT, cells});
1652 }
1653
1656 requires std::derived_from<T, SizedWidget>
1657 {
1658 return std::move(*this).constrainSize({detail::SizeDimension::FIT_WIDTH});
1659 }
1660
1663 requires std::derived_from<T, SizedWidget>
1664 {
1665 return std::move(*this).constrainSize({detail::SizeDimension::FIT_HEIGHT});
1666 }
1667
1671 Description &&minWidth(std::int32_t cells) &&
1672 requires std::derived_from<T, SizedWidget>
1673 {
1674 return std::move(*this).constrainSize({detail::SizeDimension::MIN_WIDTH, cells});
1675 }
1676
1680 Description &&maxWidth(std::int32_t cells) &&
1681 requires std::derived_from<T, SizedWidget>
1682 {
1683 return std::move(*this).constrainSize({detail::SizeDimension::MAX_WIDTH, cells});
1684 }
1685
1689 Description &&minHeight(std::int32_t cells) &&
1690 requires std::derived_from<T, SizedWidget>
1691 {
1692 return std::move(*this).constrainSize({detail::SizeDimension::MIN_HEIGHT, cells});
1693 }
1694
1698 Description &&maxHeight(std::int32_t cells) &&
1699 requires std::derived_from<T, SizedWidget>
1700 {
1701 return std::move(*this).constrainSize({detail::SizeDimension::MAX_HEIGHT, cells});
1702 }
1703
1707 Description &&columns(std::size_t count) &&
1708 requires std::same_as<T, Grid>
1709 {
1710 if (state_) {
1711 declarativeOptions().columns = count;
1712 gridControl().arguments.grid.columns = count;
1713 }
1714
1715 return std::move(*this);
1716 }
1717
1721 Description &&rows(std::size_t count) &&
1722 requires std::same_as<T, Grid>
1723 {
1724 if (state_) {
1725 declarativeOptions().rows = count;
1726 gridControl().arguments.grid.rows = count;
1727 }
1728
1729 return std::move(*this);
1730 }
1731
1736 requires std::same_as<T, Grid>
1737 {
1738 if (state_) {
1739 declarativeOptions().flow = value;
1740 gridControl().arguments.grid.flow = value;
1741 }
1742
1743 return std::move(*this);
1744 }
1745
1749 Description &&columnGap(std::int32_t cells) &&
1750 requires std::same_as<T, Grid>
1751 {
1752 if (state_) {
1753 declarativeOptions().columnGap = cells;
1754 gridControl().arguments.grid.columnGap = cells;
1755 }
1756
1757 return std::move(*this);
1758 }
1759
1763 Description &&rowGap(std::int32_t cells) &&
1764 requires std::same_as<T, Grid>
1765 {
1766 if (state_) {
1767 declarativeOptions().rowGap = cells;
1768 gridControl().arguments.grid.rowGap = cells;
1769 }
1770
1771 return std::move(*this);
1772 }
1773
1778 requires std::same_as<T, Grid>
1779 {
1780 if (state_) {
1781 declarativeOptions() = options;
1782 auto &arguments = gridControl().arguments.grid;
1783
1784 arguments.columns = options.columns;
1785 arguments.rows = options.rows;
1786 arguments.flow = options.flow;
1787 arguments.columnGap = options.columnGap;
1788 arguments.rowGap = options.rowGap;
1789 arguments.paddingLeft = options.padding.left;
1790 arguments.paddingTop = options.padding.top;
1791 arguments.paddingRight = options.padding.right;
1792 arguments.paddingBottom = options.padding.bottom;
1793 arguments.maxTracksPerAxis = options.maxTracksPerAxis;
1794 arguments.maxPlacements = options.maxPlacements;
1795 arguments.maxPlacementWork = options.maxPlacementWork;
1796 }
1797
1798 return std::move(*this);
1799 }
1800
1805 requires std::same_as<T, Grid>
1806 {
1807 if (state_) {
1808 layoutMetadata().presentation = presentation;
1809 }
1810
1811 return std::move(*this);
1812 }
1813
1817 Description &&columnSizes(const std::vector<AxisSize> &policies) &&
1818 requires std::same_as<T, Grid>
1819 {
1820 if (state_) {
1821 declarativeOptions();
1822 layoutMetadata().columnSizes = std::make_unique<std::vector<AxisSize>>(policies);
1823 }
1824
1825 return std::move(*this);
1826 }
1827
1832 Description &&rowSizes(const std::vector<AxisSize> &policies) &&
1833 requires std::same_as<T, Grid>
1834 {
1835 if (state_) {
1836 declarativeOptions();
1837 layoutMetadata().rowSizes = std::make_unique<std::vector<AxisSize>>(policies);
1838 }
1839
1840 return std::move(*this);
1841 }
1842
1846 Description &&scroll(std::shared_ptr<ScrollController> controller = {}) &&
1847 requires std::same_as<T, Grid>
1848 {
1849 if (state_) {
1850 declarativeOptions();
1851 auto &layout = layoutMetadata();
1852
1853 if (!layout.scroll) {
1854 layout.scroll.emplace();
1855 }
1856
1857 if (controller) {
1858 layout.scroll->controller = std::move(controller);
1859 }
1860
1861 gridControl().arguments.grid.scroll = true;
1862 }
1863
1864 return std::move(*this);
1865 }
1866
1871 requires std::same_as<T, Grid>
1872 {
1873 if (state_) {
1874 declarativeOptions();
1875 auto &layout = layoutMetadata();
1876
1877 if (!layout.scroll) {
1878 layout.scroll.emplace();
1879 }
1880
1881 layout.scroll->area = options;
1882 gridControl().arguments.grid.scroll = true;
1883 }
1884
1885 return std::move(*this);
1886 }
1887
1892 if (state_) {
1893 layoutMetadata().item = options;
1894 state_->layout->itemRequested = true;
1895 }
1896
1897 return std::move(*this);
1898 }
1899
1903 Description &&row(std::size_t index) && {
1904 if (state_) {
1905 layoutMetadata().item.row = index;
1906 state_->layout->itemRequested = true;
1907 }
1908
1909 return std::move(*this);
1910 }
1911
1915 Description &&column(std::size_t index) && {
1916 if (state_) {
1917 layoutMetadata().item.column = index;
1918 state_->layout->itemRequested = true;
1919 }
1920
1921 return std::move(*this);
1922 }
1923
1927 Description &&rowSpan(std::size_t count) && {
1928 if (state_) {
1929 layoutMetadata().item.rowSpan = count;
1930 state_->layout->itemRequested = true;
1931 }
1932
1933 return std::move(*this);
1934 }
1935
1939 Description &&columnSpan(std::size_t count) && {
1940 if (state_) {
1941 layoutMetadata().item.columnSpan = count;
1942 state_->layout->itemRequested = true;
1943 }
1944
1945 return std::move(*this);
1946 }
1947
1952 Description &&flexX(std::uint32_t weight = 1) &&
1953 requires std::derived_from<T, SizedWidget>
1954 {
1955 return std::move(*this).resize({detail::SizeDimension::FLEX_X, 0, weight});
1956 }
1957
1962 Description &&flexY(std::uint32_t weight = 1) &&
1963 requires std::derived_from<T, SizedWidget>
1964 {
1965 return std::move(*this).resize({detail::SizeDimension::FLEX_Y, 0, weight});
1966 }
1967
1971 Description &&flex(std::uint32_t weight = 1) &&
1972 requires std::derived_from<T, SizedWidget>
1973 {
1974 return std::move(*this).resize({detail::SizeDimension::FLEX, 0, weight});
1975 }
1976
1981 Description &&setup(Setup<T> callback) && {
1982 if (state_) {
1983 state_->setup.push_back(std::move(callback));
1984 }
1985
1986 return std::move(*this);
1987 }
1988
1993 if (state_) {
1994 state_->focusScope = true;
1995 }
1996
1997 return std::move(*this);
1998 }
1999
2005 if (state_) {
2006 state_->focusDefault = true;
2007 }
2008
2009 return std::move(*this);
2010 }
2011
2012private:
2013 friend struct detail::Access;
2014 friend struct detail::ResourceAccess;
2015 template <detail::DescriptionInput Child> friend Description<Border> border(Child &&, BorderOptions, ControlStyle);
2016
2017 Description &&scalarSettings(ControlSettings patch) && {
2018 if (state_) {
2019 detail::applyFluentControlOrigins(patch, state_->controlPatch);
2020 state_->controlPatch = detail::Access::mergeControlSettings(std::move(state_->controlPatch), patch);
2021 state_->settingsRequested = true;
2022 }
2023
2024 return std::move(*this);
2025 }
2026
2027 template <detail::DescriptionInput Child>
2028 friend Description<ScrollArea> scrollArea(Child &&, ScrollAreaOptions, std::shared_ptr<ScrollController>,
2029 ControlStyle);
2030
2031 template <class U, class... Args> friend Description<U> custom(Args &&...args);
2032 template <class U> friend Description<U> control(std::string_view, ControlStyle, SizePolicy);
2033 template <class U, detail::DescriptionInput... Children> friend Description<U> linear(LinearOptions, Children &&...);
2034 template <class U, detail::DescriptionRange R> friend Description<U> linear(LinearOptions, R &&);
2035 template <detail::DescriptionInput... Children>
2036 friend Description<Overlay> overlay(OverlayOptions, SizePolicy, Children &&...);
2037 template <detail::GridInput... Children> friend Description<Grid> grid(Children &&...);
2038 friend Description<LineEdit> lineEdit(ManagedState<std::string>, LineEditConfig);
2039
2040 using State = detail::RecipeState<T>;
2041 using Factory = typename State::Factory;
2042 using Child = typename State::Child;
2043 using FrameRecipe = typename State::FrameRecipe;
2044
2050 // Reject unrelated by-value conversions before checked-result constructor probes recurse.
2051 template <class Create>
2052 requires std::invocable<Create &, ManagedScene &, Node<Widget> &>
2053 explicit Description(Create create) : state_(std::make_unique<State>()) {
2054 state_->create = [create = std::move(create)](ManagedScene &scene, Node<Widget> parent,
2055 detail::MountContext &) mutable {
2056 return create(scene, parent);
2057 };
2058 }
2059
2060 detail::RecipeLayout &layoutMetadata() {
2061 if (!state_->layout) {
2062 state_->layout = std::make_shared<detail::RecipeLayout>();
2063 }
2064
2065 return *state_->layout;
2066 }
2067
2068 detail::GridRecipeControl &gridControl()
2069 requires std::same_as<T, Grid>
2070 {
2071 auto &layout = layoutMetadata();
2072
2073 if (!layout.control) {
2074 layout.control = std::make_unique<detail::GridRecipeControl>();
2075 }
2076
2077 return *layout.control;
2078 }
2079
2080 DeclarativeGridOptions &declarativeOptions()
2081 requires std::same_as<T, Grid>
2082 {
2083 auto &layout = layoutMetadata();
2084
2085 if (!layout.grid) {
2086 layout.grid.emplace();
2087 }
2088
2089 layout.hasDeclaredGrid = true;
2090
2091 return *layout.grid;
2092 }
2093
2097 Description &&resize(detail::SizeChange change) &&
2098 requires std::derived_from<T, SizedWidget>
2099 {
2100 auto *state = state_.get();
2101
2102 if (state && state->sizing) {
2103 state->sizing->stage(change, false);
2104 }
2105
2106 // The callback lives in this State and runs synchronously before mountInto releases it.
2107 // It must never be exported to publish/finalize/runtime callbacks.
2108 return std::move(*this).setup([change, state](ManagedScene &scene, Node<T> node) {
2109 const Node<SizedWidget> target = state && state->frame && state->frame->mounted != Node<Border>{}
2110 ? Node<SizedWidget>(state->frame->mounted)
2111 : Node<SizedWidget>(node);
2112
2113 return detail::Access::resize(scene, target, change);
2114 });
2115 }
2116
2118 Description &&constrainSize(detail::SizeChange change) &&
2119 requires std::derived_from<T, SizedWidget>
2120 {
2121 if (state_) {
2122 if (!state_->sizing) {
2123 state_->sizing = std::make_unique<detail::RecipeSizing>();
2124 }
2125
2126 state_->sizing->stage(change, true);
2127 }
2128
2129 return std::move(*this);
2130 }
2131
2133 FrameRecipe &frameRecipe() {
2134 if (!state_->frame) {
2135 state_->frame = std::make_unique<FrameRecipe>();
2136 }
2137
2138 return *state_->frame;
2139 }
2140
2146 Description &&storeReference(NodeRef<T> reference) && {
2147 if (state_) {
2148 state_->references.push_back(std::move(reference));
2149 }
2150
2151 return std::move(*this);
2152 }
2153
2157 static std::expected<void, ManagedError> prepareSemanticControl(State &state, Node<Widget> parent) {
2158 const auto kind = state.semanticConstruction ? state.semanticConstruction->kind : detail::ControlFactoryKind::USER;
2159
2160 if ((state.messageSettingsRequested && kind != detail::ControlFactoryKind::MESSAGE_BINDING) ||
2161 (state.notificationSettingsRequested && kind != detail::ControlFactoryKind::NOTIFICATION_BINDING) ||
2162 (state.themeSelectorSettingsRequested && kind != detail::ControlFactoryKind::THEME_SELECTOR_BINDING &&
2163 kind != detail::ControlFactoryKind::THEME_CATALOG_BINDING) ||
2164 (state.themeCatalogSettingsRequested && kind != detail::ControlFactoryKind::THEME_CATALOG_BINDING)) {
2165 return std::unexpected(detail::controlContextError({ControlContextErrorCode::UNSUPPORTED_PROPERTY, {}}, parent));
2166 }
2167
2168 if (state.semanticConstruction && state.semanticConstruction->prepared) {
2169 const auto &source = state.semanticConstruction->source;
2170 auto merged = detail::Access::mergeControlSettings(state.controlPatch, source);
2171
2172 // Resource packets come from ControlContext::resolve, whose origins contain exactly
2173 // the present winning leaves. Keep factory provenance for every other retained value.
2174 merged.origin = state.controlPatch.origin;
2175 merged.origins = state.controlPatch.origins;
2176
2177 for (const auto &origin : source.origins) {
2178 auto found = std::ranges::find(merged.origins, origin.path, &ControlPropertyOrigin::path);
2179
2180 if (found == merged.origins.end()) {
2181 merged.origins.push_back(origin);
2182 } else {
2183 found->source = origin.source;
2184 }
2185 }
2186
2187 state.controlPatch = std::move(merged);
2188 state.controlPrepared = true;
2189 state.materializedSettings = state.semanticConstruction->materialized;
2190 state.settingsRequested = true;
2191 }
2192
2193 return {};
2194 }
2195
2197 static std::expected<void, ControlContextError> installControlSchema(const State &state, ControlContext &controls) {
2198 if constexpr (std::same_as<T, Border> || std::same_as<T, Gauge> || std::same_as<T, Spinner>) {
2199 return detail::ControlContextAccess::installPrimitiveSchema(controls, *state.controlType);
2200 } else if constexpr (std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar> || std::same_as<T, LogView> ||
2201 std::same_as<T, DocumentView>) {
2202 return detail::ControlContextAccess::installScrollSchema(controls, *state.controlType);
2203 } else if constexpr (std::same_as<T, DataStateView>) {
2204 return detail::ControlContextAccess::installDataStateSchema(controls);
2205 } else if constexpr (std::same_as<T, OverlayHost> || std::same_as<T, Dialog>) {
2206 if (!state.semanticConstruction) {
2207 return detail::ControlContextAccess::installDialogSchema(controls, *state.controlType);
2208 }
2209
2210 if (state.semanticConstruction->kind == detail::ControlFactoryKind::THEME_CATALOG_BINDING) {
2211 return detail::ControlContextAccess::installThemeCatalogSchema(controls, true);
2212 }
2213
2214 if (state.semanticConstruction->kind == detail::ControlFactoryKind::THEME_SELECTOR_BINDING) {
2215 return detail::ControlContextAccess::installThemeSelectorSchema(controls);
2216 }
2217
2218 return detail::ControlContextAccess::installMessageSchema(controls);
2219 } else if constexpr (std::same_as<T, Overlay>) {
2220 return state.semanticConstruction ? detail::ControlContextAccess::installNotificationSchema(controls)
2221 : detail::ControlContextAccess::installOverlaySchema(controls);
2222 } else if constexpr (std::same_as<T, HelpView> || std::same_as<T, KeyHints>) {
2223 return detail::ControlContextAccess::installKeyHelpSchema(controls, *state.controlType);
2224 } else if constexpr (detail::IsVirtualList<T>::value || detail::IsVirtualTable<T>::value ||
2225 detail::IsChart<T>::value) {
2226 return detail::ControlContextAccess::installVirtualViewSchema(controls, *state.controlType);
2227 } else {
2228 return {};
2229 }
2230 }
2231
2233 static bool matchesControlFactory(const State &state, const ResolvedControl &effective) {
2234 if constexpr (std::same_as<T, Border> || std::same_as<T, Gauge> || std::same_as<T, Spinner>) {
2235 return effective.factoryKind == detail::ControlFactoryKind::PRIMITIVE_FALLBACK;
2236 } else if constexpr (std::same_as<T, ScrollArea> || std::same_as<T, ScrollBar> || std::same_as<T, LogView> ||
2237 std::same_as<T, DocumentView>) {
2238 return effective.factoryKind == detail::ControlFactoryKind::SCROLL_FALLBACK;
2239 } else if constexpr (std::same_as<T, DataStateView>) {
2240 return effective.factoryKind == detail::ControlFactoryKind::DATA_STATE_FALLBACK;
2241 } else if constexpr (std::same_as<T, OverlayHost> || std::same_as<T, Dialog>) {
2242 const auto expectedKind =
2243 state.semanticConstruction ? state.semanticConstruction->kind : detail::ControlFactoryKind::DIALOG_FALLBACK;
2244
2245 return effective.factoryKind == expectedKind;
2246 } else if constexpr (std::same_as<T, Overlay>) {
2247 const auto expectedKind = state.semanticConstruction ? detail::ControlFactoryKind::NOTIFICATION_BINDING
2248 : detail::ControlFactoryKind::OVERLAY_FALLBACK;
2249
2250 return effective.factoryKind == expectedKind;
2251 } else if constexpr (std::same_as<T, HelpView> || std::same_as<T, KeyHints>) {
2252 return effective.factoryKind == detail::ControlFactoryKind::KEY_HELP_FALLBACK;
2253 } else if constexpr (detail::IsVirtualList<T>::value || detail::IsVirtualTable<T>::value ||
2254 detail::IsChart<T>::value) {
2255 return effective.factoryKind == detail::ControlFactoryKind::VIRTUAL_VIEW_FALLBACK;
2256 } else {
2257 return true;
2258 }
2259 }
2260
2262 static std::expected<void, ManagedError> validateControlIdentity(const State &state, ResolvedControl &effective,
2263 const ControlContext &controls, Node<Widget> parent,
2264 bool restoreVariant) {
2265 if (restoreVariant && state.controlVariant) {
2266 const auto identity = controls.resolve(*state.controlVariant);
2267
2268 if (!identity) {
2269 return std::unexpected(detail::controlContextError(identity.error(), parent));
2270 }
2271
2272 effective.type = identity->type;
2273 effective.base = identity->base;
2274 effective.lineage = identity->lineage;
2275 }
2276
2277 if (effective.base != *state.controlType) {
2278 return std::unexpected(detail::controlContextError({ControlContextErrorCode::INVALID_VALUE, {}}, parent));
2279 }
2280
2281 if (!matchesControlFactory(state, effective)) {
2282 return std::unexpected(detail::controlContextError({ControlContextErrorCode::INVALID_VALUE, {}}, parent));
2283 }
2284
2285 return {};
2286 }
2287
2291 static std::expected<void, ManagedError>
2292 retainControlSettings(State &state, ResolvedControl &effective,
2293 const std::optional<ResolvedControl> &notificationStyle, Node<Widget> parent,
2294 detail::MountContext &context) {
2295 const auto addedLeaves =
2296 state.controlPrepared
2297 ? (detail::controlSettingsPresenceSet(effective.settings) & ~state.materializedSettings).count()
2298 : effective.materializedLeaves;
2299 const auto limit = context.controls.limits().maxMaterializedLeaves;
2300
2301 if (context.controlLeaves > limit || addedLeaves > limit - context.controlLeaves) {
2302 return std::unexpected(
2303 detail::controlContextError({ControlContextErrorCode::MATERIALIZED_LEAF_LIMIT, {}}, parent));
2304 }
2305
2306 context.controlLeaves += addedLeaves;
2307
2308 if (state.controlVariant) {
2309 const auto &identity = notificationStyle ? *notificationStyle : effective;
2310
2311 state.intrinsicStyle = StyleTarget{.type = identity.type,
2312 .control = std::same_as<T, RadioGroup> || std::derived_from<T, Control> ||
2313 std::same_as<T, LineEdit> || std::same_as<T, Password>,
2314 .baseTypes = identity.lineage};
2315
2316 if constexpr (std::same_as<T, Row> || std::same_as<T, Column>) {
2317 constexpr std::string_view NATURAL = std::same_as<T, Row> ? "Row" : "Column";
2318
2319 if (state.intrinsicStyle->type != NATURAL &&
2320 std::ranges::find(state.intrinsicStyle->baseTypes, NATURAL) == state.intrinsicStyle->baseTypes.end()) {
2321 state.intrinsicStyle->baseTypes.emplace_back(NATURAL);
2322 }
2323 }
2324 }
2325
2326 state.resolvedControl = std::make_unique<ResolvedControl>(std::move(effective));
2327
2328 return {};
2329 }
2330
2332 static std::expected<void, ManagedError> prepareControlSettings(State &state, Node<Widget> parent,
2333 detail::MountContext &context) {
2334 std::optional<ResolvedControl> notificationStyle;
2335
2336 if constexpr (std::same_as<T, Overlay>) {
2337 if (state.semanticConstruction && state.controlVariant &&
2338 state.semanticConstruction->kind == detail::ControlFactoryKind::NOTIFICATION_BINDING) {
2339 auto identity = context.controls.resolve(*state.controlVariant);
2340
2341 if (!identity) {
2342 return std::unexpected(detail::controlContextError(identity.error(), parent));
2343 }
2344
2345 if (identity->base == "Overlay" && identity->factoryKind == detail::ControlFactoryKind::OVERLAY_FALLBACK) {
2346 // Existing Overlay variants on notifications are visual identities, never inherited service/layout
2347 // defaults.
2348 notificationStyle.emplace(std::move(*identity));
2349 }
2350 }
2351 }
2352
2353 const bool inheritControlSettings = state.inheritControlSettings && !notificationStyle;
2354 auto controls =
2355 !inheritControlSettings || (state.controlPrepared && !state.controlVariant && !state.inheritPreparedDefaults)
2356 ? ControlContext(context.controls.limits())
2357 : context.controls;
2358 auto installed = installControlSchema(state, controls);
2359
2360 if (!installed) {
2361 return std::unexpected(detail::controlContextError(installed.error(), parent));
2362 }
2363
2364 const auto type = inheritControlSettings && state.controlVariant ? std::string_view(*state.controlVariant)
2365 : std::string_view(*state.controlType);
2366 const auto numericCandidates = [&] {
2367 if constexpr ((std::derived_from<T, Slider> || std::same_as<T, SpinBox>)) {
2368 return std::array{state.controlPatch.value ? state.controlPatch.value : state.controlArguments.value,
2369 state.controlPatch.minimum ? state.controlPatch.minimum : state.controlArguments.minimum,
2370 state.controlPatch.maximum ? state.controlPatch.maximum : state.controlArguments.maximum,
2371 state.controlPatch.step ? state.controlPatch.step : state.controlArguments.step};
2372 } else {
2373 return std::array<std::optional<double>, 0>{};
2374 }
2375 }();
2376 auto effective = inheritControlSettings
2377 ? controls.resolve(type, detail::Access::mergeControlSettings(std::move(state.controlArguments),
2378 state.controlPatch))
2379 : controls.resolve(type, state.controlPatch);
2380
2381 if (!effective) {
2382 auto failure = detail::controlContextError(effective.error(), parent);
2383
2384 if constexpr ((std::derived_from<T, Slider> || std::same_as<T, SpinBox>)) {
2385 const auto &original = effective.error();
2386
2387 if (original.code == ControlContextErrorCode::INVALID_VALUE && original.diagnostic) {
2388 constexpr std::array<std::string_view, 4> LEAVES{".value", ".minimum", ".maximum", ".step"};
2389
2390 for (std::size_t index = 0; index < LEAVES.size(); ++index) {
2391 const auto candidate = numericCandidates[index];
2392
2393 if (candidate && original.diagnostic->path.ends_with(LEAVES[index])) {
2394 if (!std::isfinite(*candidate)) {
2395 failure.numeric = NumericError::NOT_FINITE;
2396 } else if (LEAVES[index] == ".step" && *candidate <= 0) {
2397 failure.numeric = NumericError::INVALID_STEP;
2398 }
2399 }
2400 }
2401 }
2402 }
2403
2404 return std::unexpected(std::move(failure));
2405 }
2406
2407 auto validated = validateControlIdentity(state, *effective, context.controls, parent,
2408 !inheritControlSettings && !notificationStyle);
2409
2410 if (!validated) {
2411 return validated;
2412 }
2413
2414 return retainControlSettings(state, *effective, notificationStyle, parent, context);
2415 }
2416
2423 static std::expected<void, ManagedError> prepareControl(State &state, Node<Widget> parent,
2424 detail::MountContext &context) {
2425 if constexpr (std::same_as<T, Dialog> || std::same_as<T, Overlay>) {
2426 auto prepared = prepareSemanticControl(state, parent);
2427
2428 if (!prepared) {
2429 return prepared;
2430 }
2431 }
2432
2433 if constexpr (std::same_as<T, Grid>) {
2434 if (state.layout && state.layout->gridContainer && state.layout->control && state.layout->control->prepared) {
2435 state.resolvedControl = std::move(state.layout->control->resolved);
2436
2437 if (state.controlVariant && state.resolvedControl) {
2438 state.intrinsicStyle =
2439 StyleTarget{.type = state.resolvedControl->type, .baseTypes = state.resolvedControl->lineage};
2440 }
2441
2442 return {};
2443 }
2444 }
2445
2446 if ((state.settingsRequested || state.controlVariant) && !state.controlType) {
2447 return std::unexpected(detail::controlContextError({ControlContextErrorCode::UNSUPPORTED_PROPERTY, {}}, parent));
2448 }
2449
2450 const bool builtinOnly = context.controls.empty() && !state.settingsRequested && !state.controlVariant;
2451
2452 if (state.controlType && (!state.controlPrepared || state.settingsRequested || state.controlVariant) &&
2453 !builtinOnly) {
2454 return prepareControlSettings(state, parent, context);
2455 }
2456
2457 return {};
2458 }
2459
2469 std::expected<Node<T>, ManagedError> mountInto(ManagedScene &scene, Node<Widget> parent,
2470 detail::MountContext &context) && {
2471 auto state = std::move(state_);
2472
2473 if (!state) {
2474 return std::unexpected(detail::error(parent, TreeError::INVALID_ARGUMENT));
2475 }
2476
2477 if (state->prerequisiteFailure) {
2478 auto admitted = detail::Access::check(scene, parent);
2479
2480 if (!admitted) {
2481 return std::unexpected(admitted.error());
2482 }
2483
2484 return std::unexpected(*state->prerequisiteFailure);
2485 }
2486
2487 if (!state->create) {
2488 return std::unexpected(detail::error(parent, TreeError::INVALID_ARGUMENT));
2489 }
2490
2491 auto gridPrepared = detail::prepareGridLayouts(state->layout, context, parent);
2492
2493 if (!gridPrepared) {
2494 return std::unexpected(gridPrepared.error());
2495 }
2496
2497 auto layoutChecked = detail::preflightLayout(state->layout);
2498
2499 if (!layoutChecked) {
2500 return std::unexpected(detail::error(parent, layoutChecked.error()));
2501 }
2502
2503 auto prepared = prepareControl(*state, parent, context);
2504 if (!prepared) {
2505 return std::unexpected(prepared.error());
2506 }
2507 const auto *resolved = state->resolvedControl.get();
2508
2509 auto mountParent = parent;
2510
2511 if constexpr (std::derived_from<T, SizedWidget> && !std::derived_from<T, ScrollArea>) {
2512 const auto &settings = resolved ? resolved->settings : state->controlArguments;
2513 const bool configuredFrame = detail::hasFrameSettings(settings.frame);
2514
2515 if (state->frame || configuredFrame) {
2516 if (state->frame && state->frame->invalidPattern) {
2517 return std::unexpected(
2518 detail::frameContextError(ControlContextErrorCode::INVALID_VALUE, "frame.pattern", parent));
2519 }
2520
2521 auto effective = detail::controlFrameOptions(
2522 settings, state->frame && state->frame->hasOptions ? std::optional(state->frame->options) : std::nullopt,
2523 scene.widthPolicy());
2524
2525 if (!effective) {
2526 return std::unexpected(effective.error());
2527 }
2528
2529 if (state->frame && state->frame->source) {
2530 effective = detail::controlFrameOptions(*state->frame->source, std::move(*effective), scene.widthPolicy());
2531
2532 if (!effective) {
2533 return std::unexpected(effective.error());
2534 }
2535 }
2536
2537 if (*effective) {
2538 if (!state->frame) {
2539 state->frame = std::make_unique<FrameRecipe>();
2540 }
2541
2542 state->frame->options = std::move(**effective);
2543 state->frame->hasOptions = true;
2544 } else {
2545 state->frame.reset();
2546 }
2547 }
2548 }
2549
2550 if (state->frame) {
2551 if (state->frame->invalidPattern) {
2552 return std::unexpected(
2553 detail::frameContextError(ControlContextErrorCode::INVALID_VALUE, "frame.pattern", parent));
2554 }
2555
2556 const auto valid = Border::validateFrame(state->frame->options);
2557
2558 if (!valid) {
2559 return std::unexpected(detail::error(parent, valid.error()));
2560 }
2561
2562 if constexpr (std::derived_from<T, ScrollArea>) {
2563 // Only the native factory consumes constructor-scoped advanced frame settings.
2564 if (!state->controlType || (*state->controlType != "ScrollArea" && *state->controlType != "LogView" &&
2565 *state->controlType != "DocumentView")) {
2566 return std::unexpected(detail::error(parent, TreeError::INVALID_ARGUMENT));
2567 }
2568 } else {
2569 auto frame = detail::Access::framedControl(std::move(state->frame->options), {});
2570
2571 if (state->frame->reference) {
2572 (void)std::move(frame).reference(*state->frame->reference);
2573 }
2574
2575 auto mounted = detail::Access::mount(std::move(frame), scene, parent, context);
2576
2577 if (!mounted) {
2578 return std::unexpected(mounted.error());
2579 }
2580
2581 state->frame->mounted = *mounted;
2582 mountParent = *mounted;
2583 if (state->frame->titleBinding) {
2584 auto bound = state->frame->titleBinding(scene, *mounted, context);
2585 if (!bound) {
2586 return std::unexpected(bound.error());
2587 }
2588 }
2589 }
2590 }
2591
2592 context.mountedOuter = {};
2593
2594 auto node = [&] {
2595 struct Restore {
2596 detail::MountContext &context;
2597 bool previous;
2598 const ControlSettings *settings;
2599 const FrameOptions *frame;
2600 const ControlSettings *frameSettings;
2601 Description<Widget> *body;
2602 ~Restore() {
2603 context.controlPrepared = previous;
2604 context.controlSettings = settings;
2605 context.frameOptions = frame;
2606 context.frameSettings = frameSettings;
2607 context.messageBody = body;
2608 }
2609 } restore{context,
2610 context.controlPrepared,
2611 context.controlSettings,
2612 context.frameOptions,
2613 context.frameSettings,
2614 context.messageBody};
2615
2616 context.controlPrepared = state->controlPrepared;
2617 context.controlSettings = resolved ? &resolved->settings : &state->controlArguments;
2618 context.frameOptions =
2619 std::derived_from<T, ScrollArea> && state->frame && state->frame->hasOptions ? &state->frame->options : nullptr;
2620 context.frameSettings = std::derived_from<T, ScrollArea> && state->frame ? state->frame->source.get() : nullptr;
2621
2622 context.messageBody = state->semanticConstruction ? state->semanticConstruction->body.get() : nullptr;
2623
2624 return state->create(scene, mountParent, context);
2625 }();
2626
2627 if (!node) {
2628 return node;
2629 }
2630
2631 const Node<Widget> outer = state->frame && state->frame->mounted != Node<Border>{}
2632 ? Node<Widget>(state->frame->mounted)
2633 : state->forwardsOuter && context.mountedOuter != Node<Widget>{} ? context.mountedOuter
2634 : Node<Widget>(*node);
2635
2636 if (context.root == Node<Widget>{}) {
2637 context.root = *node;
2638 }
2639
2640 context.nodes.push_back(*node);
2641
2642 if (state->visible || state->enabled) {
2643 auto configured = detail::Access::instanceState(scene, outer, state->visible, state->enabled);
2644
2645 if (!configured) {
2646 return std::unexpected(configured.error());
2647 }
2648 }
2649
2650 if (state->intrinsicStyle) {
2651 auto styled = [&] {
2652 if constexpr (std::same_as<T, Dialog> || std::same_as<T, OverlayHost>) {
2653 // These managed factories already supplied their native structural classes.
2654 return detail::Access::finalizeStyleIdentity(scene, *node, *state->intrinsicStyle);
2655 } else if constexpr (std::same_as<T, Overlay>) {
2656 return state->semanticConstruction
2657 ? detail::Access::finalizeStyleIdentity(scene, *node, *state->intrinsicStyle)
2658 : scene.style(*node, *state->intrinsicStyle);
2659 } else {
2660 return scene.style(*node, *state->intrinsicStyle);
2661 }
2662 }();
2663
2664 if (!styled) {
2665 return std::unexpected(styled.error());
2666 }
2667 }
2668
2669 if (state->controlSetup) {
2670 auto configured = state->controlSetup(scene, *node, resolved ? resolved->settings : state->controlArguments);
2671 if (!configured) {
2672 return std::unexpected(configured.error());
2673 }
2674 }
2675
2676 if constexpr (std::derived_from<T, SizedWidget>) {
2677 if (resolved) {
2678 const auto &settings = resolved->settings;
2679 const auto *sourceSizing =
2680 state->semanticConstruction && state->semanticConstruction->prepared &&
2681 state->semanticConstruction->kind == detail::ControlFactoryKind::NOTIFICATION_BINDING
2682 ? &state->semanticConstruction->source
2683 : nullptr;
2684
2685 const auto sizing = detail::controlSizing(settings, sourceSizing);
2686 const Node<SizedWidget> target = state->frame && state->frame->mounted != Node<Border>{}
2687 ? Node<SizedWidget>(state->frame->mounted)
2688 : Node<SizedWidget>(*node);
2689 auto resized = detail::Access::finishSizing(scene, target, target, &sizing);
2690
2691 if (!resized) {
2692 return std::unexpected(resized.error());
2693 }
2694 }
2695 }
2696
2697 Node<LineEdit> fieldDraft;
2698
2699 if constexpr (std::same_as<T, FormField> || std::same_as<T, FindBar> || std::same_as<T, SpinBox> ||
2700 std::derived_from<T, ComboBox>) {
2701 auto editor = detail::NamedAccess::fieldDraft(scene, *node);
2702
2703 if (!editor) {
2704 return std::unexpected(editor.error());
2705 }
2706
2707 fieldDraft = *editor;
2708 }
2709
2710 for (auto &reference : state->references) {
2711 auto slot = reference.slot_;
2712
2713 if (slot && slot->fluent && slot->target.owner != std::this_thread::get_id()) {
2714 return std::unexpected(detail::error(*node, TreeError::WRONG_THREAD));
2715 }
2716
2717 if (!slot || slot->node != Node<T>{} || slot->pending) {
2718 return std::unexpected(detail::error(*node, TreeError::INVALID_ARGUMENT));
2719 }
2720
2721 // Reserve across reentrant mount calls too, but never publish a partial identity.
2722 // Allocate both callbacks before setting pending so exceptions cannot strand the slot.
2723 context.release.push_back([slot] {
2724 slot->pending = false;
2725 });
2726 context.publish.push_back(
2727 [slot, value = *node, owner = &scene, lifetime = detail::Access::lifetime(scene), fieldDraft] {
2728 slot->node = value;
2729 slot->target.node = value;
2730 slot->target.scene = owner;
2731 slot->target.lifetime = lifetime;
2732
2733 if constexpr (std::derived_from<T, Control>) {
2734 slot->target.caption = value;
2735 } else if constexpr (std::same_as<T, LineEdit>) {
2736 slot->target.draft = value;
2737 } else if constexpr (std::same_as<T, FormField> || std::same_as<T, FindBar> || std::same_as<T, SpinBox> ||
2738 std::derived_from<T, ComboBox>) {
2739 slot->target.draft = fieldDraft;
2740 } else if constexpr (std::same_as<T, Password>) {
2741 slot->target.secret = value;
2742 }
2743 });
2744 detail::RefTarget pending;
2745 pending.node = *node;
2746 pending.scene = &scene;
2747 pending.lifetime = detail::Access::lifetime(scene);
2748 if constexpr (std::derived_from<T, Control>) {
2749 pending.caption = *node;
2750 } else if constexpr (std::same_as<T, LineEdit>) {
2751 pending.draft = *node;
2752 } else if constexpr (std::same_as<T, FormField> || std::same_as<T, FindBar> || std::same_as<T, SpinBox> ||
2753 std::derived_from<T, ComboBox>) {
2754 pending.draft = fieldDraft;
2755 } else if constexpr (std::same_as<T, Password>) {
2756 pending.secret = *node;
2757 }
2758 context.pending.push_back({&slot->target, std::move(pending)});
2759 slot->pending = true;
2760 }
2761
2762 if (state->focusScope) {
2763 auto registered = scene.focusScope(*node);
2764
2765 if (!registered) {
2766 return std::unexpected(registered.error());
2767 }
2768 }
2769
2770 if (state->focusDefault) {
2771 auto configured = scene.focusDefault(*node);
2772
2773 if (!configured) {
2774 return std::unexpected(configured.error());
2775 }
2776 }
2777
2778 for (auto &setup : state->setup) {
2779 if (!setup) {
2780 return std::unexpected(detail::error(*node, TreeError::INVALID_ARGUMENT));
2781 }
2782
2783 auto configured = setup(scene, *node);
2784
2785 if (!configured) {
2786 return std::unexpected(configured.error());
2787 }
2788 }
2789
2790 if constexpr (std::same_as<T, Overlay>) {
2791 if (state->semanticConstruction && state->semanticConstruction->prepared &&
2792 state->semanticConstruction->kind == detail::ControlFactoryKind::NOTIFICATION_BINDING) {
2793 // Resource common sizing follows factory setup, including through erased native recipes.
2794 const auto &source = state->semanticConstruction->source;
2795
2796 const auto sizing = detail::controlSizing(source);
2797 auto resized = detail::Access::finishSizing(scene, *node, *node, &sizing);
2798
2799 if (!resized) {
2800 return std::unexpected(resized.error());
2801 }
2802
2803 if (state->sizing) {
2804 state->sizing->overlay(sizing);
2805 }
2806 }
2807 }
2808
2809 if constexpr (std::derived_from<T, SizedWidget>) {
2810 if (state->sizing || (state->frame && state->frame->mounted != Node<Border>{})) {
2811 const auto target = state->frame && state->frame->mounted != Node<Border>{}
2812 ? Node<SizedWidget>(state->frame->mounted)
2813 : Node<SizedWidget>(*node);
2814 auto sized = detail::Access::finishSizing(scene, *node, target, state->sizing.get());
2815
2816 if (!sized) {
2817 return std::unexpected(sized.error());
2818 }
2819 }
2820 }
2821
2822 if (state->intrinsicStyle) {
2823 auto styled = detail::Access::finalizeStyleIdentity(scene, *node, *state->intrinsicStyle);
2824
2825 if (!styled) {
2826 return std::unexpected(styled.error());
2827 }
2828 }
2829
2830 for (auto &child : state->children) {
2831 auto mounted = child(scene, *node, context);
2832
2833 if (!mounted) {
2834 return std::unexpected(mounted.error());
2835 }
2836 }
2837
2838 if constexpr (std::same_as<T, Grid>) {
2839 if (state->layout && state->layout->grid) {
2840 if (state->layout->mounted.size() != state->layout->children.size()) {
2841 return std::unexpected(detail::error(*node, TreeError::INVALID_ARGUMENT));
2842 }
2843
2844 auto configured = detail::Access::gridOptions(scene, *node, detail::resolvedGridOptions(*state->layout));
2845
2846 if (!configured) {
2847 return std::unexpected(configured.error());
2848 }
2849 }
2850 }
2851
2852 if constexpr (std::same_as<T, Dialog>) {
2853 if (state->anchorRequested) {
2854 context.finalize.push_back([&scene, &context, node = *node, target = state->anchor,
2855 placement = state->placement]() -> std::expected<void, ManagedError> {
2856 const auto *resolved = target.get();
2857 if (!resolved) {
2858 return std::unexpected(detail::error(node, TreeError::CLOSED));
2859 }
2860 for (const auto &pending : context.pending) {
2861 if (pending.identity == target.get()) {
2862 resolved = &pending.target;
2863 break;
2864 }
2865 }
2866 if (resolved->owner != std::this_thread::get_id()) {
2867 return std::unexpected(detail::error(node, TreeError::WRONG_THREAD));
2868 }
2869 if (resolved->failure) {
2870 return std::unexpected(*resolved->failure);
2871 }
2872 if (resolved->lifetime.expired()) {
2873 return std::unexpected(detail::error(node, TreeError::CLOSED));
2874 }
2875 return scene.dialogAnchor(node, resolved->node, placement);
2876 });
2877 }
2878 }
2879
2880 context.mountedOuter = outer;
2881
2882 return node;
2883 }
2884
2885 std::unique_ptr<State> state_;
2886};
2887
2890public:
2893 : region_(other.region_), sticky_(other.sticky_), valid_(other.valid_), style_(other.style_), rows_(other.rows_) {
2894 children_.swap(other.children_);
2895 other.valid_ = false;
2896 }
2897
2900 if (this == &other) {
2901 return *this;
2902 }
2903
2904 children_.swap(other.children_);
2905 region_ = other.region_;
2906 sticky_ = other.sticky_;
2907 valid_ = other.valid_;
2908 style_ = other.style_;
2909 rows_ = other.rows_;
2910 other.valid_ = false;
2911
2912 return *this;
2913 }
2914
2915 GridSection(const GridSection &) = delete;
2916 GridSection &operator=(const GridSection &) = delete;
2917
2921 GridSection &&sticky(bool value = true) && {
2922 sticky_ = value;
2923 valid_ = valid_ && region_ == GridRegion::HEADER;
2924
2925 return std::move(*this);
2926 }
2927
2932 style_ = value;
2933
2934 return std::move(*this);
2935 }
2936
2941 rows_ = value;
2942 valid_ = valid_ && region_ == GridRegion::BODY;
2943
2944 return std::move(*this);
2945 }
2946
2947private:
2948 friend struct detail::Access;
2949 template <detail::DescriptionInput... Children> friend GridSection header(Children &&...);
2950 template <detail::DescriptionInput... Children> friend GridSection body(Children &&...);
2951
2952 explicit GridSection(GridRegion region) : region_(region) {
2953 }
2954
2955 GridRegion region_;
2956 bool sticky_{};
2957 bool valid_{true};
2958 std::optional<CellStyle> style_;
2959 std::optional<GridRowStyles> rows_;
2960 std::vector<Description<Widget>> children_ = std::vector<Description<Widget>>(0);
2961};
2962
2963namespace detail {
2964inline std::expected<void, ManagedError> prepareGridLayouts(const std::shared_ptr<RecipeLayout> &root,
2965 MountContext &context, Node<Widget> parent) {
2966 if (!root || root->validated) {
2967 return {};
2968 }
2969
2970 std::vector<std::shared_ptr<RecipeLayout>> pending(0);
2971 std::size_t addedLeaves{};
2972 const auto limit = context.controls.limits().maxMaterializedLeaves;
2973
2974 pending.push_back(root);
2975
2976 while (!pending.empty()) {
2977 auto layout = std::move(pending.back());
2978
2979 pending.pop_back();
2980
2981 for (const auto &child : layout->children) {
2982 pending.push_back(child);
2983 }
2984
2985 if (!layout->gridContainer || !layout->grid) {
2986 continue;
2987 }
2988
2989 if (!layout->control) {
2990 layout->control = std::make_unique<GridRecipeControl>();
2991 }
2992
2993 auto &control = *layout->control;
2994
2995 if (control.prepared) {
2996 continue;
2997 }
2998
2999 auto identityControls = context.controls;
3000 auto installed = ControlContextAccess::installFallbackSchema(identityControls);
3001
3002 if (!installed) {
3003 return std::unexpected(controlContextError(installed.error(), parent));
3004 }
3005
3006 auto identity = identityControls.resolve(control.variant ? std::string_view(*control.variant) : "Grid");
3007
3008 if (!identity) {
3009 return std::unexpected(controlContextError(identity.error(), parent));
3010 }
3011
3012 if (identity->factoryKind != ControlFactoryKind::DECLARATIVE_GRID_FALLBACK) {
3013 return std::unexpected(controlContextError({ControlContextErrorCode::INVALID_VALUE, {}}, parent));
3014 }
3015
3016 if (control.materialized && !control.settingsRequested && !control.variant) {
3017 control.prepared = true;
3018
3019 continue;
3020 }
3021
3022 auto controls =
3023 control.materialized && !control.variant ? ControlContext(context.controls.limits()) : identityControls;
3024 installed = ControlContextAccess::installFallbackSchema(controls);
3025
3026 if (!installed) {
3027 return std::unexpected(controlContextError(installed.error(), parent));
3028 }
3029
3030 auto effective = controls.resolve(control.variant ? std::string_view(*control.variant) : "Grid",
3031 Access::mergeControlSettings(control.arguments, control.patch));
3032
3033 if (!effective) {
3034 return std::unexpected(controlContextError(effective.error(), parent));
3035 }
3036
3037 const auto leaves = control.materialized
3038 ? (controlSettingsPresenceSet(effective->settings) & ~control.materializedSettings).count()
3039 : effective->materializedLeaves;
3040
3041 if (context.controlLeaves > limit || addedLeaves > limit - context.controlLeaves ||
3042 leaves > limit - context.controlLeaves - addedLeaves) {
3043 return std::unexpected(controlContextError({ControlContextErrorCode::MATERIALIZED_LEAF_LIMIT, {}}, parent));
3044 }
3045
3046 addedLeaves += leaves;
3047
3048 const auto &grid = effective->settings.grid;
3049 auto &options = *layout->grid;
3050 const auto apply = [](auto &target, const auto &source) {
3051 if (source) {
3052 target = *source;
3053 }
3054 };
3055
3056 apply(options.columns, grid.columns);
3057 apply(options.rows, grid.rows);
3058 apply(options.flow, grid.flow);
3059 apply(options.columnGap, grid.columnGap);
3060 apply(options.rowGap, grid.rowGap);
3061 apply(options.padding.left, grid.paddingLeft);
3062 apply(options.padding.top, grid.paddingTop);
3063 apply(options.padding.right, grid.paddingRight);
3064 apply(options.padding.bottom, grid.paddingBottom);
3065 apply(options.maxTracksPerAxis, grid.maxTracksPerAxis);
3066 apply(options.maxPlacements, grid.maxPlacements);
3067 apply(options.maxPlacementWork, grid.maxPlacementWork);
3068
3069 if (grid.scroll) {
3070 if (*grid.scroll && !layout->scroll) {
3071 layout->scroll.emplace();
3072 } else if (!*grid.scroll) {
3073 layout->scroll.reset();
3074 }
3075 }
3076
3077 control.resolved = std::make_unique<ResolvedControl>(std::move(*effective));
3078 control.prepared = true;
3079 }
3080
3081 context.controlLeaves += addedLeaves;
3082
3083 return {};
3084}
3085
3086template <class T> bool Access::needsGridContext(const Description<T> &description) {
3087 return description.state_ && description.state_->layout && description.state_->layout->hasDeclaredGrid;
3088}
3089
3091template <class T> bool Access::needsChoiceHost(const Description<T> &description) {
3092 const auto *layout = description.state_ ? description.state_->layout.get() : nullptr;
3093
3094 return layout && layout->needsChoiceHost && !layout->hasOverlayHost;
3095}
3096
3097template <class T, class Probe> Description<T> Access::choiceProbe(Description<T> description, Probe probe) {
3098 description.layoutMetadata().choiceProbe = std::move(probe);
3099 return description;
3100}
3101
3102template <class T>
3103std::expected<bool, ManagedError> Access::prepareChoiceHost(Description<T> &description, ControlContext controls) {
3104 auto root = description.state_ ? description.state_->layout : nullptr;
3105 if (!root) {
3106 return false;
3107 }
3108 std::vector<std::shared_ptr<RecipeLayout>> pending(0);
3109 pending.push_back(root);
3110 bool needed = root->needsChoiceHost, hosted = root->hasOverlayHost;
3111 for (std::size_t index = 0; index < pending.size(); ++index) {
3112 const auto layout = pending[index];
3113 if (!layout) {
3114 continue;
3115 }
3116 needed = needed || layout->needsChoiceHost;
3117 hosted = hosted || layout->hasOverlayHost;
3118 if (layout->choiceProbe) {
3119 auto result = layout->choiceProbe(controls);
3120 if (!result) {
3121 return std::unexpected(result.error());
3122 }
3123 needed = needed || result->first;
3124 hosted = hosted || result->second;
3125 }
3126 pending.insert(pending.end(), layout->children.begin(), layout->children.end());
3127 }
3128 return needed && !hosted;
3129}
3130
3131template <class T> Description<T> Access::choiceHost(Description<T> description, bool explicitHost) {
3132 auto &layout = description.layoutMetadata();
3133 layout.needsChoiceHost = !explicitHost;
3134 layout.hasOverlayHost = explicitHost;
3135
3136 return description;
3137}
3138
3140
3142 if (description.state_) {
3143 description.state_->deferredControlValidation = true;
3144 }
3145
3146 return description;
3147}
3148
3149template <class T> bool Access::defersControlValidation(const Description<T> &description) {
3150 return description.state_ && description.state_->deferredControlValidation;
3151}
3152
3153template <class Child>
3154void Access::gridChild(Description<Grid> &parent, Child &&child, std::optional<GridRegion> region) {
3155 layoutChild(parent, child, true);
3156
3157 if (region && child.state_) {
3158 child.state_->layout->item.region = *region;
3159 }
3160
3161 auto layout = parent.state_->layout;
3162
3163 parent.state_->children.push_back(
3164 [layout, child = std::forward<Child>(child)](ManagedScene &scene, Node<Widget> owner,
3165 MountContext &context) mutable -> std::expected<void, ManagedError> {
3166 auto mounted = Access::mount(std::move(child), scene, owner, context);
3167
3168 if (!mounted) {
3169 return std::unexpected(mounted.error());
3170 }
3171
3172 if (layout->grid) {
3173 // A framed source keeps its typed Ref while the Grid places its direct Border child.
3174 layout->mounted.push_back(context.mountedOuter.id());
3175 }
3176
3177 return {};
3178 });
3179}
3180
3182 auto &layout = parent.layoutMetadata();
3183
3184 parent.declarativeOptions();
3185 layout.validSections = layout.validSections && section.valid_;
3186
3187 if (section.region_ == GridRegion::HEADER) {
3188 ++layout.headerSections;
3189 layout.stickyHeader = section.sticky_;
3190 layout.headerStyle = section.style_;
3191 } else {
3192 ++layout.bodySections;
3193 layout.bodyStyle = section.style_;
3194 layout.rowStyles = section.rows_;
3195 }
3196
3197 for (auto &child : section.children_) {
3198 gridChild(parent, std::move(child), section.region_);
3199 }
3200}
3201
3202template <class... Children> std::shared_ptr<RecipeLayout> Access::captureLayouts(Children &...children) {
3203 std::shared_ptr<RecipeLayout> layout;
3204 const auto append = [&](auto &child) {
3205 if (!child.state_ || child.state_->layout) {
3206 if (!layout) {
3207 layout = std::make_shared<RecipeLayout>();
3208 }
3209
3210 if (child.state_) {
3211 layout->children.push_back(child.state_->layout);
3212 layout->hasDeclaredGrid = layout->hasDeclaredGrid || child.state_->layout->hasDeclaredGrid;
3213 layout->needsChoiceHost = layout->needsChoiceHost || child.state_->layout->needsChoiceHost;
3214 layout->hasOverlayHost = layout->hasOverlayHost || child.state_->layout->hasOverlayHost;
3215 } else {
3216 auto empty = std::make_shared<RecipeLayout>();
3217
3218 empty->validRecipe = false;
3219 layout->children.push_back(std::move(empty));
3220 }
3221 }
3222 };
3223
3224 (append(children), ...);
3225
3226 return layout;
3227}
3228
3229template <class T> Description<T> Access::withLayout(Description<T> description, std::shared_ptr<RecipeLayout> layout) {
3230 if (description.state_) {
3231 description.state_->layout = std::move(layout);
3232 }
3233
3234 return description;
3235}
3236
3237template <class Parent, class Child>
3238void Access::layoutChild(Description<Parent> &parent, Description<Child> &child, bool structural) {
3239 if (!parent.state_) {
3240 return;
3241 }
3242
3243 if (!child.state_) {
3244 auto empty = std::make_shared<RecipeLayout>();
3245
3246 empty->validRecipe = false;
3247 parent.layoutMetadata().children.push_back(std::move(empty));
3248
3249 return;
3250 }
3251
3252 if (structural) {
3253 child.layoutMetadata();
3254 }
3255
3256 if (child.state_->layout) {
3257 parent.layoutMetadata().children.push_back(child.state_->layout);
3258 parent.state_->layout->hasDeclaredGrid =
3259 parent.state_->layout->hasDeclaredGrid || child.state_->layout->hasDeclaredGrid;
3260 parent.state_->layout->needsChoiceHost =
3261 parent.state_->layout->needsChoiceHost || child.state_->layout->needsChoiceHost;
3262 parent.state_->layout->hasOverlayHost =
3263 parent.state_->layout->hasOverlayHost || child.state_->layout->hasOverlayHost;
3264 }
3265}
3266
3267template <class T> void Access::preparedControl(Description<T> &description, std::uint32_t alreadyMaterialized) {
3268 preparedControlPresence(description, ControlPropertyPresence{alreadyMaterialized});
3269}
3270
3271template <class T> void Access::sizingSettings(Description<T> &description, const RecipeSizing &sizing) {
3272 if constexpr (std::derived_from<T, SizedWidget>) {
3273 if (!description.state_ || (!sizing.width && !sizing.height)) {
3274 return;
3275 }
3276
3277 if (!description.state_->sizing) {
3278 description.state_->sizing = std::make_unique<RecipeSizing>();
3279 }
3280
3281 description.state_->sizing->overlay(sizing);
3282 }
3283}
3284
3285template <class T>
3286void Access::preparedControlPresence(Description<T> &description, ControlPropertyPresence alreadyMaterialized) {
3287 if (description.state_) {
3288 description.state_->controlPrepared = true;
3289 description.state_->materializedSettings = alreadyMaterialized;
3290
3291 if constexpr (std::same_as<T, Grid>) {
3292 if (description.state_->layout && description.state_->layout->gridContainer && description.state_->layout->grid) {
3293 auto &control = description.gridControl();
3294
3295 control.materialized = true;
3296 control.materializedSettings = alreadyMaterialized;
3297 }
3298 }
3299 }
3300}
3301
3302inline void Access::preparedDialogHeading(Description<Label> &description, const TextValue &title) {
3303 ControlSettings materialized;
3304
3305 materialized.text = title;
3306 preparedControlPresence(description, controlSettingsPresenceSet(materialized));
3307
3308 if (description.state_) {
3309 description.state_->inheritPreparedDefaults = true;
3310 }
3311}
3312
3313template <class T> void Access::preparedThemeSelectorCaption(Description<T> &description, const TextValue &caption) {
3314 static_assert(std::same_as<T, Label> || std::same_as<T, Button>);
3315 ControlSettings settings;
3316
3317 settings.text = caption;
3318 preparedControlPresence(description, controlSettingsPresenceSet(settings));
3319
3320 if (description.state_) {
3321 description.state_->inheritPreparedDefaults = true;
3322 description.state_->settingsRequested = true;
3323 }
3324}
3325
3327 if (description.state_) {
3328 description.state_->semanticConstruction = std::make_shared<SemanticConstruction>();
3329 description.state_->semanticConstruction->kind = ControlFactoryKind::THEME_CATALOG_BINDING;
3330 }
3331 return configuredControl(std::move(description), "ThemeSelectorCatalog");
3332}
3333
3334template <class T> bool Access::themeCatalogRecipient(const Description<T> &description) noexcept {
3335 return description.state_ && description.state_->semanticConstruction &&
3336 description.state_->semanticConstruction->kind == ControlFactoryKind::THEME_CATALOG_BINDING;
3337}
3338
3340 if (description.state_) {
3341 description.state_->semanticConstruction = std::make_shared<SemanticConstruction>();
3342 description.state_->semanticConstruction->kind = ControlFactoryKind::THEME_SELECTOR_BINDING;
3343 }
3344
3345 return configuredControl(std::move(description), "ThemeSelector");
3346}
3347
3349 if (description.state_) {
3350 description.state_->semanticConstruction = std::make_shared<SemanticConstruction>();
3351 }
3352
3353 return configuredControl(std::move(description), "MessageBox");
3354}
3355
3357 if (description.state_) {
3358 description.state_->semanticConstruction = std::make_shared<SemanticConstruction>();
3359 description.state_->semanticConstruction->kind = ControlFactoryKind::NOTIFICATION_BINDING;
3360 }
3361
3362 return configuredControl(std::move(description), "Notifications");
3363}
3364
3365template <class T>
3366std::expected<void, ManagedError> Access::messageSource(Description<T> &description, const ControlSettings &settings,
3367 ControlPropertyPresence materialized, ControlFactoryKind kind) {
3368 if (!description.state_ || !description.state_->semanticConstruction ||
3369 (description.state_->semanticConstruction->kind != kind &&
3370 !(kind == ControlFactoryKind::THEME_SELECTOR_BINDING && themeCatalogRecipient(description)))) {
3371 return std::unexpected(controlContextError({ControlContextErrorCode::INVALID_VALUE, {}}));
3372 }
3373
3374 auto &construction = *description.state_->semanticConstruction;
3375
3376 construction.source = settings;
3377 construction.materialized = materialized;
3378 construction.prepared = true;
3379
3380 return {};
3381}
3382
3383template <class T>
3384std::expected<void, ManagedError> Access::messageBody(Description<T> &description, Description<Widget> body) {
3385 if (!description.state_ || !description.state_->semanticConstruction ||
3386 description.state_->semanticConstruction->kind != ControlFactoryKind::MESSAGE_BINDING) {
3387 return std::unexpected(error({}, TreeError::INVALID_ARGUMENT));
3388 }
3389
3390 description.state_->semanticConstruction->body = std::make_shared<Description<Widget>>(std::move(body));
3391
3392 return {};
3393}
3394
3396 // Only this composite's already checked options bypass ambient Dialog defaults; children still inherit normally.
3397 if (prechargedTitle) {
3398 ControlSettings settings;
3399
3400 settings.title = *prechargedTitle;
3401 preparedControlPresence(description, controlSettingsPresenceSet(settings));
3402 (void)std::move(description).settings(std::move(settings));
3403 }
3404
3405 return configuredControl(std::move(description), "Dialog", false);
3406}
3407
3408template <class T>
3409Description<T> Access::configuredControl(Description<T> description, std::string_view type, bool inherit) {
3410 if (description.state_ && !type.empty()) {
3411 description.state_->controlType.emplace(type);
3412 description.state_->inheritControlSettings = inherit;
3413 }
3414 return description;
3415}
3416
3417template <class T> Description<T> Access::controlArguments(Description<T> description, ControlSettings arguments) {
3418 if (description.state_) {
3419 description.state_->controlArguments = std::move(arguments);
3420 }
3421 return description;
3422}
3423
3424template <class T> Description<T> Access::failed(ManagedError failure) {
3425 Description<T> description;
3426
3427 description.state_ = std::make_unique<typename Description<T>::State>();
3428 description.state_->prerequisiteFailure = std::make_unique<ManagedError>(std::move(failure));
3429
3430 return description;
3431}
3432
3434 if (!description.state_ || description.state_->prerequisiteFailure ||
3435 (!patch.state && !patch.cycle && !patch.readOnly)) {
3436 return;
3437 }
3438
3439 auto &state = *description.state_;
3440 auto merged = mergeControlSettings(state.controlPatch, patch);
3441
3442 // Retain factory provenance for every leaf not replaced by this resource packet.
3443 merged.origin = state.controlPatch.origin;
3444 merged.origins = state.controlPatch.origins;
3445
3446 for (const auto &origin : patch.origins) {
3447 auto found = std::ranges::find(merged.origins, origin.path, &ControlPropertyOrigin::path);
3448
3449 if (found == merged.origins.end()) {
3450 merged.origins.push_back(origin);
3451 } else {
3452 found->source = origin.source;
3453 }
3454 }
3455
3456 state.controlPatch = std::move(merged);
3457 state.settingsRequested = true;
3458}
3459
3460template <class T, class Callback> Description<T> Access::controlSetup(Description<T> description, Callback callback) {
3461 if (description.state_) {
3462 description.state_->controlSetup = std::move(callback);
3463 }
3464 return description;
3465}
3466
3467template <class T, class Factory> Description<T> Access::describe(Factory factory) {
3468 return Description<T>(std::move(factory));
3469}
3470
3471template <class T> Description<T> Access::intrinsicStyle(Description<T> description, StyleTarget identity) {
3472 if (description.state_) {
3473 description.state_->intrinsicStyle.emplace(std::move(identity));
3474 }
3475
3476 return description;
3477}
3478
3480template <class T, class Factory> Description<T> Access::cold(Factory factory) {
3481 Description<T> description;
3482 description.state_ = std::make_unique<typename Description<T>::State>();
3483 description.state_->create = std::move(factory);
3484 return description;
3485}
3486
3488
3489template <class Factory> Description<Widget> Access::transaction(Factory factory) {
3490 Description<Widget> description;
3491
3492 description.state_ = std::make_unique<Description<Widget>::State>();
3493 description.state_->create = std::move(factory);
3494
3495 return description;
3496}
3497
3499 if (description.state_) {
3500 description.state_->forwardsOuter = true;
3501 }
3502
3503 return description;
3504}
3505
3506template <class T> void Access::numericSettings(Description<T> &description, ControlSettings patch) {
3507 static_assert(std::derived_from<T, Slider> || std::same_as<T, SpinBox>);
3508
3509 if (!description.state_ || description.state_->prerequisiteFailure ||
3510 detail::controlSettingsPresenceSet(patch).count() == 0) {
3511 return;
3512 }
3513
3514 auto &state = *description.state_;
3515 auto merged = mergeControlSettings(state.controlPatch, patch);
3516
3517 merged.origin = state.controlPatch.origin;
3518 merged.origins = state.controlPatch.origins;
3519
3520 for (const auto &origin : patch.origins) {
3521 auto found = std::ranges::find(merged.origins, origin.path, &ControlPropertyOrigin::path);
3522
3523 if (found == merged.origins.end()) {
3524 merged.origins.push_back(origin);
3525 } else {
3526 found->source = origin.source;
3527 }
3528 }
3529
3530 state.controlPatch = std::move(merged);
3531 state.settingsRequested = true;
3532}
3533
3534template <class T> Description<Widget> Access::erase(Description<T> description) {
3535 Description<Widget> erased;
3536
3537 erased.state_ = std::make_unique<Description<Widget>::State>();
3538 erased.state_->forwardsOuter = true;
3539 if (description.state_) {
3540 erased.state_->prerequisiteFailure = std::move(description.state_->prerequisiteFailure);
3541 erased.state_->layout = description.state_->layout;
3542 erased.state_->semanticConstruction = description.state_->semanticConstruction;
3543 }
3544 erased.state_->create =
3545 [description = std::move(description)](ManagedScene &scene, Node<Widget> parent,
3546 MountContext &context) mutable -> std::expected<Node<Widget>, ManagedError> {
3547 auto result = mount(std::move(description), scene, parent, context);
3548
3549 if (!result) {
3550 return std::unexpected(result.error());
3551 }
3552
3553 return Node<Widget>(*result);
3554 };
3555
3556 return erased;
3557}
3558
3559template <class T>
3560std::expected<Node<T>, ManagedError> Access::mount(Description<T> &&description, ManagedScene &scene,
3561 Node<Widget> parent, MountContext &context) {
3562 return std::move(description).mountInto(scene, parent, context);
3563}
3564
3573template <class T> auto own(T &&value) {
3574 if constexpr (std::convertible_to<T, std::string_view>) {
3575 return std::string(std::string_view(value));
3576 } else {
3577 return std::decay_t<T>(std::forward<T>(value));
3578 }
3579}
3580
3586template <class T> decltype(auto) constructionArgument(T &&value) {
3587 if constexpr (std::convertible_to<T, std::string_view>) {
3588 return std::string_view(value);
3589 } else {
3590 return std::forward<T>(value);
3591 }
3592}
3593} // namespace detail
3594
3595} // namespace portals::ui
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
Copyable typed observer; never owns or exposes an unchecked widget pointer.
Definition widget.hpp:92
Owning literal bytes or a resource key, measured only at resolution.
Definition text_value.hpp:42
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Description && framed(Ref< Border > outer, std::string_view pattern, Model< Value > title) &&
Description && rowGap(std::int32_t cells) &&
Definition ui_description.hpp:1763
Description && emptyText(std::string value) &&
Definition ui_description.hpp:1040
Description && interval(SchedulerTime value) &&
Definition ui_description.hpp:1125
Description && closeOnEscape(bool value=true) &&
Definition ui_description.hpp:906
Description && hex(DocumentHexOptions options={}) &&
Definition ui_description.hpp:100
Description && syntax(DocumentSyntaxPolicy value) &&
Definition ui_description.hpp:143
Description && mode(ChartMode value) &&
Definition ui_description.hpp:744
Description && placeholder(std::string_view value) &&
Definition ui_description.hpp:521
Description && verticalAlign(LayoutAlign align) &&
Definition ui_description.hpp:1224
Description && scrollStep(std::uint64_t rows) &&
Definition ui_description.hpp:184
Description && scroll(std::shared_ptr< ScrollController > controller={}) &&
Definition ui_description.hpp:1846
Description && immediate(bool enabled=true) &&
Definition ui_description.hpp:469
Description && glyphs(PrimitiveGlyphs value) &&
Definition ui_description.hpp:270
Description && scrollTrack(ScrollbarPattern pattern) &&
Definition ui_description.hpp:591
Description && glyphFallback(std::string_view value) &&
Definition ui_description.hpp:261
Description && framed(FrameOptions options={}) &&
Definition ui_description.hpp:1450
Description && style(StyleTarget target) &&
Definition ui_description.hpp:1288
Description && gridOptions(DeclarativeGridOptions options) &&
Definition ui_description.hpp:1777
Description && lineNumbers(bool enabled=true) &&
Definition ui_description.hpp:155
Description && glyphs(SliderGlyphs value) &&
Definition ui_description.hpp:377
Description && scrollbar(std::string_view pattern) &&
Definition ui_description.hpp:566
Description && id(std::string_view value) &&
Definition ui_description.hpp:1306
Description && selectionMode(RadioSelectionMode value) &&
Definition ui_description.hpp:460
Description && viewportMargin(std::int32_t value) &&
Definition ui_description.hpp:888
Description && placeholder(TextValue value) &&
Definition ui_description.hpp:514
Description && skin(SpinBoxSkin value) &&
Definition ui_description.hpp:365
Description && format(ControlKeyFormatSettings values) &&
Definition ui_description.hpp:1031
Description && maxFrameBytes(std::size_t value) &&
Definition ui_description.hpp:1197
Description && placement(ScrollPlacement placement) &&
Definition ui_description.hpp:548
Description && horizontal(ScrollBarPolicy policy) &&
Definition ui_description.hpp:530
Description && glyphFallback(GlyphFallback value) &&
Definition ui_description.hpp:254
Description && scrollTrack(std::string_view pattern) &&
Definition ui_description.hpp:584
Description && unavailableText(std::string value) &&
Definition ui_description.hpp:1049
Description && scrollArrows(std::string_view pattern) &&
Definition ui_description.hpp:616
Description && framed(std::string_view pattern, std::string_view title) &&
Definition ui_description.hpp:1532
Description && arrows(bool enabled=true) &&
Definition ui_description.hpp:424
Description()=default
Construct an empty recipe; mounting it returns INVALID_ARGUMENT.
Description && glyphProfile(GlyphProfile value) &&
Definition ui_description.hpp:236
Description && fitWidth() &&
Definition ui_description.hpp:1655
Description && overscanRows(std::size_t value) &&
Definition ui_description.hpp:708
Description && language(std::string_view name) &&
Definition ui_description.hpp:134
Description && range(double minimum, double maximum) &&
Definition ui_description.hpp:318
Description && wheelStep(double cells) &&
Definition ui_description.hpp:397
Description && flexY(std::uint32_t weight=1) &&
Definition ui_description.hpp:1962
Description && showStatus(bool value=true) &&
Definition ui_description.hpp:787
Description && minWidth(std::int32_t cells) &&
Definition ui_description.hpp:1671
Description && preset(SpinnerPreset value) &&
Definition ui_description.hpp:1088
Description && scrollbar(ScrollbarSkin skin) &&
Definition ui_description.hpp:633
Description && chrome(ButtonChrome value) &&
Definition ui_description.hpp:227
Description && prefix() &&
Definition ui_description.hpp:486
Description && anchorGap(std::int32_t value) &&
Definition ui_description.hpp:897
Description && enabled(bool value=true) &&
Definition ui_description.hpp:1437
Description && readOnly(bool value=true) &&
Definition ui_description.hpp:451
Description && preferredWidth(std::int32_t cells) &&
Definition ui_description.hpp:327
Description && noEcho(bool enabled=true) &&
Definition ui_description.hpp:495
Description && fastScroll(std::uint64_t step=8, key::Modifier keyboard=key::CTRL, key::Modifier wheel=key::ALT) &&
Definition ui_description.hpp:167
Description && yRange(std::optional< ChartRange > range) &&
Definition ui_description.hpp:771
Description && candleGap(std::int32_t cells) &&
Definition ui_description.hpp:762
Description && scrollbar(ScrollbarPattern pattern) &&
Definition ui_description.hpp:575
Description && columns(std::size_t count) &&
Definition ui_description.hpp:1707
Description && settings(ControlSettings patch) &&
Definition ui_description.hpp:69
Description && anchor(const Ref< U > &reference, DialogPlacement placement=DialogPlacement::BELOW_START) &&
Definition ui_description.hpp:1261
Description && vertical(ScrollBarPolicy policy) &&
Definition ui_description.hpp:539
Description && active(bool value) &&
Definition ui_description.hpp:1152
Description && maxFrames(std::size_t value) &&
Definition ui_description.hpp:1188
Description && frameEnabled(bool enabled=true) &&
Definition ui_description.hpp:652
Description && onDismiss(Callback callback) &&
Definition ui_description.hpp:1277
Description && scrollThumb(ScrollbarThumbPattern pattern) &&
Definition ui_description.hpp:607
Description && minHeight(std::int32_t cells) &&
Definition ui_description.hpp:1689
Description && framed(Ref< Border > outer, std::string_view pattern, std::string_view title) &&
Definition ui_description.hpp:1603
Description && focusable(bool value=true) &&
Definition ui_description.hpp:442
Description && labels(ControlDataStateLabelSettings values) &&
Definition ui_description.hpp:823
Description && themeCatalogSettings(ControlThemeCatalogSettings values) &&
Definition ui_description.hpp:984
Description && rowSpan(std::size_t count) &&
Definition ui_description.hpp:1927
Description && scrollArrows(ScrollbarArrowPattern pattern) &&
Definition ui_description.hpp:623
Description && classes(std::string_view value) &&
Definition ui_description.hpp:1320
Description && reference(NodeRef< T > reference) &&
Definition ui_description.hpp:1251
Description && axis(ScrollAxis axis) &&
Definition ui_description.hpp:679
Description && observe(ManagedSource< Value > source, Callback callback) &&
Definition ui_description.hpp:1374
Description && width(std::int32_t cells) &&
Definition ui_description.hpp:1639
Description && chartGlyphSet(ChartGlyphSet value) &&
Definition ui_description.hpp:753
Description && horizontalAlign(LayoutAlign align) &&
Definition ui_description.hpp:1215
Description && keyStep(std::uint64_t cells) &&
Definition ui_description.hpp:406
Description && focusScope() &&
Declare this subtree as a nested focus scope, with scene-owned lifetime.
Definition ui_description.hpp:1992
Description && padding(LayoutPadding insets) &&
Definition ui_description.hpp:1076
Description && titleDecoration(TitleDecoration decoration) &&
Definition ui_description.hpp:1468
Description && row(std::size_t index) &&
Definition ui_description.hpp:1903
Description && label(TextValue value) &&
Definition ui_description.hpp:1179
Description && autoRowHeight(bool enabled=true) &&
Definition ui_description.hpp:697
Description && direction(SpinnerDirection value) &&
Definition ui_description.hpp:1134
Description && glyphProfile(std::string_view value) &&
Definition ui_description.hpp:245
Description && themeSelectorSettings(ControlThemeSelectorSettings values) &&
Definition ui_description.hpp:996
Description && rowHeight(std::int32_t value) &&
Definition ui_description.hpp:688
Description && column(std::size_t index) &&
Definition ui_description.hpp:1915
Description && title(TextValue value) &&
Definition ui_description.hpp:841
Description && maximumPanelSize(CellSize caps) &&
Definition ui_description.hpp:926
Description && contentPolicy(DataContentPolicy value) &&
Definition ui_description.hpp:805
Description && flow(GridFlow value) &&
Definition ui_description.hpp:1735
Description && flex(std::uint32_t weight=1) &&
Definition ui_description.hpp:1971
Description && fitHeight() &&
Definition ui_description.hpp:1662
Description && scrollThumb(std::string_view pattern) &&
Definition ui_description.hpp:600
Description && dialogSettings(ControlDialogSettings values) &&
Definition ui_description.hpp:946
Description && minimum(double value) &&
Definition ui_description.hpp:299
Description && scrollOptions(ScrollAreaOptions options) &&
Definition ui_description.hpp:1870
Description && minimumThumb(std::int32_t cells) &&
Definition ui_description.hpp:433
Description && columnSpan(std::size_t count) &&
Definition ui_description.hpp:1939
Description && gridItem(GridItemOptions options) &&
Definition ui_description.hpp:1891
Description && frames(std::string_view value) &&
Definition ui_description.hpp:1116
Description && rows(std::size_t count) &&
Definition ui_description.hpp:1721
Description && setup(Setup< T > callback) &&
Definition ui_description.hpp:1981
Description && frames(std::initializer_list< std::string_view > values) &&
Definition ui_description.hpp:1107
Description && alignment(LayoutAlign value) &&
Definition ui_description.hpp:1143
Description && columnGap(std::int32_t cells) &&
Definition ui_description.hpp:1749
Description && onClick(Callback callback) &&
Definition ui_description.hpp:1332
Description && framed(std::string_view pattern) &&
Definition ui_description.hpp:1508
Description && flexX(std::uint32_t weight=1) &&
Definition ui_description.hpp:1952
Description && framed(Ref< Border > outer, std::string_view pattern, Title title) &&
Description && height(std::int32_t cells) &&
Definition ui_description.hpp:1648
Description && frame(BorderOptions options) &&
Definition ui_description.hpp:936
Description && spinnerInterval(SchedulerTime value) &&
Definition ui_description.hpp:814
Description && maxColumns(std::size_t value) &&
Definition ui_description.hpp:717
Description && framed(Ref< Border > outer, std::string_view pattern) &&
Definition ui_description.hpp:1586
Description && mode(DialogMode value) &&
Definition ui_description.hpp:859
Description && preset(Name &&value) &&
Definition ui_description.hpp:1100
Description && maxLayers(std::size_t value) &&
Definition ui_description.hpp:832
Description && columnSizes(const std::vector< AxisSize > &policies) &&
Definition ui_description.hpp:1817
Description && visible(bool value=true) &&
Definition ui_description.hpp:1426
Description && pageSteps(std::uint64_t count) &&
Definition ui_description.hpp:388
Description && step(double amount) &&
Definition ui_description.hpp:336
Description && mode(DocumentViewMode value) &&
Definition ui_description.hpp:87
Description && nonModal() &&
Keep the main form available while this dialog is open.
Definition ui_description.hpp:870
Description && variant(std::string_view type) &&
Definition ui_description.hpp:1234
Description && encoding(DocumentEncoding value) &&
Definition ui_description.hpp:207
Description && value(double value) &&
Definition ui_description.hpp:290
Description && closeButton(DialogCloseOptions options={}) &&
Definition ui_description.hpp:915
Description && onPrepare(Callback callback) &&
Definition ui_description.hpp:1406
Description && messageSettings(ControlMessageSettings values) &&
Definition ui_description.hpp:971
Description && maxWidth(std::int32_t cells) &&
Definition ui_description.hpp:1680
Description && frameMaxPaintCells(std::size_t cells) &&
Definition ui_description.hpp:670
Description && maxPreparedTextBytes(std::size_t value) &&
Definition ui_description.hpp:735
Description && skin(SliderSkin value) &&
Definition ui_description.hpp:354
Description && initiallyOpen(bool opened=true) &&
Definition ui_description.hpp:1022
Description && scrollOnFrame() &&
Definition ui_description.hpp:557
Description && onPrepare(ManagedPrepareHandler< T > callback) &&
Definition ui_description.hpp:1392
Description && label(std::string_view value) &&
Definition ui_description.hpp:1170
Description && entrySeparator(std::string value) &&
Definition ui_description.hpp:1058
Description && reducedMotion(bool value) &&
Definition ui_description.hpp:1161
Description && body(TextValue value) &&
Definition ui_description.hpp:955
Description && presentation(GridPresentation presentation) &&
Definition ui_description.hpp:1804
Description && observe(ManagedState< Value > model, Callback callback) &&
Definition ui_description.hpp:1357
Description && wrap(bool enabled=true) &&
Definition ui_description.hpp:198
Description && titleDecoration(std::string_view name) &&
Definition ui_description.hpp:1484
Description && focusDefault() &&
Prefer this node when entering its nearest scope without eligible history.
Definition ui_description.hpp:2004
Description && frameGlyphs(PrimitiveGlyphs glyphs) &&
Definition ui_description.hpp:661
Description && statusRows(std::int32_t value) &&
Definition ui_description.hpp:796
Description && framed(std::string_view pattern, Model< Value > title) &&
Description && placement(DialogPlacement value) &&
Definition ui_description.hpp:879
Description && titleDecoration(CustomTitleDecoration decoration) &&
Definition ui_description.hpp:1493
Description && maximum(double value) &&
Definition ui_description.hpp:308
Description && maxPaintCells(std::size_t cells) &&
Definition ui_description.hpp:280
Description && framed(Ref< Border > outer, FrameOptions options={}) &&
Definition ui_description.hpp:1570
Description && fuzzy(bool enabled=true) &&
Definition ui_description.hpp:478
Description && maxHeight(std::int32_t cells) &&
Definition ui_description.hpp:1698
Description && notificationSettings(ControlNotificationSettings values) &&
Definition ui_description.hpp:1009
Description && editMode(EditMode value) &&
Definition ui_description.hpp:506
Description && threeState() &&
Definition ui_description.hpp:218
Description && pageOverlap(std::uint64_t cells) &&
Definition ui_description.hpp:415
Description && onEvent(ManagedEventHandler< T > callback) &&
Definition ui_description.hpp:1383
Description && language(DocumentLanguage value) &&
Definition ui_description.hpp:120
Description && rowSizes(const std::vector< AxisSize > &policies) &&
Definition ui_description.hpp:1832
Description && skin(std::string_view name) &&
Definition ui_description.hpp:345
Description && maxFrameCells(std::size_t value) &&
Definition ui_description.hpp:1206
Description && overflowMarker(std::string value) &&
Definition ui_description.hpp:1067
Description && title(std::string_view value) &&
Definition ui_description.hpp:850
Description && framed(std::string_view pattern, Title title) &&
Description && body(std::string_view value) &&
Definition ui_description.hpp:962
Description && maxPreparedCells(std::size_t value) &&
Definition ui_description.hpp:726
Description(Description &&) noexcept=default
Transfer the unnamed recipe; its source becomes empty.
Single-use semantic Grid section; owns recipes and never mounts a placeholder Widget.
Definition ui_description.hpp:2889
GridSection && style(CellStyle value) &&
Definition ui_description.hpp:2931
GridSection(GridSection &&other)
Definition ui_description.hpp:2892
GridSection & operator=(GridSection &&other)
Definition ui_description.hpp:2899
GridSection && sticky(bool value=true) &&
Definition ui_description.hpp:2921
GridSection && rowStyles(GridRowStyles value) &&
Definition ui_description.hpp:2940
Owning cold model declaration; copies share one single-scene registration. Construction does not read...
Definition ui_model.hpp:129
Shared observing slot published only after a complete successful description mount.
Definition ui_ref.hpp:724
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Scene & style(const StyleStage &stage, std::source_location origin=std::source_location::current()) &
A compact action optionally receives owning event parameters.
Definition managed.hpp:239
Exact checked TreeError result, including owning success values.
Definition managed.hpp:201
Admit only consuming recipe arguments, rejecting implicit moves from lvalues.
Definition ui_recipe_context.hpp:71
consteval auto type(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:876
auto reference(ui::Ref< T > value)
Definition ui_static.hpp:572
DocumentSyntaxPolicy
Recovery policy; the language still selects the lexical rules.
Definition document_highlight_types.hpp:31
ScrollBarPolicy
Presence policy, independent of whether the content can scroll.
Definition scroll_geometry.hpp:21
RadioSelectionMode
User selection publication policy; active navigation remains local to the group.
Definition radio_group.hpp:80
@ ON_ACTIVATION
Arrows move active; Space/Enter selects.
Definition radio_group.hpp:81
@ IMMEDIATE
Eligible keyboard movement also selects.
Definition radio_group.hpp:82
SpinBoxSkin
Immutable presentation of the two numeric step buttons.
Definition spin_box.hpp:9
@ NORMAL
Render the draft using its actual grapheme widths; copying and cutting retain normal behavior.
Definition line_edit.hpp:35
@ NO_ECHO
Render no value or selection, with a fixed-origin caret and intrinsic width one; suppress copy/cut.
Definition line_edit.hpp:37
@ PASSWORD
Render one ASCII '*' per grapheme, revealing its count; suppress outbound copy/cut.
Definition line_edit.hpp:36
ChartMode
Retained chart rendering mode.
Definition chart.hpp:49
GridFlow
Direction in which declarative placement searches for the next free origin.
Definition grid.hpp:53
PrimitiveGlyphs
One-cell decoration selection under the complete receiving WidthPolicy.
Definition primitives.hpp:20
ScrollbarThumbPattern
Independent thumb source; all choices are opt-in.
Definition scrollbar_skin.hpp:24
DocumentViewMode
Projection of the same original source bytes.
Definition document_view.hpp:37
@ HEX
Project raw fixed-width byte rows without decoding.
Definition document_view.hpp:39
std::function< std::expected< EventReply, TreeError >(T &, const RoutedEvent &)> ManagedEventHandler
Owning, copyable custom input adapter; arguments are borrowed for one invocation.
Definition managed.hpp:326
DataContentPolicy
Explicit content policy; automatic range wrappers always keep their request-owning body live.
Definition data_presentation.hpp:63
SliderSkin
Built-in one-cell slider glyph sets.
Definition slider.hpp:11
DocumentLanguage
Explicit lexical profiles; unknown names resolve to PLAIN.
Definition document_highlight_types.hpp:11
constexpr SizePolicy DEFAULT_EDITOR_POLICY
Single-line editors retain one cell even during shortage; text length is not a flex basis.
Definition layout.hpp:50
DialogMode
Input policy applied by the managed dialog owner.
Definition dialog.hpp:15
@ NON_MODAL
Let input outside the panel reach the scene.
Definition dialog.hpp:17
ScrollPlacement
Explicit relationship between bars, content and an optional frame.
Definition scroll_geometry.hpp:28
@ ON_FRAME
Bars occupy the right/bottom frame lines, excluding corners.
Definition scroll_geometry.hpp:31
TitleDecoration
Optional top-title break decoration; NONE preserves literal legacy titles.
Definition frame.hpp:39
ScrollbarPattern
Opt-in scrollbar glyph presets; legacy calls retain their original appearance.
Definition scrollbar_skin.hpp:15
SpinnerDirection
Traversal of the finite owning frame sequence.
Definition spinner.hpp:81
LayoutAlign
Alignment; center assigns floor(free/2) before the child/group.
Definition layout.hpp:172
ChartGlyphSet
Candle brushes; Unicode falls back to ASCII when the width policy requires wide symbols.
Definition chart.hpp:55
SpinnerPreset
Original single-row indeterminate animation sequences.
Definition spinner.hpp:16
GlyphProfile
Explicit glyph map, independent of colors and geometry. NF maps use Nerd Fonts 3 Powerline codepoints...
Definition glyph_profile.hpp:12
ScrollAxis
Logical scrolling axis; X increases right and Y increases down.
Definition scroll_geometry.hpp:15
DocumentLanguage documentLanguageFromName(std::string_view name) noexcept
std::uint64_t SchedulerTime
Monotonic milliseconds; the clock must not move backwards.
Definition scheduler.hpp:18
SpinnerPreset spinnerPreset(std::string_view name) noexcept
Definition spinner.hpp:39
GlyphFallback
Portable replacement when the selected map fails one-cell admission.
Definition glyph_profile.hpp:23
DialogPlacement
Preferred panel position within the owning host.
Definition dialog.hpp:21
@ BELOW_START
Prefer below the body anchor, aligned to its leading edge.
Definition dialog.hpp:23
ButtonChrome
Button caption decoration; action routing and identity remain unchanged.
Definition controls.hpp:155
ScrollbarArrowPattern
Independent functional-arrow source; selecting it never enables buttons.
Definition scrollbar_skin.hpp:32
std::function< std::expected< void, TreeError >(T &, Node< Widget >)> ManagedPrepareHandler
Owning, copyable custom presentation adapter at the dirty-frame boundary.
Definition managed.hpp:331
GridRegion
Independent local row coordinate space sharing the grid's columns.
Definition grid.hpp:22
@ BODY
Ordinary content rows, optionally below a header.
Definition grid.hpp:23
@ HEADER
Independent heading rows sharing the horizontal tracks.
Definition grid.hpp:24
@ INVALID_ARGUMENT
An option, enum value or operation argument is invalid.
Definition widget_types.hpp:27
DocumentEncoding
Resolved byte encoding, or an unresolved selection.
Definition document_encoding.hpp:14
EditMode
When an accepted editing candidate is validated and published to its model.
Definition line_edit.hpp:27
Owning frame decoration and finite paint-work policy.
Definition primitives.hpp:27
An owning available extent in terminal columns/rows.
Definition geometry.hpp:44
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 title ends; each holds at most 64 UTF-8 bytes and 16 printable one-cell graphemes.
Definition primitives.hpp:53
Owning automatic-placement settings; counts are distinct from GridOptions track policies.
Definition grid.hpp:76
Optional finite close chrome settings; the glyph occupies three terminal cells.
Definition dialog.hpp:40
Fixed raw-byte rows; auto-fit may choose a smaller row at preparation time.
Definition document_view.hpp:43
Owning advanced frame settings; legacy BorderOptions remains a literal value type.
Definition primitives.hpp:62
Owning parent-child relationship; omitted coordinates request automatic placement.
Definition grid.hpp:65
Backgrounds only; these values never inherit into child control state styles.
Definition grid.hpp:35
Optional owning row backgrounds; logical row zero is even.
Definition grid.hpp:28
Owning nonnegative padding in terminal cells.
Definition layout.hpp:185
Owning bounds and appearances for a one-line editor.
Definition line_edit.hpp:175
Exact editing or confirmation result delivered on the UI thread.
Definition line_edit.hpp:104
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Owning ordinary-area settings; content is retained rather than automatically virtualized....
Definition scroll_options.hpp:36
Owning scrollbar skin; no callbacks, borrowed views, timers or layout changes. Ends occupy existing t...
Definition scrollbar_skin.hpp:66
Owning independent policies for width and height.
Definition layout.hpp:35
Owning custom one-cell printable graphemes used for slider parts. Each value is at most 64 UTF-8 byte...
Definition slider.hpp:21
Owned subject metadata, supplied explicitly for built-in or custom widget types.
Definition style.hpp:40
Sparse explicit chart scale; disabling leaves inherited bounds inactive.
Definition ui_control_context.hpp:195
std::optional< double > maximum
Finite upper endpoint; active ranges must not be reversed.
Definition ui_control_context.hpp:198
std::optional< double > minimum
Finite lower endpoint; requires an effective explicit range.
Definition ui_control_context.hpp:197
Sparse owning status expressions; unused labels remain native construction concerns.
Definition ui_control_context.hpp:202
Sparse native dialog geometry/input options, merged per leaf.
Definition ui_control_context.hpp:342
Sparse owning literal formatter settings; omitted strings preserve the receiving options.
Definition ui_control_context.hpp:183
Sparse native MessageBox options, preserving captured values and kind-specific checks.
Definition ui_control_context.hpp:252
Sparse immutable notification-center construction options; runtime posts stay code-owned.
Definition ui_control_context.hpp:318
std::string path
Canonical relative path, e.g. history.maxBytes.
Definition ui_control_context.hpp:70
Owning sparse literals only; never contains IDs, models, handlers or live history.
Definition ui_control_context.hpp:391
std::optional< TextValue > text
Caption/value expression, resolved by receiving scene.
Definition ui_control_context.hpp:394
std::optional< CheckCycle > cycle
CheckBox cycle; ThreeState is fixed THREE_STATE.
Definition ui_control_context.hpp:400
std::optional< bool > readOnly
User-mutation policy for supporting controls.
Definition ui_control_context.hpp:402
std::vector< ControlPropertyOrigin > origins
Per-property overrides.
Definition ui_control_context.hpp:408
std::optional< TextValue > title
Owning Dialog caption expression; unspecified keeps the actual caption.
Definition ui_control_context.hpp:452
std::shared_ptr< const ControlDocumentSettings > document
Cold immutable document settings.
Definition ui_control_context.hpp:505
std::optional< CheckState > state
CheckBox/ThreeState/Switch initial state; Switch is boolean only.
Definition ui_control_context.hpp:399
Constructor-only scalars for a real owning default catalog recipe.
Definition ui_control_context.hpp:299
Native ThemeSelector view settings, independent of model/catalog construction.
Definition ui_control_context.hpp:311
Owning optional editor customization and confirmation policy.
Definition ui_description.hpp:34
LineEditOptions options
Editor limits and appearances; scene width policy overrides options.widthPolicy.
Definition ui_description.hpp:36
std::function< std::expected< void, TreeError >(LineEditResult)> result
Optional callback after standard editing.
Definition ui_description.hpp:35
std::function< bool(std::string_view)> validate
Optional publication validator; false retains visible draft.
Definition ui_description.hpp:39
std::shared_ptr< Clipboard > clipboard
Optional UI-owned clipboard adapter retained by the binding.
Definition ui_description.hpp:38
SizePolicy policy
Owning layout constraints validated by the existing layout engine.
Definition ui_description.hpp:37
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< 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 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 gridSection(Description< Grid > &parent, GridSection section)
Definition ui_description.hpp:3181
static Description< Dialog > themeCatalogControl(Description< Dialog > description)
Definition ui_description.hpp:3326
static Description< T > controlArguments(Description< T > description, ControlSettings arguments)
Retain explicit constructor properties above inherited defaults.
Definition ui_description.hpp:3417
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::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 Description< Dialog > messageControl(Description< Dialog > description)
Definition ui_description.hpp:3348
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 bool defersControlValidation(const Description< T > &description)
Definition ui_description.hpp:3149
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 void gridChild(Description< Grid > &parent, Child &&child, std::optional< GridRegion > region={})
Definition ui_description.hpp:3154
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
bool materialized
Resource properties already supplied materialized grid settings.
Definition ui_recipe_context.hpp:349
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
Stack-owned transaction bookkeeping, discarded after one description mount.
Definition ui_recipe_context.hpp:554
Node< Widget > mountedOuter
Last synchronous mount's actual layout root, including through type erasure.
Definition ui_recipe_context.hpp:566
std::function< std::expected< std::pair< bool, bool >, ManagedError >(ControlContext)> choiceProbe
Owning cold metadata probe; never mounts nodes or invokes application factories.
Definition ui_recipe_context.hpp:365
std::vector< std::shared_ptr< RecipeLayout > > children
Cold child metadata in insertion order.
Definition ui_recipe_context.hpp:368