Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
style_static.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/detail/pss_parser.hpp>
6#include <portals/ui_static.hpp>
7
9namespace portals::style::ct {
10namespace detail {
11using ui::ct::Literal;
12
13// Named non-constexpr boundaries make rejected constant inputs diagnosable on both toolchains.
15void staticStyleInvalidRgb();
17void staticStyleInvalidMix();
19void staticStyleInvalidState();
21void staticStyleInvalidMetric();
22
24void staticStyleInvalidScrollbarPattern();
25
29template <class T>
31 std::same_as<T, RgbColor> || std::same_as<T, bool> || std::same_as<T, std::int32_t> ||
32 std::same_as<T, ScrollbarPattern> || std::same_as<T, ScrollbarThumbPattern> || std::same_as<T, ScrollbarArrowPattern>;
33
38template <Literal Name, ParameterValue T> struct Parameter {
39 static constexpr auto NAME = Name;
41};
42
46template <class... P> struct Parameters {
47 std::tuple<P...> entries;
48
50 constexpr auto defaults() const {
51 return std::apply(
52 [](const auto &...entry) {
53 return std::tuple{entry.initial...};
54 },
55 entries);
56 }
57};
58
62template <Literal Name> struct Token {
63 static constexpr auto NAME = Name;
64};
65
70template <class Left, class Right> struct Mix {
71 Left left;
72 Right right;
73 std::int32_t percentage;
74};
75
80template <Literal Name, class... P> consteval std::size_t parameterIndex(Parameters<P...> const &) {
81 constexpr std::array NAMES{P::NAME.view()...};
82
83 for (std::size_t index = 0; index < NAMES.size(); ++index) {
84 if (NAMES[index] == Name.view()) {
85 return index;
86 }
87 }
88
89 return sizeof...(P);
90}
91
95template <Literal Name> consteval std::size_t parameterIndex(Parameters<> const &) {
96 return 0;
97}
98
105template <class T, class P, class V> constexpr T evaluate(T value, const P &, const V &) {
106 return value;
107}
108
115template <Literal Name, class... P, class V>
116constexpr auto evaluate(Token<Name>, const Parameters<P...> &, const V &values) {
117 constexpr auto INDEX = parameterIndex<Name>(Parameters<P...>{});
118 static_assert(INDEX < sizeof...(P), "Static style token requires a known parameter");
119
120 if constexpr (INDEX < sizeof...(P)) {
121 return std::get<INDEX>(values);
122 }
123}
124
134template <class Left, class Right, class P, class V>
135constexpr RgbColor evaluate(Mix<Left, Right> expression, const P &parameters, const V &values) {
136 auto left = evaluate(expression.left, parameters, values);
137 auto right = evaluate(expression.right, parameters, values);
138 static_assert(std::same_as<decltype(left), RgbColor> && std::same_as<decltype(right), RgbColor>,
139 "Static style mix requires color expressions");
140
141 if constexpr (std::same_as<decltype(left), RgbColor> && std::same_as<decltype(right), RgbColor>) {
142 const auto component = [&](std::uint8_t a, std::uint8_t b) {
143 constexpr std::int32_t FULL_PERCENTAGE = 100;
144
145 return static_cast<std::uint8_t>((a * (FULL_PERCENTAGE - expression.percentage) + b * expression.percentage) /
146 FULL_PERCENTAGE);
147 };
148
149 return {component(left.red, right.red), component(left.green, right.green), component(left.blue, right.blue)};
150 } else {
151 return {};
152 }
153}
154
156enum class Property {
157 FOREGROUND,
158 BACKGROUND,
159 BOLD,
160 ITALIC,
161 UNDERLINE,
162 MIN_WIDTH,
163 FRAME_LINE_FOREGROUND,
164 FRAME_LINE_BACKGROUND,
165 FRAME_LINE_BOLD,
166 FRAME_LINE_ITALIC,
167 FRAME_LINE_UNDERLINE,
168 FRAME_TITLE_FOREGROUND,
169 FRAME_TITLE_BACKGROUND,
170 FRAME_TITLE_BOLD,
171 FRAME_TITLE_ITALIC,
172 FRAME_TITLE_UNDERLINE,
173 FRAME_ENDS_FOREGROUND,
174 FRAME_ENDS_BACKGROUND,
175 FRAME_ENDS_BOLD,
176 FRAME_ENDS_ITALIC,
177 FRAME_ENDS_UNDERLINE,
178 SCROLLBAR_TRACK_FOREGROUND,
179 SCROLLBAR_TRACK_BACKGROUND,
180 SCROLLBAR_TRACK_BOLD,
181 SCROLLBAR_TRACK_ITALIC,
182 SCROLLBAR_TRACK_UNDERLINE,
183 SCROLLBAR_THUMB_FOREGROUND,
184 SCROLLBAR_THUMB_BACKGROUND,
185 SCROLLBAR_THUMB_BOLD,
186 SCROLLBAR_THUMB_ITALIC,
187 SCROLLBAR_THUMB_UNDERLINE,
188 SCROLLBAR_ENDS_FOREGROUND,
189 SCROLLBAR_ENDS_BACKGROUND,
190 SCROLLBAR_ENDS_BOLD,
191 SCROLLBAR_ENDS_ITALIC,
192 SCROLLBAR_ENDS_UNDERLINE,
193 SCROLLBAR_ARROWS_FOREGROUND,
194 SCROLLBAR_ARROWS_BACKGROUND,
195 SCROLLBAR_ARROWS_BOLD,
196 SCROLLBAR_ARROWS_ITALIC,
197 SCROLLBAR_ARROWS_UNDERLINE,
198 SCROLLBAR_CORNER_FOREGROUND,
199 SCROLLBAR_CORNER_BACKGROUND,
200 SCROLLBAR_CORNER_BOLD,
201 SCROLLBAR_CORNER_ITALIC,
202 SCROLLBAR_CORNER_UNDERLINE,
203 SCROLLBAR_TRACK_PATTERN,
204 SCROLLBAR_THUMB_PATTERN,
205 SCROLLBAR_ARROW_PATTERN,
206 SLIDER_TRACK_FOREGROUND,
207 SLIDER_TRACK_BACKGROUND,
208 SLIDER_TRACK_BOLD,
209 SLIDER_TRACK_ITALIC,
210 SLIDER_TRACK_UNDERLINE,
211 SLIDER_FILL_FOREGROUND,
212 SLIDER_FILL_BACKGROUND,
213 SLIDER_FILL_BOLD,
214 SLIDER_FILL_ITALIC,
215 SLIDER_FILL_UNDERLINE,
216 SLIDER_THUMB_FOREGROUND,
217 SLIDER_THUMB_BACKGROUND,
218 SLIDER_THUMB_BOLD,
219 SLIDER_THUMB_ITALIC,
220 SLIDER_THUMB_UNDERLINE,
221 GLYPH_PROFILE,
222 GLYPH_FALLBACK,
223 SCROLLBAR_THUMB_START_FOREGROUND,
224 SCROLLBAR_THUMB_START_BACKGROUND,
225 SCROLLBAR_THUMB_START_BOLD,
226 SCROLLBAR_THUMB_START_ITALIC,
227 SCROLLBAR_THUMB_START_UNDERLINE,
228 SCROLLBAR_THUMB_BODY_FOREGROUND,
229 SCROLLBAR_THUMB_BODY_BACKGROUND,
230 SCROLLBAR_THUMB_BODY_BOLD,
231 SCROLLBAR_THUMB_BODY_ITALIC,
232 SCROLLBAR_THUMB_BODY_UNDERLINE,
233 SCROLLBAR_THUMB_END_FOREGROUND,
234 SCROLLBAR_THUMB_END_BACKGROUND,
235 SCROLLBAR_THUMB_END_BOLD,
236 SCROLLBAR_THUMB_END_ITALIC,
237 SCROLLBAR_THUMB_END_UNDERLINE,
238 SCROLLBAR_THUMB_SINGLE_FOREGROUND,
239 SCROLLBAR_THUMB_SINGLE_BACKGROUND,
240 SCROLLBAR_THUMB_SINGLE_BOLD,
241 SCROLLBAR_THUMB_SINGLE_ITALIC,
242 SCROLLBAR_THUMB_SINGLE_UNDERLINE,
243};
244
249template <Property Kind, class Expression> struct Declaration {
250 static constexpr auto KIND = Kind;
251 Expression expression;
252};
253
259template <Literal Type, Literal Id, Literal... Classes> struct Selector {
260 static constexpr auto TYPE = Type;
261 static constexpr auto ID = Id;
262 static constexpr std::array CLASS_NAMES{Classes.view()...};
264 bool readOnly{};
265};
266
271template <Literal Type, Literal Id> struct Selector<Type, Id> {
272 static constexpr auto TYPE = Type;
273 static constexpr auto ID = Id;
274 static constexpr std::array<std::string_view, 0> CLASS_NAMES{};
276 bool readOnly{};
277};
278
283template <class S, class... D> struct Rule {
285 std::tuple<D...> declarations;
286};
287
291template <class T> struct IsRule : std::false_type {};
292
297template <class S, class... D> struct IsRule<Rule<S, D...>> : std::true_type {};
298
302template <class T> struct IsDeclaration : std::false_type {};
303
308template <Property K, class E> struct IsDeclaration<Declaration<K, E>> : std::true_type {};
309
313template <class T> struct IsParameter : std::false_type {};
314
319template <Literal N, class V> struct IsParameter<Parameter<N, V>> : std::true_type {};
320
324template <class... P> consteval bool uniqueParameters(Parameters<P...> const &) {
325 constexpr std::array<std::string_view, sizeof...(P)> NAMES{P::NAME.view()...};
326
327 for (std::size_t index = 0; index < NAMES.size(); ++index) {
328 if (NAMES[index].empty()) {
329 return false;
330 }
331
332 for (std::size_t other = index + 1; other < NAMES.size(); ++other) {
333 if (NAMES[index] == NAMES[other]) {
334 return false;
335 }
336 }
337 }
338
339 return true;
340}
341
345template <class... D> consteval bool uniqueDeclarations(const std::tuple<D...> &) {
346 constexpr std::array<Property, sizeof...(D)> KINDS{D::KIND...};
347
348 for (std::size_t index = 0; index < KINDS.size(); ++index) {
349 for (std::size_t other = index + 1; other < KINDS.size(); ++other) {
350 if (KINDS[index] == KINDS[other]) {
351 return false;
352 }
353 }
354 }
355
356 return true;
357}
358
367template <class D, class P, class V>
368constexpr void assign(const D &declaration, StyleDeclarations &destination, const P &parameters, const V &values) {
369 auto value = evaluate(declaration.expression, parameters, values);
370 constexpr bool COLOR =
371 D::KIND == Property::FOREGROUND || D::KIND == Property::BACKGROUND || D::KIND == Property::FRAME_LINE_FOREGROUND ||
372 D::KIND == Property::FRAME_LINE_BACKGROUND || D::KIND == Property::FRAME_TITLE_FOREGROUND ||
373 D::KIND == Property::FRAME_TITLE_BACKGROUND || D::KIND == Property::FRAME_ENDS_FOREGROUND ||
374 D::KIND == Property::FRAME_ENDS_BACKGROUND || D::KIND == Property::SCROLLBAR_TRACK_FOREGROUND ||
375 D::KIND == Property::SCROLLBAR_TRACK_BACKGROUND || D::KIND == Property::SCROLLBAR_THUMB_START_FOREGROUND ||
376 D::KIND == Property::SCROLLBAR_THUMB_START_BACKGROUND || D::KIND == Property::SCROLLBAR_THUMB_BODY_FOREGROUND ||
377 D::KIND == Property::SCROLLBAR_THUMB_BODY_BACKGROUND || D::KIND == Property::SCROLLBAR_THUMB_END_FOREGROUND ||
378 D::KIND == Property::SCROLLBAR_THUMB_END_BACKGROUND || D::KIND == Property::SCROLLBAR_THUMB_SINGLE_FOREGROUND ||
379 D::KIND == Property::SCROLLBAR_THUMB_SINGLE_BACKGROUND || D::KIND == Property::SCROLLBAR_THUMB_FOREGROUND ||
380 D::KIND == Property::SCROLLBAR_THUMB_BACKGROUND || D::KIND == Property::SCROLLBAR_ENDS_FOREGROUND ||
381 D::KIND == Property::SCROLLBAR_ENDS_BACKGROUND || D::KIND == Property::SCROLLBAR_ARROWS_FOREGROUND ||
382 D::KIND == Property::SCROLLBAR_ARROWS_BACKGROUND || D::KIND == Property::SCROLLBAR_CORNER_FOREGROUND ||
383 D::KIND == Property::SCROLLBAR_CORNER_BACKGROUND || D::KIND == Property::SLIDER_TRACK_FOREGROUND ||
384 D::KIND == Property::SLIDER_TRACK_BACKGROUND || D::KIND == Property::SLIDER_FILL_FOREGROUND ||
385 D::KIND == Property::SLIDER_FILL_BACKGROUND || D::KIND == Property::SLIDER_THUMB_FOREGROUND ||
386 D::KIND == Property::SLIDER_THUMB_BACKGROUND;
387 constexpr bool METRIC = D::KIND == Property::MIN_WIDTH;
388 using Expected = std::conditional_t<
389 D::KIND == Property::SCROLLBAR_TRACK_PATTERN, ScrollbarPattern,
390 std::conditional_t<
391 D::KIND == Property::SCROLLBAR_THUMB_PATTERN, ScrollbarThumbPattern,
392 std::conditional_t<
393 D::KIND == Property::SCROLLBAR_ARROW_PATTERN, ScrollbarArrowPattern,
394 std::conditional_t<
395 D::KIND == Property::GLYPH_PROFILE, GlyphProfile,
396 std::conditional_t<D::KIND == Property::GLYPH_FALLBACK, GlyphFallback,
397 std::conditional_t<COLOR, RgbColor, std::conditional_t<METRIC, std::int32_t, bool>>>>>>>;
398 static_assert(std::same_as<decltype(value), Expected>, "Static style declaration value type mismatch");
399
400 if constexpr (std::same_as<decltype(value), Expected>) {
401 if constexpr (D::KIND == Property::FOREGROUND) {
402 destination.foreground = value;
403 } else if constexpr (D::KIND == Property::BACKGROUND) {
404 destination.background = value;
405 } else if constexpr (D::KIND == Property::BOLD) {
406 destination.bold = value;
407 } else if constexpr (D::KIND == Property::ITALIC) {
408 destination.italic = value;
409 } else if constexpr (D::KIND == Property::UNDERLINE) {
410 destination.underline = value;
411 } else if constexpr (D::KIND == Property::FRAME_LINE_FOREGROUND) {
412 destination.frameLine.foreground = value;
413 } else if constexpr (D::KIND == Property::FRAME_LINE_BACKGROUND) {
414 destination.frameLine.background = value;
415 } else if constexpr (D::KIND == Property::FRAME_LINE_BOLD) {
416 destination.frameLine.bold = value;
417 } else if constexpr (D::KIND == Property::FRAME_LINE_ITALIC) {
418 destination.frameLine.italic = value;
419 } else if constexpr (D::KIND == Property::FRAME_LINE_UNDERLINE) {
420 destination.frameLine.underline = value;
421 } else if constexpr (D::KIND == Property::FRAME_TITLE_FOREGROUND) {
422 destination.frameTitle.foreground = value;
423 } else if constexpr (D::KIND == Property::FRAME_TITLE_BACKGROUND) {
424 destination.frameTitle.background = value;
425 } else if constexpr (D::KIND == Property::FRAME_TITLE_BOLD) {
426 destination.frameTitle.bold = value;
427 } else if constexpr (D::KIND == Property::FRAME_TITLE_ITALIC) {
428 destination.frameTitle.italic = value;
429 } else if constexpr (D::KIND == Property::FRAME_TITLE_UNDERLINE) {
430 destination.frameTitle.underline = value;
431 } else if constexpr (D::KIND == Property::FRAME_ENDS_FOREGROUND) {
432 destination.frameEnds.foreground = value;
433 } else if constexpr (D::KIND == Property::FRAME_ENDS_BACKGROUND) {
434 destination.frameEnds.background = value;
435 } else if constexpr (D::KIND == Property::FRAME_ENDS_BOLD) {
436 destination.frameEnds.bold = value;
437 } else if constexpr (D::KIND == Property::FRAME_ENDS_ITALIC) {
438 destination.frameEnds.italic = value;
439 } else if constexpr (D::KIND == Property::FRAME_ENDS_UNDERLINE) {
440 destination.frameEnds.underline = value;
441 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_FOREGROUND) {
442 destination.scrollbarTrack.foreground = value;
443 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_BACKGROUND) {
444 destination.scrollbarTrack.background = value;
445 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_BOLD) {
446 destination.scrollbarTrack.bold = value;
447 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_ITALIC) {
448 destination.scrollbarTrack.italic = value;
449 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_UNDERLINE) {
450 destination.scrollbarTrack.underline = value;
451 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_FOREGROUND) {
452 destination.scrollbarThumb.foreground = value;
453 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BACKGROUND) {
454 destination.scrollbarThumb.background = value;
455 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BOLD) {
456 destination.scrollbarThumb.bold = value;
457 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_ITALIC) {
458 destination.scrollbarThumb.italic = value;
459 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_UNDERLINE) {
460 destination.scrollbarThumb.underline = value;
461 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_START_FOREGROUND) {
462 destination.scrollbarThumbStart.foreground = value;
463 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_START_BACKGROUND) {
464 destination.scrollbarThumbStart.background = value;
465 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_START_BOLD) {
466 destination.scrollbarThumbStart.bold = value;
467 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_START_ITALIC) {
468 destination.scrollbarThumbStart.italic = value;
469 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_START_UNDERLINE) {
470 destination.scrollbarThumbStart.underline = value;
471 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BODY_FOREGROUND) {
472 destination.scrollbarThumbBody.foreground = value;
473 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BODY_BACKGROUND) {
474 destination.scrollbarThumbBody.background = value;
475 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BODY_BOLD) {
476 destination.scrollbarThumbBody.bold = value;
477 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BODY_ITALIC) {
478 destination.scrollbarThumbBody.italic = value;
479 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_BODY_UNDERLINE) {
480 destination.scrollbarThumbBody.underline = value;
481 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_END_FOREGROUND) {
482 destination.scrollbarThumbEnd.foreground = value;
483 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_END_BACKGROUND) {
484 destination.scrollbarThumbEnd.background = value;
485 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_END_BOLD) {
486 destination.scrollbarThumbEnd.bold = value;
487 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_END_ITALIC) {
488 destination.scrollbarThumbEnd.italic = value;
489 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_END_UNDERLINE) {
490 destination.scrollbarThumbEnd.underline = value;
491 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_SINGLE_FOREGROUND) {
492 destination.scrollbarThumbSingle.foreground = value;
493 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_SINGLE_BACKGROUND) {
494 destination.scrollbarThumbSingle.background = value;
495 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_SINGLE_BOLD) {
496 destination.scrollbarThumbSingle.bold = value;
497 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_SINGLE_ITALIC) {
498 destination.scrollbarThumbSingle.italic = value;
499 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_SINGLE_UNDERLINE) {
500 destination.scrollbarThumbSingle.underline = value;
501 } else if constexpr (D::KIND == Property::SCROLLBAR_ENDS_FOREGROUND) {
502 destination.scrollbarEnds.foreground = value;
503 } else if constexpr (D::KIND == Property::SCROLLBAR_ENDS_BACKGROUND) {
504 destination.scrollbarEnds.background = value;
505 } else if constexpr (D::KIND == Property::SCROLLBAR_ENDS_BOLD) {
506 destination.scrollbarEnds.bold = value;
507 } else if constexpr (D::KIND == Property::SCROLLBAR_ENDS_ITALIC) {
508 destination.scrollbarEnds.italic = value;
509 } else if constexpr (D::KIND == Property::SCROLLBAR_ENDS_UNDERLINE) {
510 destination.scrollbarEnds.underline = value;
511 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROWS_FOREGROUND) {
512 destination.scrollbarArrows.foreground = value;
513 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROWS_BACKGROUND) {
514 destination.scrollbarArrows.background = value;
515 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROWS_BOLD) {
516 destination.scrollbarArrows.bold = value;
517 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROWS_ITALIC) {
518 destination.scrollbarArrows.italic = value;
519 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROWS_UNDERLINE) {
520 destination.scrollbarArrows.underline = value;
521 } else if constexpr (D::KIND == Property::SCROLLBAR_CORNER_FOREGROUND) {
522 destination.scrollbarCorner.foreground = value;
523 } else if constexpr (D::KIND == Property::SCROLLBAR_CORNER_BACKGROUND) {
524 destination.scrollbarCorner.background = value;
525 } else if constexpr (D::KIND == Property::SCROLLBAR_CORNER_BOLD) {
526 destination.scrollbarCorner.bold = value;
527 } else if constexpr (D::KIND == Property::SCROLLBAR_CORNER_ITALIC) {
528 destination.scrollbarCorner.italic = value;
529 } else if constexpr (D::KIND == Property::SCROLLBAR_CORNER_UNDERLINE) {
530 destination.scrollbarCorner.underline = value;
531 } else if constexpr (D::KIND == Property::SCROLLBAR_TRACK_PATTERN) {
532 destination.scrollbarTrackPattern = value;
533 } else if constexpr (D::KIND == Property::SCROLLBAR_THUMB_PATTERN) {
534 destination.scrollbarThumbPattern = value;
535 } else if constexpr (D::KIND == Property::SLIDER_TRACK_FOREGROUND) {
536 destination.sliderTrack.foreground = value;
537 } else if constexpr (D::KIND == Property::SLIDER_TRACK_BACKGROUND) {
538 destination.sliderTrack.background = value;
539 } else if constexpr (D::KIND == Property::SLIDER_TRACK_BOLD) {
540 destination.sliderTrack.bold = value;
541 } else if constexpr (D::KIND == Property::SLIDER_TRACK_ITALIC) {
542 destination.sliderTrack.italic = value;
543 } else if constexpr (D::KIND == Property::SLIDER_TRACK_UNDERLINE) {
544 destination.sliderTrack.underline = value;
545 } else if constexpr (D::KIND == Property::SLIDER_FILL_FOREGROUND) {
546 destination.sliderFill.foreground = value;
547 } else if constexpr (D::KIND == Property::SLIDER_FILL_BACKGROUND) {
548 destination.sliderFill.background = value;
549 } else if constexpr (D::KIND == Property::SLIDER_FILL_BOLD) {
550 destination.sliderFill.bold = value;
551 } else if constexpr (D::KIND == Property::SLIDER_FILL_ITALIC) {
552 destination.sliderFill.italic = value;
553 } else if constexpr (D::KIND == Property::SLIDER_FILL_UNDERLINE) {
554 destination.sliderFill.underline = value;
555 } else if constexpr (D::KIND == Property::SLIDER_THUMB_FOREGROUND) {
556 destination.sliderThumb.foreground = value;
557 } else if constexpr (D::KIND == Property::SLIDER_THUMB_BACKGROUND) {
558 destination.sliderThumb.background = value;
559 } else if constexpr (D::KIND == Property::SLIDER_THUMB_BOLD) {
560 destination.sliderThumb.bold = value;
561 } else if constexpr (D::KIND == Property::SLIDER_THUMB_ITALIC) {
562 destination.sliderThumb.italic = value;
563 } else if constexpr (D::KIND == Property::SLIDER_THUMB_UNDERLINE) {
564 destination.sliderThumb.underline = value;
565 } else if constexpr (D::KIND == Property::GLYPH_PROFILE) {
566 destination.glyphProfile = value;
567 } else if constexpr (D::KIND == Property::GLYPH_FALLBACK) {
568 destination.glyphFallback = value;
569 } else if constexpr (D::KIND == Property::SCROLLBAR_ARROW_PATTERN) {
570 destination.scrollbarArrowPattern = value;
571 } else if constexpr (METRIC) {
572 destination.minWidth = value;
573 }
574 }
575}
576
585template <class R, class P, class V>
586constexpr StyleDeclarations declarations(const R &rule, const P &parameters, const V &values) {
587 StyleDeclarations result{};
588 std::apply(
589 [&](const auto &...declaration) {
590 (assign(declaration, result, parameters, values), ...);
591 },
592 rule.declarations);
593
594 return result;
595}
596
602template <class R, class P> consteval void validateRule(const R &rule, const P &parameters) {
603 if (rule.selector.state < StyleState::ANY || rule.selector.state > StyleState::CARET) {
604 staticStyleInvalidState();
605 }
606
607 static_assert(uniqueDeclarations(decltype(rule.declarations){}), "Static style rule repeats a declaration");
608 const auto values = declarations(rule, parameters, parameters.defaults());
609
610 if ((values.glyphProfile &&
611 (*values.glyphProfile < GlyphProfile::DEFAULT || *values.glyphProfile > GlyphProfile::NF_BACKSLASH)) ||
612 (values.glyphFallback &&
613 (*values.glyphFallback < GlyphFallback::UNICODE_GLYPHS || *values.glyphFallback > GlyphFallback::ASCII)) ||
614 (values.scrollbarTrackPattern && (*values.scrollbarTrackPattern < ScrollbarPattern::LEGACY ||
615 *values.scrollbarTrackPattern > ScrollbarPattern::FRACTIONAL_BLOCK)) ||
616 (values.scrollbarThumbPattern && (*values.scrollbarThumbPattern < ScrollbarThumbPattern::LEGACY ||
617 *values.scrollbarThumbPattern > ScrollbarThumbPattern::FRACTIONAL_BLOCK)) ||
618 (values.scrollbarArrowPattern && (*values.scrollbarArrowPattern < ScrollbarArrowPattern::LEGACY ||
619 *values.scrollbarArrowPattern > ScrollbarArrowPattern::ASCII))) {
620 staticStyleInvalidScrollbarPattern();
621 }
622
623 if (values.minWidth && (*values.minWidth < 0 || rule.selector.state != StyleState::ANY || rule.selector.readOnly)) {
624 staticStyleInvalidMetric();
625 }
626}
627
632template <class P, class... R> class Sheet {
633public:
637 consteval Sheet(P parameters, R... rules) : parameters_(parameters), rules_(rules...) {
638 static_assert(sizeof...(R) <= MAX_STYLE_RULES, "Static style sheet exceeds the rule limit");
639 static_assert(uniqueParameters(P{}), "Static style parameter names must be nonempty and unique");
640 (validateRule(rules, parameters), ...);
641 }
642
644 constexpr const P &parameters() const noexcept {
645 return parameters_;
646 }
647
649 constexpr const std::tuple<R...> &rules() const noexcept {
650 return rules_;
651 }
652
653private:
654 P parameters_;
655 std::tuple<R...> rules_;
656};
657
661template <class T> struct IsSheet : std::false_type {};
662
666template <class T> struct IsSheet<const T> : IsSheet<T> {};
667
672template <class P, class... R> struct IsSheet<Sheet<P, R...>> : std::true_type {};
673
678template <Literal Name, class T> struct Change {
679 static constexpr auto NAME = Name;
681};
682
686template <class... C> consteval bool uniqueChanges() {
687 constexpr std::array<std::string_view, sizeof...(C)> NAMES{C::NAME.view()...};
688
689 for (std::size_t index = 0; index < NAMES.size(); ++index) {
690 for (std::size_t other = index + 1; other < NAMES.size(); ++other) {
691 if (NAMES[index] == NAMES[other]) {
692 return false;
693 }
694 }
695 }
696
697 return true;
698}
699
701struct Access {
705 static std::weak_ptr<const void> lifetime(ManagedScene &scene) {
706 return scene.lifetime_;
707 }
708
712 static std::thread::id owner(ManagedScene &scene) {
713 return scene.owner_;
714 }
715
719 static std::expected<void, ManagedError> boundary(ManagedScene &scene) {
720 return scene.boundary(ManagedPhase::STYLE, scene.root_);
721 }
722
726 static bool pending(ManagedScene &scene) noexcept {
727 return scene.stylesDirty_;
728 }
729
734 return scene.captureThemeLease();
735 }
736
741 static std::expected<void, ManagedError> checkLease(ManagedScene &scene, portals::detail::StyleThemeLease lease) {
742 return scene.checkThemeLease(lease);
743 }
744
751 return scene.attachTheme(sheet, lease);
752 }
753
760 return scene.applyTheme(sheet, lease);
761 }
762};
763
768inline ManagedError error(NodeId node, TreeError cause) {
769 return {ManagedPhase::STYLE, node, cause, {}, {}};
770}
771} // namespace detail
772
779consteval RgbColor rgb(std::int32_t red, std::int32_t green, std::int32_t blue) {
780 constexpr std::int32_t MAX_COMPONENT = 255;
781
782 if (red < 0 || green < 0 || blue < 0 || red > MAX_COMPONENT || green > MAX_COMPONENT || blue > MAX_COMPONENT) {
783 detail::staticStyleInvalidRgb();
784 }
785
786 return {static_cast<std::uint8_t>(red), static_cast<std::uint8_t>(green), static_cast<std::uint8_t>(blue)};
787}
788
794template <detail::Literal Name, detail::ParameterValue T> consteval auto parameter(T initial) {
795 return detail::Parameter<Name, T>{initial};
796}
797
802template <class... P>
803 requires(detail::IsParameter<P>::value && ...)
804consteval auto parameters(P... entries) {
805 static_assert(detail::uniqueParameters(detail::Parameters<P...>{}),
806 "Static style parameter names must be nonempty and unique");
807
808 return detail::Parameters<P...>{{entries...}};
809}
810
814template <detail::Literal Name> consteval auto token() {
815 return detail::Token<Name>{};
816}
817
826template <class Left, class Right> consteval auto mix(Left left, Right right, std::int32_t percentage) {
827 constexpr std::int32_t FULL_PERCENTAGE = 100;
828
829 if (percentage < 0 || percentage > FULL_PERCENTAGE) {
830 detail::staticStyleInvalidMix();
831 }
832
833 return detail::Mix<Left, Right>{left, right, percentage};
834}
835
843template <detail::Literal Type = "", detail::Literal Id = "", detail::Literal... Classes>
844consteval auto selector(StyleState state = StyleState::ANY, bool readOnly = false) {
845 if (state < StyleState::ANY || state > StyleState::CARET) {
846 detail::staticStyleInvalidState();
847 }
848
849 return detail::Selector<Type, Id, Classes...>{state, readOnly};
850}
851
856consteval auto all(StyleState state = StyleState::ANY, bool readOnly = false) {
857 return selector<>(state, readOnly);
858}
859
865template <detail::Literal Name> consteval auto id(StyleState state = StyleState::ANY, bool readOnly = false) {
866 static_assert(portals::detail::isPssIdentifier(Name.view()), "Static style ID requires a PSS ASCII identifier");
867
868 return selector<"", Name>(state, readOnly);
869}
870
876template <detail::Literal Name> consteval auto type(StyleState state = StyleState::ANY, bool readOnly = false) {
877 static_assert(Name.view() == "*" || portals::detail::isPssIdentifier(Name.view()),
878 "Static style type requires a PSS ASCII identifier or universal '*'");
879
880 return selector<Name>(state, readOnly);
881}
882
888template <detail::Literal Name> consteval auto className(StyleState state = StyleState::ANY, bool readOnly = false) {
889 static_assert(portals::detail::isPssIdentifier(Name.view()), "Static style class requires a PSS ASCII identifier");
890
891 return selector<"", "", Name>(state, readOnly);
892}
893
898template <class E> consteval auto foreground(E expression) {
900}
901
906template <class E> consteval auto background(E expression) {
908}
909
914template <class E> consteval auto fg(E expression) {
915 return foreground(expression);
916}
917
922template <class E> consteval auto bg(E expression) {
923 return background(expression);
924}
925
930template <class E> consteval auto bold(E expression) {
932}
933
938template <class E> consteval auto italic(E expression) {
940}
941
946template <class E> consteval auto underline(E expression) {
948}
949
954template <class E> consteval auto minWidth(E expression) {
956}
957
959template <class E> consteval auto frameLineForeground(E expression) {
961}
962
964template <class E> consteval auto frameLineBackground(E expression) {
966}
967
969template <class E> consteval auto frameLineBold(E expression) {
971}
972
974template <class E> consteval auto frameLineItalic(E expression) {
976}
977
979template <class E> consteval auto frameLineUnderline(E expression) {
981}
982
984template <class E> consteval auto frameTitleForeground(E expression) {
986}
987
989template <class E> consteval auto frameTitleBackground(E expression) {
991}
992
994template <class E> consteval auto frameTitleBold(E expression) {
996}
997
999template <class E> consteval auto frameTitleItalic(E expression) {
1001}
1002
1004template <class E> consteval auto frameTitleUnderline(E expression) {
1006}
1007
1009template <class E> consteval auto frameEndsForeground(E expression) {
1011}
1012
1014template <class E> consteval auto frameEndsBackground(E expression) {
1016}
1017
1019template <class E> consteval auto frameEndsBold(E expression) {
1021}
1022
1024template <class E> consteval auto frameEndsItalic(E expression) {
1026}
1027
1029template <class E> consteval auto frameEndsUnderline(E expression) {
1031}
1032
1034template <class E> consteval auto scrollbarTrackPattern(E expression) {
1036}
1037
1039template <class E> consteval auto glyphProfile(E expression) {
1041}
1042
1044template <class E> consteval auto glyphFallback(E expression) {
1046}
1047
1049template <class E> consteval auto scrollbarThumbPattern(E expression) {
1051}
1052
1054template <class E> consteval auto scrollbarArrowPattern(E expression) {
1056}
1057
1059template <class E> consteval auto scrollbarTrackForeground(E expression) {
1061}
1062
1064template <class E> consteval auto scrollbarTrackBackground(E expression) {
1066}
1067
1069template <class E> consteval auto scrollbarTrackBold(E expression) {
1071}
1072
1074template <class E> consteval auto scrollbarTrackItalic(E expression) {
1076}
1077
1079template <class E> consteval auto scrollbarTrackUnderline(E expression) {
1081}
1082
1084template <class E> consteval auto scrollbarThumbForeground(E expression) {
1086}
1087
1089template <class E> consteval auto scrollbarThumbBackground(E expression) {
1091}
1092
1094template <class E> consteval auto scrollbarThumbBold(E expression) {
1096}
1097
1099template <class E> consteval auto scrollbarThumbItalic(E expression) {
1101}
1102
1104template <class E> consteval auto scrollbarThumbUnderline(E expression) {
1106}
1107
1109template <class E> consteval auto scrollbarThumbStartForeground(E expression) {
1111}
1112
1114template <class E> consteval auto scrollbarThumbStartBackground(E expression) {
1116}
1117
1119template <class E> consteval auto scrollbarThumbStartBold(E expression) {
1121}
1122
1124template <class E> consteval auto scrollbarThumbStartItalic(E expression) {
1126}
1127
1129template <class E> consteval auto scrollbarThumbStartUnderline(E expression) {
1131}
1132
1134template <class E> consteval auto scrollbarThumbBodyForeground(E expression) {
1136}
1137
1139template <class E> consteval auto scrollbarThumbBodyBackground(E expression) {
1141}
1142
1144template <class E> consteval auto scrollbarThumbBodyBold(E expression) {
1146}
1147
1149template <class E> consteval auto scrollbarThumbBodyItalic(E expression) {
1151}
1152
1154template <class E> consteval auto scrollbarThumbBodyUnderline(E expression) {
1156}
1157
1159template <class E> consteval auto scrollbarThumbEndForeground(E expression) {
1161}
1162
1164template <class E> consteval auto scrollbarThumbEndBackground(E expression) {
1166}
1167
1169template <class E> consteval auto scrollbarThumbEndBold(E expression) {
1171}
1172
1174template <class E> consteval auto scrollbarThumbEndItalic(E expression) {
1176}
1177
1179template <class E> consteval auto scrollbarThumbEndUnderline(E expression) {
1181}
1182
1184template <class E> consteval auto scrollbarThumbSingleForeground(E expression) {
1186}
1187
1189template <class E> consteval auto scrollbarThumbSingleBackground(E expression) {
1191}
1192
1194template <class E> consteval auto scrollbarThumbSingleBold(E expression) {
1196}
1197
1199template <class E> consteval auto scrollbarThumbSingleItalic(E expression) {
1201}
1202
1204template <class E> consteval auto scrollbarThumbSingleUnderline(E expression) {
1206}
1207
1209template <class E> consteval auto sliderTrackForeground(E expression) {
1211}
1212
1214template <class E> consteval auto sliderTrackBackground(E expression) {
1216}
1217
1219template <class E> consteval auto sliderTrackBold(E expression) {
1221}
1222
1224template <class E> consteval auto sliderTrackItalic(E expression) {
1226}
1227
1229template <class E> consteval auto sliderTrackUnderline(E expression) {
1231}
1232
1234template <class E> consteval auto sliderFillForeground(E expression) {
1236}
1237
1239template <class E> consteval auto sliderFillBackground(E expression) {
1241}
1242
1244template <class E> consteval auto sliderFillBold(E expression) {
1246}
1247
1249template <class E> consteval auto sliderFillItalic(E expression) {
1251}
1252
1254template <class E> consteval auto sliderFillUnderline(E expression) {
1256}
1257
1259template <class E> consteval auto sliderThumbForeground(E expression) {
1261}
1262
1264template <class E> consteval auto sliderThumbBackground(E expression) {
1266}
1267
1269template <class E> consteval auto sliderThumbBold(E expression) {
1271}
1272
1274template <class E> consteval auto sliderThumbItalic(E expression) {
1276}
1277
1279template <class E> consteval auto sliderThumbUnderline(E expression) {
1281}
1282
1284template <class E> consteval auto scrollbarEndsForeground(E expression) {
1286}
1287
1289template <class E> consteval auto scrollbarEndsBackground(E expression) {
1291}
1292
1294template <class E> consteval auto scrollbarEndsBold(E expression) {
1296}
1297
1299template <class E> consteval auto scrollbarEndsItalic(E expression) {
1301}
1302
1304template <class E> consteval auto scrollbarEndsUnderline(E expression) {
1306}
1307
1309template <class E> consteval auto scrollbarArrowsForeground(E expression) {
1311}
1312
1314template <class E> consteval auto scrollbarArrowsBackground(E expression) {
1316}
1317
1319template <class E> consteval auto scrollbarArrowsBold(E expression) {
1321}
1322
1324template <class E> consteval auto scrollbarArrowsItalic(E expression) {
1326}
1327
1329template <class E> consteval auto scrollbarArrowsUnderline(E expression) {
1331}
1332
1334template <class E> consteval auto scrollbarCornerForeground(E expression) {
1336}
1337
1339template <class E> consteval auto scrollbarCornerBackground(E expression) {
1341}
1342
1344template <class E> consteval auto scrollbarCornerBold(E expression) {
1346}
1347
1349template <class E> consteval auto scrollbarCornerItalic(E expression) {
1351}
1352
1354template <class E> consteval auto scrollbarCornerUnderline(E expression) {
1356}
1357
1364template <class S, class... D>
1365 requires(detail::IsDeclaration<D>::value && ...)
1366consteval auto rule(S target, D... declarations) {
1367 static_assert(detail::uniqueDeclarations(std::tuple<D...>{}), "Static style rule repeats a declaration");
1368
1369 return detail::Rule<S, D...>{target, {declarations...}};
1370}
1371
1378template <class P, class... R>
1379 requires(detail::IsRule<R>::value && ...)
1380consteval auto sheet(P values, R... rules) {
1381 static_assert(sizeof...(R) <= MAX_STYLE_RULES, "Static style sheet exceeds the rule limit");
1382
1383 if constexpr (sizeof...(R) <= MAX_STYLE_RULES) {
1384 return detail::Sheet<P, R...>(values, rules...);
1385 }
1386}
1387
1396template <class... P, class... R>
1397 requires(detail::IsRule<R>::value && ...)
1398consteval auto themeFromTokens(ThemeTokens defaults, detail::Parameters<P...> extraParameters = {}, R... extraRules) {
1399 static_cast<void>(extraParameters); // An empty parameter pack otherwise leaves no expression using this argument.
1400
1401 return sheet(
1402 parameters(parameter<"foreground">(defaults.foreground), parameter<"background">(defaults.background),
1403 parameter<"accent">(defaults.accent), parameter<"muted">(defaults.muted),
1404 parameter<"selection">(defaults.selection), parameter<"heading">(defaults.heading),
1405 std::get<P>(extraParameters.entries)...),
1418 scrollbarCornerBold(true)),
1421 bold(true), italic(false)),
1426 bold(false), italic(false), underline(false)),
1439 extraRules...);
1440}
1441
1442namespace detail {
1449template <class S, class V> StyleSheet materializeValues(const S &description, const V &values) {
1450 StyleSheet result;
1451 result.rules.reserve(std::tuple_size_v<std::remove_cvref_t<decltype(description.rules())>>);
1452 std::apply(
1453 [&](const auto &...rule) {
1454 if constexpr (sizeof...(rule) > 0) {
1455 const auto append = [&](const auto &source) {
1456 using SelectorType = std::remove_cvref_t<decltype(source.selector)>;
1457 StyleRule target;
1458 target.selector.type = SelectorType::TYPE.view();
1459 target.selector.id = SelectorType::ID.view();
1460 target.selector.state = source.selector.state;
1461 target.selector.readOnly = source.selector.readOnly;
1462 target.selector.classes.reserve(SelectorType::CLASS_NAMES.size());
1463
1464 for (const auto name : SelectorType::CLASS_NAMES) {
1465 target.selector.classes.emplace_back(name);
1466 }
1467
1468 target.declarations = declarations(source, description.parameters(), values);
1469 result.rules.push_back(std::move(target));
1470 };
1471 (append(rule), ...);
1472 }
1473 },
1474 description.rules());
1475
1476 return result;
1477}
1478} // namespace detail
1479
1485template <class S>
1487StyleSheet materialize(const S &description) {
1488 return detail::materializeValues(description, description.parameters().defaults());
1489}
1490
1496template <detail::Literal Name, class T> auto change(T value) {
1497 return detail::Change<Name, T>{value};
1498}
1499
1508template <class S>
1509 requires detail::IsSheet<S>::value
1511 using Values = decltype(std::declval<S>().parameters().defaults());
1512
1513 struct State {
1514 S description;
1515 Values values;
1516 ManagedScene *scene;
1517 std::weak_ptr<const void> lifetime;
1518 std::thread::id owner;
1519 NodeId root;
1521 bool applying{};
1522 };
1523
1524public:
1526 LiveTheme() = default;
1527
1533 static std::expected<LiveTheme, ManagedError> attach(ManagedScene &scene, const S &description) {
1534 auto allowed = detail::Access::boundary(scene);
1535
1536 if (!allowed) {
1537 return std::unexpected(allowed.error());
1538 }
1539
1540 const auto root = scene.root().id();
1541 const auto lifetime = detail::Access::lifetime(scene);
1542 const auto owner = detail::Access::owner(scene);
1543 const auto lease = detail::Access::lease(scene);
1544
1545 try {
1546 LiveTheme result;
1547 result.state_ =
1548 std::make_shared<State>(description, description.parameters().defaults(), &scene, lifetime, owner, root, lease);
1549 auto sheet = detail::materializeValues(result.state_->description, result.state_->values);
1550 allowed = boundary(result.state_);
1551
1552 if (!allowed) {
1553 return std::unexpected(allowed.error());
1554 }
1555
1556 auto installed = detail::Access::attachTheme(*result.state_->scene, sheet, result.state_->lease);
1557
1558 if (!installed) {
1559 return std::unexpected(installed.error());
1560 }
1561
1562 result.state_->lease = *installed;
1563 return result;
1564 } catch (const std::bad_alloc &) {
1565 return std::unexpected(detail::error(root, TreeError::NO_MEMORY));
1566 }
1567 }
1568
1572 template <detail::Literal Name> auto get() const {
1573 constexpr auto INDEX = index<Name>();
1574 using Value = std::tuple_element_t<INDEX, Values>;
1575 std::expected<Value, ManagedError> result;
1576 const auto state = state_;
1577 auto allowed = boundary(state);
1578
1579 if (!allowed) {
1580 return decltype(result)(std::unexpected(allowed.error()));
1581 }
1582
1583 return decltype(result)(std::get<INDEX>(state->values));
1584 }
1585
1591 template <detail::Literal Name, class T> std::expected<bool, ManagedError> set(T value) const {
1592 return apply(change<Name>(value));
1593 }
1594
1602 template <class... C> std::expected<bool, ManagedError> apply(C... changes) const {
1603 static_assert(detail::uniqueChanges<C...>(), "Static style update repeats a parameter");
1604 const auto state = state_; // A hook may destroy or replace the calling handle during style staging.
1605 auto allowed = boundary(state);
1606
1607 if (!allowed) {
1608 return std::unexpected(allowed.error());
1609 }
1610
1611 auto candidate = state->values;
1612 (update(candidate, changes), ...);
1613
1614 const bool changed = candidate != state->values;
1615 if (!changed && (!state->lease.layered || !detail::Access::pending(*state->scene))) {
1616 return false;
1617 }
1618
1619 struct Guard {
1620 State &state;
1621
1622 explicit Guard(State &value) : state(value) {
1623 state.applying = true;
1624 }
1625
1626 ~Guard() {
1627 state.applying = false;
1628 }
1629 } guard(*state);
1630
1631 try {
1632 auto sheet = detail::materializeValues(state->description, candidate);
1633 allowed = boundary(state, true);
1634
1635 if (!allowed) {
1636 return std::unexpected(allowed.error());
1637 }
1638
1639 auto installed = detail::Access::applyTheme(*state->scene, sheet, state->lease);
1640
1641 if (!installed) {
1642 return std::unexpected(installed.error());
1643 }
1644
1645 state->values = candidate;
1646
1647 return changed;
1648 } catch (const std::bad_alloc &) {
1649 return std::unexpected(detail::error(state->root, TreeError::NO_MEMORY));
1650 }
1651 }
1652
1653private:
1654 template <detail::Literal Name> static consteval std::size_t index() {
1655 using P = std::remove_cvref_t<decltype(std::declval<S>().parameters())>;
1656 constexpr auto INDEX = detail::parameterIndex<Name>(P{});
1657 static_assert(INDEX < std::tuple_size_v<Values>, "Static style update requires a known parameter");
1658
1659 return INDEX;
1660 }
1661
1662 template <class C> static void update(Values &values, const C &change) {
1663 constexpr auto INDEX = index<C::NAME>();
1664 using Value = std::tuple_element_t<INDEX, Values>;
1665 static_assert(std::same_as<decltype(change.value), Value>, "Static style update value type mismatch");
1666
1667 if constexpr (std::same_as<decltype(change.value), Value>) {
1668 std::get<INDEX>(values) = change.value;
1669 }
1670 }
1671
1672 static std::expected<void, ManagedError> boundary(const std::shared_ptr<State> &state, bool completing = false) {
1673 if (!state) {
1674 return std::unexpected(detail::error({}, TreeError::CLOSED));
1675 }
1676
1677 // UI identity is checked before the raw observer or weak token can touch the scene.
1678 if (state->owner != std::this_thread::get_id()) {
1679 return std::unexpected(detail::error(state->root, TreeError::WRONG_THREAD));
1680 }
1681
1682 if (state->lifetime.expired()) {
1683 return std::unexpected(detail::error(state->root, TreeError::CLOSED));
1684 }
1685
1686 if (state->applying && !completing) {
1687 return std::unexpected(detail::error(state->root, TreeError::WOULD_BLOCK));
1688 }
1689
1690 return detail::Access::checkLease(*state->scene, state->lease);
1691 }
1692
1693 std::shared_ptr<State> state_;
1694};
1695
1701template <class S>
1703auto live(ManagedScene &scene, const S &description) {
1704 return LiveTheme<S>::attach(scene, description);
1705}
1706} // namespace portals::style::ct
Additive lifecycle owner over one existing Application subtree. UI affine and nonmovable....
Definition managed.hpp:530
std::expected< bool, ManagedError > set(T value) const
Definition style_static.hpp:1591
auto get() const
Definition style_static.hpp:1572
static std::expected< LiveTheme, ManagedError > attach(ManagedScene &scene, const S &description)
Definition style_static.hpp:1533
std::expected< bool, ManagedError > apply(C... changes) const
Definition style_static.hpp:1602
LiveTheme()=default
Construct an empty observer; operations return CLOSED.
Immutable owning parameter/rule description returned by sheet().
Definition style_static.hpp:632
constexpr const P & parameters() const noexcept
Definition style_static.hpp:644
consteval Sheet(P parameters, R... rules)
Definition style_static.hpp:637
constexpr const std::tuple< R... > & rules() const noexcept
Definition style_static.hpp:649
Scalar types with nonthrowing ownership and equality.
Definition style_static.hpp:30
Owning compile-time PSS v0 snapshots using the existing runtime cascade.
Definition pss_compact.hpp:8
consteval auto sliderTrackUnderline(E expression)
Definition style_static.hpp:1229
consteval auto sliderFillUnderline(E expression)
Definition style_static.hpp:1254
consteval auto scrollbarArrowsBackground(E expression)
Definition style_static.hpp:1314
StyleSheet materialize(const CompactSheet< R, C, D, B > &description)
Definition style_pss.hpp:362
consteval auto scrollbarThumbEndBackground(E expression)
Definition style_static.hpp:1164
consteval auto scrollbarThumbStartUnderline(E expression)
Definition style_static.hpp:1129
consteval auto frameLineBackground(E expression)
Definition style_static.hpp:964
consteval auto sliderThumbItalic(E expression)
Definition style_static.hpp:1274
consteval auto frameEndsItalic(E expression)
Definition style_static.hpp:1024
consteval auto frameEndsUnderline(E expression)
Definition style_static.hpp:1029
consteval auto frameTitleForeground(E expression)
Definition style_static.hpp:984
consteval auto foreground(E expression)
Definition style_static.hpp:898
consteval auto scrollbarCornerForeground(E expression)
Definition style_static.hpp:1334
consteval auto scrollbarThumbEndBold(E expression)
Definition style_static.hpp:1169
consteval auto frameLineBold(E expression)
Definition style_static.hpp:969
consteval auto scrollbarThumbBodyBackground(E expression)
Definition style_static.hpp:1139
consteval auto sliderThumbUnderline(E expression)
Definition style_static.hpp:1279
consteval auto frameLineForeground(E expression)
Definition style_static.hpp:959
consteval auto scrollbarThumbSingleForeground(E expression)
Definition style_static.hpp:1184
consteval auto sliderFillItalic(E expression)
Definition style_static.hpp:1249
consteval auto scrollbarThumbBackground(E expression)
Definition style_static.hpp:1089
consteval auto scrollbarThumbSingleBackground(E expression)
Definition style_static.hpp:1189
consteval auto scrollbarCornerUnderline(E expression)
Definition style_static.hpp:1354
consteval auto frameEndsBold(E expression)
Definition style_static.hpp:1019
consteval auto bg(E expression)
Definition style_static.hpp:922
consteval auto sliderTrackBackground(E expression)
Definition style_static.hpp:1214
consteval auto scrollbarEndsForeground(E expression)
Definition style_static.hpp:1284
consteval auto sliderFillBackground(E expression)
Definition style_static.hpp:1239
consteval auto glyphFallback(E expression)
Definition style_static.hpp:1044
consteval auto parameters(P... entries)
Definition style_static.hpp:804
consteval auto scrollbarThumbPattern(E expression)
Definition style_static.hpp:1049
consteval auto bold(E expression)
Definition style_static.hpp:930
consteval auto sliderThumbForeground(E expression)
Definition style_static.hpp:1259
consteval auto scrollbarThumbBodyForeground(E expression)
Definition style_static.hpp:1134
consteval auto minWidth(E expression)
Definition style_static.hpp:954
consteval auto scrollbarArrowsItalic(E expression)
Definition style_static.hpp:1324
consteval auto fg(E expression)
Definition style_static.hpp:914
consteval auto scrollbarEndsItalic(E expression)
Definition style_static.hpp:1299
consteval auto scrollbarThumbStartBold(E expression)
Definition style_static.hpp:1119
consteval auto scrollbarEndsBold(E expression)
Definition style_static.hpp:1294
consteval auto scrollbarTrackUnderline(E expression)
Definition style_static.hpp:1079
consteval auto scrollbarTrackForeground(E expression)
Definition style_static.hpp:1059
consteval auto sheet(P values, R... rules)
Definition style_static.hpp:1380
consteval auto underline(E expression)
Definition style_static.hpp:946
consteval auto scrollbarThumbBold(E expression)
Definition style_static.hpp:1094
consteval auto id(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:865
consteval auto background(E expression)
Definition style_static.hpp:906
consteval auto frameLineItalic(E expression)
Definition style_static.hpp:974
consteval auto frameEndsForeground(E expression)
Definition style_static.hpp:1009
consteval auto scrollbarThumbBodyBold(E expression)
Definition style_static.hpp:1144
consteval auto selector(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:844
consteval auto rule(S target, D... declarations)
Definition style_static.hpp:1366
consteval auto frameTitleItalic(E expression)
Definition style_static.hpp:999
consteval auto mix(Left left, Right right, std::int32_t percentage)
Blend colors using integral components, rounding down.
Definition style_static.hpp:826
consteval auto scrollbarThumbItalic(E expression)
Definition style_static.hpp:1099
consteval auto frameEndsBackground(E expression)
Definition style_static.hpp:1014
consteval auto scrollbarThumbUnderline(E expression)
Definition style_static.hpp:1104
consteval auto parameter(T initial)
Definition style_static.hpp:794
consteval auto scrollbarThumbBodyItalic(E expression)
Definition style_static.hpp:1149
consteval auto frameTitleBold(E expression)
Definition style_static.hpp:994
consteval auto scrollbarArrowPattern(E expression)
Definition style_static.hpp:1054
consteval auto scrollbarThumbEndUnderline(E expression)
Definition style_static.hpp:1179
consteval auto token()
Definition style_static.hpp:814
consteval auto frameTitleUnderline(E expression)
Definition style_static.hpp:1004
consteval auto scrollbarEndsBackground(E expression)
Definition style_static.hpp:1289
consteval auto sliderThumbBold(E expression)
Definition style_static.hpp:1269
consteval auto sliderThumbBackground(E expression)
Definition style_static.hpp:1264
consteval auto sliderFillForeground(E expression)
Definition style_static.hpp:1234
auto live(ManagedScene &scene, const S &description)
Definition style_static.hpp:1703
consteval auto scrollbarTrackItalic(E expression)
Definition style_static.hpp:1074
consteval auto scrollbarThumbStartBackground(E expression)
Definition style_static.hpp:1114
consteval auto scrollbarThumbBodyUnderline(E expression)
Definition style_static.hpp:1154
consteval auto scrollbarCornerBackground(E expression)
Definition style_static.hpp:1339
consteval auto scrollbarTrackPattern(E expression)
Definition style_static.hpp:1034
consteval RgbColor rgb(std::int32_t red, std::int32_t green, std::int32_t blue)
Validate and construct a constant RGB value without narrowing first.
Definition style_static.hpp:779
consteval auto themeFromTokens(ThemeTokens defaults, detail::Parameters< P... > extraParameters={}, R... extraRules)
Constant counterpart of portals::themeFromTokens with live named color parameters.
Definition style_static.hpp:1398
consteval auto scrollbarTrackBold(E expression)
Definition style_static.hpp:1069
consteval auto scrollbarThumbStartForeground(E expression)
Definition style_static.hpp:1109
consteval auto sliderFillBold(E expression)
Definition style_static.hpp:1244
consteval auto sliderTrackForeground(E expression)
Definition style_static.hpp:1209
consteval auto scrollbarThumbSingleItalic(E expression)
Definition style_static.hpp:1199
consteval auto italic(E expression)
Definition style_static.hpp:938
consteval auto scrollbarThumbForeground(E expression)
Definition style_static.hpp:1084
consteval auto scrollbarCornerBold(E expression)
Definition style_static.hpp:1344
consteval auto scrollbarArrowsForeground(E expression)
Definition style_static.hpp:1309
consteval auto scrollbarThumbSingleUnderline(E expression)
Definition style_static.hpp:1204
auto change(T value)
Definition style_static.hpp:1496
consteval auto sliderTrackBold(E expression)
Definition style_static.hpp:1219
consteval auto scrollbarTrackBackground(E expression)
Definition style_static.hpp:1064
consteval auto glyphProfile(E expression)
Definition style_static.hpp:1039
consteval auto scrollbarArrowsBold(E expression)
Definition style_static.hpp:1319
consteval auto sliderTrackItalic(E expression)
Definition style_static.hpp:1224
consteval auto className(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:888
consteval auto type(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:876
consteval auto scrollbarEndsUnderline(E expression)
Definition style_static.hpp:1304
consteval auto scrollbarCornerItalic(E expression)
Definition style_static.hpp:1349
consteval auto scrollbarThumbStartItalic(E expression)
Definition style_static.hpp:1124
consteval auto frameLineUnderline(E expression)
Definition style_static.hpp:979
consteval auto frameTitleBackground(E expression)
Definition style_static.hpp:989
consteval auto scrollbarArrowsUnderline(E expression)
Definition style_static.hpp:1329
consteval auto scrollbarThumbEndItalic(E expression)
Definition style_static.hpp:1174
consteval auto scrollbarThumbSingleBold(E expression)
Definition style_static.hpp:1194
consteval auto all(StyleState state=StyleState::ANY, bool readOnly=false)
Definition style_static.hpp:856
consteval auto scrollbarThumbEndForeground(E expression)
Definition style_static.hpp:1159
ScrollbarThumbPattern
Independent thumb source; all choices are opt-in.
Definition scrollbar_skin.hpp:24
@ LEGACY
Existing repeated thumb, including ASCII fallback.
Definition scrollbar_skin.hpp:25
@ FRACTIONAL_BLOCK
Eighth-cell block placement; requires a blank track and no custom thumb shapes.
Definition scrollbar_skin.hpp:28
ScrollbarPattern
Opt-in scrollbar glyph presets; legacy calls retain their original appearance.
Definition scrollbar_skin.hpp:15
@ LEGACY
Existing shaded track and block thumb.
Definition scrollbar_skin.hpp:16
@ FRACTIONAL_BLOCK
Blank track and eighth-cell block placement; explicit leaves keep priority.
Definition scrollbar_skin.hpp:20
@ STYLE
Register or apply styles, including a theme change.
Definition managed_diagnostics.hpp:52
GlyphProfile
Explicit glyph map, independent of colors and geometry. NF maps use Nerd Fonts 3 Powerline codepoints...
Definition glyph_profile.hpp:12
@ DEFAULT
Preserve the control's existing glyph sources.
Definition glyph_profile.hpp:13
@ NF_BACKSLASH
Powerline backslash horizontal caps, Unicode vertical inset caps.
Definition glyph_profile.hpp:19
GlyphFallback
Portable replacement when the selected map fails one-cell admission.
Definition glyph_profile.hpp:23
@ UNICODE_GLYPHS
Unicode replacement, with ASCII when Unicode is not one cell.
Definition glyph_profile.hpp:24
@ ASCII
ASCII replacement; also selects ASCII vertical caps for NF maps.
Definition glyph_profile.hpp:25
StyleState
Presentation states; ANY matches every state without changing behavior.
Definition style.hpp:26
@ DISABLED
Synchronized control ineligibility.
Definition style.hpp:30
@ FOCUSED
Synchronized control focus.
Definition style.hpp:29
@ CARET
Editor software caret.
Definition style.hpp:33
@ HEADER
Fixed table heading.
Definition style.hpp:32
@ ANY
Match all presentation variants.
Definition style.hpp:27
@ SELECTED
Selected row or editor range.
Definition style.hpp:31
constexpr std::size_t MAX_STYLE_RULES
Finite typed/PSS rule budget.
Definition style.hpp:302
ScrollbarArrowPattern
Independent functional-arrow source; selecting it never enables buttons.
Definition scrollbar_skin.hpp:32
@ LEGACY
Existing functional arrow source.
Definition scrollbar_skin.hpp:33
@ ASCII
Less-than, greater-than, caret and lowercase v.
Definition scrollbar_skin.hpp:35
TreeError
Checked tree failures; rejected operations never start the requested callback.
Definition widget_types.hpp:26
@ CLOSED
The owning tree or source is closed.
Definition widget_types.hpp:31
@ WRONG_THREAD
Operation requires the tree's UI thread.
Definition widget_types.hpp:28
@ WOULD_BLOCK
The current frame/reentry boundary or finite queue/work budget rejects this operation.
Definition widget_types.hpp:32
@ NO_MEMORY
Allocation failed inside the operation boundary.
Definition widget_types.hpp:33
Original error plus independent runner/restoration and cleanup failures.
Definition managed_diagnostics.hpp:62
Owning identity, independent of addresses; zero is never a live identity.
Definition widget_types.hpp:15
Owning RGB color; terminal encoding belongs to the output adapter.
Definition cell_buffer.hpp:20
One owned selector/declaration pair in source order.
Definition style.hpp:205
StyleSelector selector
Matching and specificity criteria.
Definition style.hpp:211
std::string type
Empty or * means any type.
Definition style.hpp:68
Owned immutable-at-use rules; constructing typed values may allocate and throw.
Definition style.hpp:233
std::vector< StyleRule > rules
Source-order rules, at most MAX_STYLE_RULES when installed.
Definition style.hpp:239
Typed palette tokens for the built-in theme factories.
Definition style.hpp:347
Private captured theme authority, including legacy epoch admission.
Definition style.hpp:293
Private bridge reusing managed lifetime, affinity and mutation boundaries.
Definition style_static.hpp:701
static bool pending(ManagedScene &scene) noexcept
Definition style_static.hpp:726
static auto attachTheme(ManagedScene &scene, const StyleSheet &sheet, portals::detail::StyleThemeLease lease)
Definition style_static.hpp:750
static portals::detail::StyleThemeLease lease(ManagedScene &scene)
Definition style_static.hpp:733
static std::expected< void, ManagedError > checkLease(ManagedScene &scene, portals::detail::StyleThemeLease lease)
Definition style_static.hpp:741
static auto applyTheme(ManagedScene &scene, const StyleSheet &sheet, portals::detail::StyleThemeLease lease)
Definition style_static.hpp:759
static std::expected< void, ManagedError > boundary(ManagedScene &scene)
Definition style_static.hpp:719
static std::weak_ptr< const void > lifetime(ManagedScene &scene)
Definition style_static.hpp:705
static std::thread::id owner(ManagedScene &scene)
Definition style_static.hpp:712
Internal owning named update member.
Definition style_static.hpp:678
T value
Candidate scalar.
Definition style_static.hpp:680
static constexpr auto NAME
Owning update identity.
Definition style_static.hpp:679
Internal typed owning declaration.
Definition style_static.hpp:249
Expression expression
Owned value expression.
Definition style_static.hpp:251
static constexpr auto KIND
Destination identity.
Definition style_static.hpp:250
Recognize internal declaration types.
Definition style_static.hpp:302
Recognize internal parameter types.
Definition style_static.hpp:313
Recognize internal rule types.
Definition style_static.hpp:291
Recognize validated owning sheet types.
Definition style_static.hpp:661
constexpr std::string_view view() const noexcept
Definition ui_static.hpp:31
Internal acyclic color blend expression.
Definition style_static.hpp:70
Right right
Owned expression selected at one hundred percent.
Definition style_static.hpp:72
Left left
Owned expression selected at zero percent.
Definition style_static.hpp:71
std::int32_t percentage
Validated constant blend factor.
Definition style_static.hpp:73
Internal owning constant parameter definition.
Definition style_static.hpp:38
T initial
Constant default value.
Definition style_static.hpp:40
static constexpr auto NAME
Owning static identity.
Definition style_static.hpp:39
Internal owning parameter pack.
Definition style_static.hpp:46
std::tuple< P... > entries
Owning definitions.
Definition style_static.hpp:47
constexpr auto defaults() const
Definition style_static.hpp:50
Internal owning rule, validated by its containing sheet.
Definition style_static.hpp:283
S selector
Owning selector.
Definition style_static.hpp:284
std::tuple< D... > declarations
Owning declarations.
Definition style_static.hpp:285
static constexpr std::array< std::string_view, 0 > CLASS_NAMES
Empty class predicates.
Definition style_static.hpp:274
StyleState state
Existing pseudo-state.
Definition style_static.hpp:275
bool readOnly
Orthogonal read-only qualifier.
Definition style_static.hpp:276
static constexpr auto TYPE
Owning type identity.
Definition style_static.hpp:272
static constexpr auto ID
Owning target identity.
Definition style_static.hpp:273
Internal conjunction selector with static owning byte identities.
Definition style_static.hpp:259
static constexpr std::array CLASS_NAMES
Views into static owned template bytes.
Definition style_static.hpp:262
StyleState state
Existing pseudo-state.
Definition style_static.hpp:263
static constexpr auto ID
Owning target identity.
Definition style_static.hpp:261
bool readOnly
Orthogonal read-only qualifier.
Definition style_static.hpp:264
static constexpr auto TYPE
Owning type identity.
Definition style_static.hpp:260
Internal named expression leaf.
Definition style_static.hpp:62
static constexpr auto NAME
Owning static identity.
Definition style_static.hpp:63
Owning fixed-size bytes usable as a structural template argument.
Definition ui_static.hpp:15
constexpr std::string_view view() const noexcept
Definition ui_static.hpp:31