5#include <portals/ui_scene_resource.hpp>
20 consteval Literal(
const char (&value)[N]) {
21 static_assert(N > 0,
"Static scene text requires a terminated array");
23 std::copy_n(value, N,
bytes.begin());
25 if (
bytes.back() !=
'\0') {
26 throw "Static scene text requires a terminated array";
31 constexpr std::string_view
view() const noexcept {
32 return {
bytes.data(), N - 1};
91void staticSceneInvalidLinearOptions();
93void staticSceneInvalidSizePolicy();
95void staticSceneInvalidEditMode();
100constexpr bool validAxis(
AxisSize axis) {
101 return axis.minimum >= 0 && axis.maximum >= axis.minimum && axis.preferred >=
INTRINSIC_EXTENT && axis.weight > 0 &&
109constexpr bool validAlignment(
LayoutAlign alignment) {
133template <
class T,
Literal Id, std::size_t N,
class... Children>
class Element {
136 static constexpr auto ID = Id;
137 static constexpr std::size_t
NODE_COUNT = 1 + (Children::NODE_COUNT + ... + 0);
140 constexpr std::string_view
text() const noexcept {
146 return style_.value();
165 constexpr const std::tuple<Children...> &
children() const noexcept {
174 : text_(text), style_(style), policy_(policy), options_(options), mode_(mode), children_(
children...) {
175 if (!detail::validAxis(policy.
width) || !detail::validAxis(policy.
height)) {
176 detail::staticSceneInvalidSizePolicy();
179 if (!detail::validLinear(options)) {
180 detail::staticSceneInvalidLinearOptions();
184 detail::staticSceneInvalidEditMode();
189 detail::PackedControlStyle style_;
191 LinearOptions options_;
193 std::tuple<Children...> children_;
200template <
class T>
struct IsElement : std::false_type {};
208template <
class T,
Literal Id, std::size_t N,
class... Children>
220template <StaticElement Node>
consteval auto identities() {
221 std::array<std::string_view, Node::NODE_COUNT> result{};
224 result[index++] = Node::ID.view();
225 if constexpr (Node::NODE_COUNT > 1) {
226 []<
class... Children>(std::tuple<Children...> *,
auto &values,
auto &offset) {
229 for (
auto id : identities<Children>()) {
230 values[offset++] = id;
234 }(
static_cast<std::remove_cvref_t<decltype(std::declval<Node>().children())
> *>(
nullptr), result, index);
243template <StaticElement Node>
consteval bool uniqueIds() {
244 constexpr auto IDS = identities<Node>();
246 for (std::size_t i = 0; i < IDS.size(); ++i) {
247 for (std::size_t j = i + 1; j < IDS.size(); ++j) {
248 if (!IDS[i].empty() && IDS[i] == IDS[j]) {
261template <Literal Id, StaticElement Node>
consteval std::size_t idCount() {
262 constexpr auto IDS = identities<Node>();
264 return Id.view().empty() ? 0 : std::ranges::count(IDS, Id.view());
271template <detail::StaticElement Root>
class StaticScene {
274 constexpr const Root &
root() const noexcept {
282 static_assert(detail::uniqueIds<Root>(),
"Static scene duplicate nonempty ID");
305 EditMode mode, Children... children) {
306 return Element<T, Id, N, Children...>(
Literal(text), style, policy, options, mode, children...);
313 template <StaticElement Root>
static consteval auto scene(Root root) {
326template <Literal Id =
"", std::size_t N>
339template <Literal Id =
"", std::size_t N>
353template <Literal Id =
"", std::size_t N>
365template <Literal Id =
"", detail::StaticElement... Children>
385template <Literal Id =
"", detail::StaticElement... Children>
403template <detail::StaticElement Root>
consteval auto scene(Root root) {
409enum class AdapterKind {
420 static constexpr auto ID = Id;
421 static constexpr auto KIND = AdapterKind::REFERENCE;
429 static_assert(std::same_as<T, U>,
"Static scene reference widget type mismatch");
431 if constexpr (std::same_as<T, U>) {
432 return std::move(recipe).reference(std::move(
value));
441template <Literal Id,
class Callback>
struct Click {
442 static constexpr auto ID = Id;
443 static constexpr auto KIND = AdapterKind::CLICK;
451 static_assert(std::same_as<T, Button>,
"Static scene onClick requires Button");
453 if constexpr (std::same_as<T, Button>) {
454 return std::move(recipe).onClick(std::move(
value));
463 static constexpr auto ID = Id;
464 static constexpr auto KIND = AdapterKind::TEXT_BINDING;
471template <
class T>
struct IsAdapter : std::false_type {};
481template <Literal Id,
class Callback>
struct IsAdapter<
Click<Id, Callback>> : std::true_type {};
495template <
RuntimeAdapter... Adapters>
consteval bool uniqueAdapters() {
496 constexpr std::array<std::string_view,
sizeof...(Adapters)> IDS{Adapters::ID.view()...};
497 constexpr std::array<AdapterKind,
sizeof...(Adapters)> KINDS{Adapters::KIND...};
499 for (std::size_t i = 0; i < IDS.size(); ++i) {
500 for (std::size_t j = i + 1; j < IDS.size(); ++j) {
501 if (IDS[i] == IDS[j] && KINDS[i] == KINDS[j]) {
517 using T =
typename Node::WidgetType;
520 if constexpr (std::same_as<T, Row> || std::same_as<T, Column>) {
522 [&](
const auto &...children) {
523 return ui::linear<T>(node.linearOptions(), describeNode(children, adapters...)...);
526 }
else if constexpr (std::same_as<T, LineEdit>) {
528 std::optional<ManagedState<std::string>> state;
532 config.
policy = node.sizePolicy();
535 if constexpr (Adapters::KIND == AdapterKind::TEXT_BINDING && Adapters::ID.view() == Node::ID.view()) {
536 state = adapters.value;
541 return state ? ui::lineEdit(*state, std::move(config)) : ui::
lineEdit(node.text(), std::move(config));
543 return ui::control<T>(node.text(), node.style(), node.sizePolicy());
547 if constexpr (!Node::ID.view().empty()) {
548 recipe = std::move(recipe).id(Node::ID.view());
553 if constexpr (Adapters::ID.view() == Node::ID.view()) {
554 if constexpr (Adapters::KIND == AdapterKind::TEXT_BINDING) {
555 static_assert(std::same_as<T, LineEdit>,
"Static scene bind requires LineEdit");
557 recipe = adapters.apply(std::move(recipe));
581template <Literal Id,
class Callback>
604template <detail::StaticElement Root, detail::RuntimeAdapter... Adapters>
606 static_assert(((detail::idCount<Adapters::ID, Root>() == 1) && ...),
607 "Static scene runtime adapter requires a known nonempty ID");
608 static_assert(detail::uniqueAdapters<Adapters...>(),
"Static scene duplicate runtime adapter kind and ID");
610 return detail::describeNode(value.root(), adapters...);
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
Single-use owning construction recipe; no mounted widget ownership.
Definition ui_description.hpp:48
Typed Widget observation; explicit composite specializations reuse their existing weak facades.
Definition ui_ref.hpp:761
Immutable-through-accessors static node; no live widgets, models, slots or callbacks.
Definition ui_static.hpp:133
static constexpr std::size_t NODE_COUNT
Complete subtree node count.
Definition ui_static.hpp:137
constexpr SizePolicy sizePolicy() const
Definition ui_static.hpp:150
constexpr std::string_view text() const noexcept
Definition ui_static.hpp:140
constexpr const std::tuple< Children... > & children() const noexcept
Definition ui_static.hpp:165
T WidgetType
Existing widget type instantiated only at runtime mount.
Definition ui_static.hpp:135
static constexpr auto ID
Owning static identity; empty means unnamed.
Definition ui_static.hpp:136
constexpr LinearOptions linearOptions() const
Definition ui_static.hpp:155
constexpr ControlStyle style() const
Definition ui_static.hpp:145
constexpr EditMode editMode() const
Definition ui_static.hpp:160
Validated static scene value; runtime recipes and mounted ownership remain separate.
Definition ui_static.hpp:271
constexpr const Root & root() const noexcept
Definition ui_static.hpp:274
A compact action optionally receives owning event parameters.
Definition managed.hpp:239
Admit exact factory-produced runtime adapter types.
Definition ui_static.hpp:490
Admit only static elements produced by this header's factories.
Definition ui_static.hpp:215
Compile-time descriptions translated into the existing owning UI recipes at runtime.
Definition ui_static.hpp:10
consteval auto column(LinearOptions options, Children... children)
Definition ui_static.hpp:386
consteval auto lineEdit(const char(&initial)[N], EditMode mode=EditMode::IMMEDIATE, ControlStyle style=ControlStyle{}, SizePolicy policy=DEFAULT_EDITOR_POLICY)
Definition ui_static.hpp:354
auto reference(ui::Ref< T > value)
Definition ui_static.hpp:572
auto onClick(Callback value)
Definition ui_static.hpp:583
auto bind(ManagedState< std::string > value)
Definition ui_static.hpp:591
consteval auto row(LinearOptions options, Children... children)
Definition ui_static.hpp:366
auto describe(const StaticScene< Root > &value, Adapters... adapters)
Definition ui_static.hpp:605
consteval auto label(const char(&text)[N], ControlStyle style=ControlStyle{}, SizePolicy policy=DEFAULT_CONTENT_POLICY)
Definition ui_static.hpp:327
consteval auto button(const char(&text)[N], ControlStyle style=ControlStyle{}, SizePolicy policy=DEFAULT_CONTENT_POLICY)
Definition ui_static.hpp:340
consteval auto scene(Root root)
Definition ui_static.hpp:403
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
@ AUTOMATIC
Use the preferred/intrinsic extent; shrink towards minimum when space is scarce.
Definition layout.hpp:13
@ CONTENT
Prefer intrinsic size, shrink towards minimum, and never grow to consume spare cells.
Definition layout.hpp:16
@ FIXED
Keep the bounded preferred/intrinsic extent even when it overflows the available space.
Definition layout.hpp:14
@ FLEX
Share spare main-axis cells by weight; allow shrinking towards minimum.
Definition layout.hpp:15
constexpr SizePolicy DEFAULT_CONTENT_POLICY
Intrinsic content on both axes; explicit policies remain authoritative.
Definition layout.hpp:44
constexpr std::int32_t INTRINSIC_EXTENT
Sentinel requesting the widget's intrinsic measurement.
Definition layout.hpp:20
@ CLIP
Preserve hard minima and fixed extents; clip content that does not fit the viewport.
Definition layout.hpp:181
LayoutAlign
Alignment; center assigns floor(free/2) before the child/group.
Definition layout.hpp:172
@ STRETCH
Fill available cross-axis space within size bounds; acts as START on the linear main axis.
Definition layout.hpp:176
@ START
Place at the leading edge of the available space.
Definition layout.hpp:173
@ END
Place at the trailing edge of the available space.
Definition layout.hpp:175
@ CENTER
Center within spare space, rounding the leading offset down to whole cells.
Definition layout.hpp:174
EditMode
When an accepted editing candidate is validated and published to its model.
Definition line_edit.hpp:27
@ ON_COMPLETION
Keep a draft until Enter, programmatic activation or focus loss.
Definition line_edit.hpp:29
@ EXPLICIT
Keep a draft until Enter or programmatic activation; focus loss preserves it.
Definition line_edit.hpp:30
@ IMMEDIATE
Publish each semantic-valid text change; invalid intermediate text remains visible.
Definition line_edit.hpp:28
Owning per-axis bounds; preferred=-1 or CONTENT uses intrinsic measurement.
Definition layout.hpp:23
Small owning paint value, independent of themes and text metrics.
Definition cell_buffer.hpp:35
std::optional< RgbColor > foreground
Foreground RGB, or the terminal default when absent.
Definition cell_buffer.hpp:37
std::optional< RgbColor > background
Background RGB, or the terminal default when absent.
Definition cell_buffer.hpp:39
Owning paint values; no theme engine or behavior is encoded here.
Definition controls.hpp:24
std::int32_t bottom
Trailing rows.
Definition layout.hpp:189
std::int32_t left
Leading columns.
Definition layout.hpp:186
std::int32_t right
Trailing columns.
Definition layout.hpp:188
std::int32_t top
Leading rows.
Definition layout.hpp:187
ControlStyle style
Normal, focused and disabled appearance.
Definition line_edit.hpp:178
EditMode editMode
Confirmation policy shared by input, paste and fluent text edits.
Definition line_edit.hpp:181
Owning linear container options.
Definition layout.hpp:193
LayoutPadding padding
Insets, retained during shortage.
Definition layout.hpp:195
std::int32_t gap
Cells between visible children only.
Definition layout.hpp:194
LayoutAlign cross_align
Child alignment across the linear direction.
Definition layout.hpp:197
LayoutAlign main_align
Group alignment after allocation; stretch is start on this axis.
Definition layout.hpp:196
LayoutOverflow overflow
Explicit shortage policy.
Definition layout.hpp:198
Owning RGB color; terminal encoding belongs to the output adapter.
Definition cell_buffer.hpp:20
Owning independent policies for width and height.
Definition layout.hpp:35
AxisSize width
Horizontal policy.
Definition layout.hpp:36
AxisSize height
Vertical policy.
Definition layout.hpp:37
consteval Literal(const char(&value)[N])
Definition ui_static.hpp:20
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
SizePolicy policy
Owning layout constraints validated by the existing layout engine.
Definition ui_description.hpp:37
Owning fixed-size bytes usable as a structural template argument.
Definition ui_static.hpp:15
std::array< char, N > bytes
Owned bytes, including the terminator.
Definition ui_static.hpp:16
constexpr std::string_view view() const noexcept
Definition ui_static.hpp:31
consteval Literal(const char(&value)[N])
Definition ui_static.hpp:20
Internal construction bridge; factory values cannot bypass constant validation.
Definition ui_static.hpp:290
static consteval auto scene(Root root)
Definition ui_static.hpp:313
static consteval auto element(const char(&text)[N], ControlStyle style, SizePolicy policy, LinearOptions options, EditMode mode, Children... children)
Definition ui_static.hpp:304
Runtime callback storage; captures transfer to the existing managed binding.
Definition ui_static.hpp:441
static constexpr auto ID
Required static target identity.
Definition ui_static.hpp:442
auto apply(Description< T > recipe)
Definition ui_static.hpp:450
Callback value
Owning activation action, never evaluated during constant construction.
Definition ui_static.hpp:444
static constexpr auto KIND
Duplicate checking category.
Definition ui_static.hpp:443
Admit only this header's explicit runtime adapter values.
Definition ui_static.hpp:471
Recognize exact factory-produced static elements.
Definition ui_static.hpp:200
Union-free owning snapshot of one compile-time cell appearance.
Definition ui_static.hpp:40
bool bold
Explicit bold appearance.
Definition ui_static.hpp:45
constexpr CellStyle value() const
Definition ui_static.hpp:57
bool hasForeground
Whether the foreground is an explicit RGB value.
Definition ui_static.hpp:43
RgbColor foreground
Foreground value; ignored when absent.
Definition ui_static.hpp:41
constexpr PackedCellStyle(CellStyle style)
Definition ui_static.hpp:50
bool underline
Explicit underline appearance.
Definition ui_static.hpp:47
RgbColor background
Background value; ignored when absent.
Definition ui_static.hpp:42
bool italic
Explicit italic appearance.
Definition ui_static.hpp:46
bool hasBackground
Whether the background is an explicit RGB value.
Definition ui_static.hpp:44
constexpr ControlStyle value() const
Definition ui_static.hpp:84
PackedCellStyle disabled
Disabled appearance.
Definition ui_static.hpp:76
PackedCellStyle focused
Focused appearance.
Definition ui_static.hpp:75
PackedCellStyle normal
Ordinary appearance.
Definition ui_static.hpp:74
constexpr PackedControlStyle(ControlStyle style)
Definition ui_static.hpp:79
Runtime reference storage, excluded from constant construction.
Definition ui_static.hpp:419
auto apply(Description< U > recipe)
Definition ui_static.hpp:428
ui::Ref< T > value
Shared observing slot; owns neither widget nor scene.
Definition ui_static.hpp:422
static constexpr auto ID
Required static target identity.
Definition ui_static.hpp:420
static constexpr auto KIND
Duplicate checking category.
Definition ui_static.hpp:421
Runtime model observation; no alternate property owner or reactive system.
Definition ui_static.hpp:462
static constexpr auto ID
Required static target identity.
Definition ui_static.hpp:463
ManagedState< std::string > value
Observation belonging to the receiving ManagedScene.
Definition ui_static.hpp:465
static constexpr auto KIND
Duplicate checking category.
Definition ui_static.hpp:464