|
ZenitUI
Retained-mode C++20 UI framework
|
CSS-like style cascade, .zstyle parser, custom properties, and media queries. More...
Classes | |
| struct | ZenitUI::SourceSpan |
| Source location for a diagnostic. More... | |
| struct | ZenitUI::ZStyleDiagnostic |
| A fully-formed diagnostic record. More... | |
| class | ZenitUI::DiagnosticSink |
| Abstract destination for diagnostics. More... | |
| class | ZenitUI::NullDiagnosticSink |
| Sink that discards every diagnostic. More... | |
| class | ZenitUI::CollectingDiagnosticSink |
| Sink that accumulates diagnostics in insertion order. More... | |
| struct | ZenitUI::MediaCondition |
| A single condition inside a @media query. More... | |
| struct | ZenitUI::MediaQuery |
| A conjunction of media conditions. More... | |
| struct | ZenitUI::Opt< T > |
| Optional wrapper with value semantics used for all style fields. More... | |
| class | ZenitUI::SharedPropMap |
| 8-byte Copy-on-Write wrapper around std::unordered_map<std::string, std::string>. More... | |
| class | ZenitUI::SharedVector< T > |
| 8-byte Copy-on-Write wrapper around std::vector<T> for cold style arrays. More... | |
| struct | ZenitUI::Spacing |
| Four-sided Value tuple used for padding, margin and border-width. More... | |
| struct | ZenitUI::TransitionSpec |
| One entry in the transitions list of a Style. More... | |
| struct | ZenitUI::AnimationRef |
| One entry in the animations list of a Style. More... | |
| struct | ZenitUI::ZIndex |
| CSS z-index with an explicit "auto" state. More... | |
| struct | ZenitUI::TextureRef |
| Reference to a texture asset with optional nine-slice insets. More... | |
| struct | ZenitUI::SimpleSelector |
| One component of a CSS selector chain. More... | |
| struct | ZenitUI::FilterRef |
| One filter in the filters list of a Style. More... | |
| struct | ZenitUI::BoxShadow |
| CSS box-shadow payload. More... | |
| struct | ZenitUI::GridTrack |
| One track definition in grid-template-columns or grid-template-rows. More... | |
| struct | ZenitUI::GridPlacement |
| Item placement along one grid axis (grid-column or grid-row). More... | |
| struct | ZenitUI::Style |
| Sparse style: every property is Opt<T>, unset by default. More... | |
| struct | ZenitUI::ComputedStyle |
| Dense style: every property has a concrete value. More... | |
| struct | ZenitUI::PropDesc |
| struct | ZenitUI::ZMarkup::Declaration |
| One parsed key: value; declaration, with source location. More... | |
| struct | ZenitUI::ZMarkup::StyleSheet |
| Intermediate representation: parsed rules, keyframes and root vars. More... | |
| class | ZenitUI::ZMarkup::StyleParser |
| Hand-written recursive-descent CSS-like parser. More... | |
| struct | ZenitUI::ZMarkup::StyleLintOptions |
| Options controlling static semantic linting in lintStyleSheet(). More... | |
| struct | ZenitUI::StyleResolver |
| Resolves, caches, and transitions the style of a single node. More... | |
| struct | ZenitUI::ParseCtx |
| Context passed to executable property parsers. More... | |
| struct | ZenitUI::PropSpec |
| Executable + documentation descriptor for one ZStyle key. More... | |
| struct | ZenitUI::StyleNameDoc |
| Documentation entry for a language construct (value syntax, selector, pseudo-class, media feature). More... | |
| struct | ZenitUI::PseudoClassSpec |
| Executable + documentation descriptor for a pseudo-class (:hover, :not(), ...). More... | |
| struct | ZenitUI::MediaFeatureSpec |
| Executable + documentation descriptor for a @media feature. More... | |
| struct | ZenitUI::Specificity |
| CSS-style specificity triple used to sort matching rules. More... | |
| struct | ZenitUI::ThemeRule |
| A single selector-plus-declarations entry in the stylesheet. More... | |
| class | ZenitUI::Theme |
| Per-context stylesheet: rules, keyframes, and root style. More... | |
Macros | |
| #define | BUBBLE_STYLE_PROPS(X) |
Typedefs | |
| using | ZenitUI::PropValue |
| using | ZenitUI::StyleApplyFn = ParseResult (*)(Style &, std::string_view, const ParseCtx &) |
Enumerations | |
| enum class | ZenitUI::DiagnosticSeverity { Info , Warning , Error } |
| Diagnostic severity level. | |
| enum class | ZenitUI::DiagnosticCode { UnterminatedString , UnbalancedBrace , UnexpectedToken , UnknownProperty , InvalidValue , UnknownPseudo , UnknownPart , UnresolvedVariable , UnusedVariable , UnknownSelectorTag , SelectorMatchesNothing , DuplicateRule , UnknownTag , UnknownAttribute } |
| Machine-readable diagnostic identifier. More... | |
| enum class | ZenitUI::Position : uint8_t { Static , Relative , Absolute } |
| CSS-style position modes supported by the layout system. | |
| enum class | ZenitUI::Overflow : uint8_t { Visible , Hidden , Scroll , Auto } |
| CSS overflow modes for one axis. | |
| enum class | ZenitUI::WhiteSpace : uint8_t { Normal , Nowrap } |
| CSS white-space values relevant to text layout. | |
| enum class | ZenitUI::TextOverflow : uint8_t { Visible , Ellipsis } |
| CSS text-overflow modes supported by the text renderer. | |
| enum class | ZenitUI::SelectorCombinator : uint8_t { SelectorCombinator::Descendant , SelectorCombinator::Child , SelectorCombinator::AdjacentSibling , SelectorCombinator::GeneralSibling } |
| Relationship between a selector and the preceding selector in a chain. More... | |
| enum class | Direction : uint8_t { Auto , Row , Column } |
| enum class | ZenitUI::ParseResult { ParseResult::Ok , ParseResult::Invalid , ParseResult::Reported } |
| Outcome of applying a single property value via a PropSpec. More... | |
| enum class | ZenitUI::MediaFeatureId { MinWidth , MaxWidth , MinHeight , MaxHeight , Orientation , MinAspectRatio , MaxAspectRatio } |
| Canonical identifier for each supported @media feature. | |
Functions | |
| const char * | ZenitUI::toString (DiagnosticSeverity s) noexcept |
| const char * | ZenitUI::toString (DiagnosticCode c) noexcept |
| ZStyleDiagnostic | ZenitUI::makeDiagnostic (DiagnosticCode code, DiagnosticSeverity severity, SourceSpan span, std::string message, std::string hint={}) |
| Build a diagnostic record. | |
| std::size_t | ZenitUI::editDistance (std::string_view a, std::string_view b) |
Levenshtein edit distance between a and b. | |
| std::vector< std::string > | ZenitUI::suggestSimilar (std::string_view unknown, const std::vector< std::string_view > &candidates, std::size_t maxDistance=2, std::size_t maxSuggestions=3) |
Suggest candidates within maxDistance edits of unknown. | |
| void | ZenitUI::formatDiagnostic (const ZStyleDiagnostic &d, std::ostream &os) |
Write a diagnostic to os in file:line:col: severity: message [code] format. | |
| const std::vector< std::string_view > & | ZenitUI::getKnownStyleProperties () |
| Return the list of style property names known to the parser. | |
| bool | ZenitUI::evaluateMedia (const MediaQuery &q, Vec2 viewport) |
| Evaluate a MediaQuery against a viewport size. | |
| std::ostream & | ZenitUI::operator<< (std::ostream &os, const FontStack &stack) |
| std::ostream operator for FontStack, used by debug output. | |
| bool | ZenitUI::operator== (const std::vector< FilterRef > &a, const std::vector< FilterRef > &b) |
| bool | ZenitUI::operator!= (const std::vector< FilterRef > &a, const std::vector< FilterRef > &b) |
| bool | ZenitUI::operator== (const std::vector< GridTrack > &a, const std::vector< GridTrack > &b) |
| bool | ZenitUI::operator!= (const std::vector< GridTrack > &a, const std::vector< GridTrack > &b) |
| bool | ZenitUI::isInheritedProp (std::string_view name) |
| true if the named property inherits from parent to child. | |
| bool | ZenitUI::clearStyleProp (Style &s, std::string_view name) |
Clear the property named name on s. | |
| std::string | ZenitUI::kebabToCamel (std::string_view s) |
| std::string | ZenitUI::camelToKebab (std::string_view s) |
| bool | ZenitUI::operator== (const ComputedStyle &a, const ComputedStyle &b) |
| Field-wise equality; used to detect layout-affecting style changes. | |
| bool | ZenitUI::operator!= (const ComputedStyle &a, const ComputedStyle &b) |
| float | ZenitUI::lerpProp (float a, float b, float t) |
| Color | ZenitUI::lerpProp (const Color &a, const Color &b, float t) |
| FontStack | ZenitUI::lerpProp (const FontStack &a, const FontStack &b, float t) |
| Value | ZenitUI::lerpProp (const Value &a, const Value &b, float t) |
| Spacing | ZenitUI::lerpProp (const Spacing &a, const Spacing &b, float t) |
| template<typename E, typename = std::enable_if_t<std::is_enum_v<E>>> | |
| E | ZenitUI::lerpProp (E a, E b, float t) |
| ZIndex | ZenitUI::lerpProp (const ZIndex &a, const ZIndex &b, float t) |
| std::string | ZenitUI::lerpProp (const std::string &a, const std::string &b, float t) |
| SharedVector< FilterRef > | ZenitUI::lerpProp (const SharedVector< FilterRef > &a, const SharedVector< FilterRef > &b, float t) |
| TextureRef | ZenitUI::lerpProp (const TextureRef &a, const TextureRef &b, float t) |
| BoxShadow | ZenitUI::lerpProp (const BoxShadow &a, const BoxShadow &b, float t) |
| SharedVector< GridTrack > | ZenitUI::lerpProp (const SharedVector< GridTrack > &a, const SharedVector< GridTrack > &b, float t) |
| GridPlacement | ZenitUI::lerpProp (const GridPlacement &a, const GridPlacement &b, float t) |
| ComputedStyle | ZenitUI::lerpStyle (const ComputedStyle &a, const ComputedStyle &b, float t) |
| Field-wise lerp of two ComputedStyle. | |
| ComputedStyle | ZenitUI::lerpStyleTimed (const ComputedStyle &a, const ComputedStyle &b, float realElapsed) |
Field-wise lerp using per-property durations from b's transition list. | |
| bool | ZenitUI::stylesDiffer (const Style &a, const Style &b) |
| Compare two sparse Style values for "would this change anything". | |
| template<typename T> | |
| Opt< T > | ZenitUI::lerpOpt (const Opt< T > &a, const Opt< T > &b, float t) |
| Style | ZenitUI::lerpStyleParts (const Style &a, const Style &b, float t) |
| void | ZenitUI::overlayComputed (ComputedStyle &dst, const Style &src) |
| template<typename F> | |
| void | ZenitUI::forEachSetStyleProp (const Style &s, F &&fn) |
| bool | ZenitUI::copyStyleProp (Style &dst, const Style &src, std::string_view name) |
| bool | ZenitUI::hasStyleProp (const Style &s, std::string_view name) |
| const std::vector< PropDesc > & | ZenitUI::propTable () |
| const PropDesc * | ZenitUI::findProp (std::string_view name) |
| PropValue | ZenitUI::lerpValue (const PropValue &a, const PropValue &b, float t) |
| std::optional< Value > | ZenitUI::parseValueToken (std::string_view s) |
| Parse a single Value token. | |
| std::optional< Color > | ZenitUI::parseColorToken (std::string_view s) |
| Parse a color token. | |
| std::optional< Spacing > | ZenitUI::parseSpacingToken (std::string_view s) |
| Parse a 1-4 value shorthand. | |
| std::optional< Align > | ZenitUI::parseAlignToken (std::string_view s) |
| std::optional< Direction > | ZenitUI::parseDirectionToken (std::string_view s) |
| std::optional< TextDirection > | ZenitUI::parseTextDirectionToken (std::string_view s) |
| std::optional< Justify > | ZenitUI::parseJustifyToken (std::string_view s) |
| std::optional< WhiteSpace > | ZenitUI::parseWhiteSpaceToken (std::string_view s) |
| std::optional< TextOverflow > | ZenitUI::parseTextOverflowToken (std::string_view s) |
| std::optional< CursorShape > | ZenitUI::parseCursorToken (std::string_view s) |
| bool | ZenitUI::applyStyleAttr (Style &st, std::string_view key, std::string_view val) |
Apply a single key: value declaration to st. | |
| std::string | ZenitUI::substituteVarRefs (std::string v, const std::unordered_map< std::string, std::string > &customProps) |
Recursively substitute var(--name) references in v. | |
| Style | ZenitUI::resolveUnresolvedProps (const std::unordered_map< std::string, std::string > &unresolved, const std::unordered_map< std::string, std::string > &customProps) |
Resolve every pending var(...) declaration in unresolved. | |
| std::string_view | ZenitUI::ZMarkup::trim (std::string_view s) |
| Trim leading and trailing ASCII whitespace. | |
| std::string | ZenitUI::ZMarkup::stripComments (std::string_view src) |
Strip // line and block comments from src. | |
| std::vector< std::string_view > | ZenitUI::ZMarkup::splitBy (std::string_view s, char sep) |
Split s on every occurrence of sep. | |
| std::vector< std::string_view > | ZenitUI::ZMarkup::splitWs (std::string_view s) |
Split s on any ASCII whitespace. | |
| float | ZenitUI::ZMarkup::parseDurationSec (std::string_view s) |
| Parse a CSS duration ("200ms" → 0.2, "1.5s" → 1.5). | |
| void | ZenitUI::ZMarkup::applyStyleDeclaration (Style &st, std::string_view keyRaw, std::string_view valRaw, const SourceSpan &loc, DiagnosticSink *sink=nullptr, bool strict=false) |
Apply one declaration to st. | |
| void | ZenitUI::ZMarkup::normalizeKeyframes (KeyframeAnimation &anim, const SourceSpan &loc) |
| Fill missing properties in every keyframe from neighbouring frames. | |
| void | ZenitUI::ZMarkup::applyStyleSheet (const StyleSheet &sheet, Theme &theme, DiagnosticSink *sink=nullptr, bool strict=false) |
| Apply a parsed StyleSheet to a Theme. | |
| void | ZenitUI::ZMarkup::lintStyleSheet (const StyleSheet &sheet, DiagnosticSink &sink, const StyleLintOptions &opts={}) |
| Run static semantic checks on a parsed StyleSheet. | |
| bool | ZenitUI::ZMarkup::loadStyleString (std::string_view src, Theme &theme, const std::string &fileName="<string>", DiagnosticSink *sink=nullptr, bool strict=false, const Registry *registry=nullptr) |
Parse src and apply it to theme. | |
| bool | ZenitUI::ZMarkup::loadStyleFile (const std::filesystem::path &path, Theme &theme, DiagnosticSink *sink=nullptr, bool strict=false, const Registry *registry=nullptr) |
Load a stylesheet from a file and apply it to theme. | |
| const std::vector< PropSpec > & | ZenitUI::stylePropSpecs () |
| All documented & executable ZStyle keys (properties, shorthands, aliases). | |
| const PropSpec * | ZenitUI::findStylePropSpec (std::string_view key) |
| O(1) lookup by ZStyle key; returns nullptr if unknown. | |
| std::size_t | ZenitUI::countUnmigratedStyleSpecs () |
| Number of specs whose apply pointer is still nullptr (migration audit). | |
| const std::vector< StyleNameDoc > & | ZenitUI::styleValueSyntaxDocs () |
| Shared value types (<value>, <color>, <time>, <easing>). | |
| const std::vector< StyleNameDoc > & | ZenitUI::styleSelectorDocs () |
| Selector syntax (Button, .cls, #id, >, +, ~, *, ::part). | |
| const std::vector< StyleNameDoc > & | ZenitUI::styleConstructDocs () |
| Top-level ZStyle constructs (:root, --custom, var(), @keyframes, @media, ::part). | |
| const std::vector< StyleNameDoc > & | ZenitUI::stylePseudoClassDocs () |
| Supported pseudo-classes (:hover, :pressed, :focus, :disabled, :checked, :not()). | |
| const std::vector< StyleNameDoc > & | ZenitUI::styleMediaFeatureDocs () |
| Supported @media features (min-width, orientation, ...). | |
| const std::vector< PseudoClassSpec > & | ZenitUI::stylePseudoClassSpecs () |
| const PseudoClassSpec * | ZenitUI::findPseudoClassSpec (std::string_view name) |
| const std::vector< MediaFeatureSpec > & | ZenitUI::styleMediaFeatureSpecs () |
| const MediaFeatureSpec * | ZenitUI::findMediaFeatureSpec (std::string_view name) |
| Specificity | ZenitUI::computeNegatedItemSpecificity (const SimpleSelector::NegatedItem &item) |
| Specificity | ZenitUI::computeSpecificity (const std::vector< SimpleSelector > &chain) |
| Compute the specificity of a full selector chain. | |
CSS-like style cascade, .zstyle parser, custom properties, and media queries.
Load stylesheets into a context's UIContext::theme via ZMarkup::loadStyleFile(path, ctx.theme) or ZMarkup::loadStyleString(src, ctx.theme) (optionally passing &ctx.markupRegistry() to validate custom widget ::part names). Resolution follows specificity (#id > .class > Tag), supports descendant ( ), child (>), adjacent sibling (+), and general sibling (~) combinators, * and :not(...), interaction pseudo-classes (:hover, :pressed, :focus, :checked, :disabled), live Copy-on-Write custom properties (--token / var(--token)), @media queries, dir: / cursor:, and structured parse + lint diagnostics with typo suggestions.
Live examples: 03_selectors_theme · 02_layout_flex · 15_grid_dashboard · 13_i18n_rtl Full reference: ZStyle Reference
| using ZenitUI::PropValue |
|
strong |
Machine-readable diagnostic identifier.
Grouped by subsystem:
Tools can switch on code without matching localized message strings.
|
strong |
|
strong |
|
inline |
Apply a single key: value declaration to st.
| void ZenitUI::ZMarkup::applyStyleDeclaration | ( | Style & | st, |
| std::string_view | keyRaw, | ||
| std::string_view | valRaw, | ||
| const SourceSpan & | loc, | ||
| DiagnosticSink * | sink = nullptr, | ||
| bool | strict = false ) |
Apply one declaration to st.
Handles:
Reports an UnknownProperty warning (or error in strict mode) when applyStyleAttr returns false, with "did you mean" suggestions drawn from getKnownStyleProperties.
| st | Destination style. |
| keyRaw | Property name (trimmed internally). |
| valRaw | Value string (trimmed internally). |
| loc | Source location for diagnostics. |
| sink | Optional diagnostic sink; if null, warnings go to logWarn. |
| strict | If true, unknown properties become errors instead of warnings. |
| void ZenitUI::ZMarkup::applyStyleSheet | ( | const StyleSheet & | sheet, |
| Theme & | theme, | ||
| DiagnosticSink * | sink = nullptr, | ||
| bool | strict = false ) |
Apply a parsed StyleSheet to a Theme.
Order of operations:
| sheet | Parsed stylesheet. |
| theme | Destination theme. |
| sink | Optional diagnostic sink. |
| strict | When true, unknown properties become errors. |
|
inline |
Clear the property named name on s.
|
nodiscard |
Levenshtein edit distance between a and b.
O(n*m) time, O(min(n,m)) space. Used by suggestSimilar for "did you mean" hints; strings of length > 100 are rare in this codebase.
|
inline |
Evaluate a MediaQuery against a viewport size.
| q | The query to evaluate. |
| viewport | Current viewport in logical pixels. |
| void ZenitUI::formatDiagnostic | ( | const ZStyleDiagnostic & | d, |
| std::ostream & | os ) |
Write a diagnostic to os in file:line:col: severity: message [code] format.
Appends the hint: line when non-empty, and the note: see … line when related is set.
|
nodiscard |
Return the list of style property names known to the parser.
Used by suggestSimilar when producing UnknownProperty hints.
| void ZenitUI::ZMarkup::lintStyleSheet | ( | const StyleSheet & | sheet, |
| DiagnosticSink & | sink, | ||
| const StyleLintOptions & | opts = {} ) |
Run static semantic checks on a parsed StyleSheet.
Emits UnresolvedVariable, UnusedVariable, UnknownSelectorTag, and (when opts.markupRoot is provided) SelectorMatchesNothing.
| bool ZenitUI::ZMarkup::loadStyleFile | ( | const std::filesystem::path & | path, |
| Theme & | theme, | ||
| DiagnosticSink * | sink = nullptr, | ||
| bool | strict = false, | ||
| const Registry * | registry = nullptr ) |
Load a stylesheet from a file and apply it to theme.
| bool ZenitUI::ZMarkup::loadStyleString | ( | std::string_view | src, |
| Theme & | theme, | ||
| const std::string & | fileName = "<string>", | ||
| DiagnosticSink * | sink = nullptr, | ||
| bool | strict = false, | ||
| const Registry * | registry = nullptr ) |
Parse src and apply it to theme.
|
nodiscard |
Build a diagnostic record.
| code | Machine-readable identifier. |
| severity | Severity level. |
| span | Primary source location. |
| message | Human-readable message. |
| hint | Optional suggestion text. |
| void ZenitUI::ZMarkup::normalizeKeyframes | ( | KeyframeAnimation & | anim, |
| const SourceSpan & | loc ) |
Fill missing properties in every keyframe from neighbouring frames.
CSS animations that declare a property only at the start and end still need all keyframes to hold a value for that property, so that the evaluator can interpolate uniformly. This function fills gaps by copying from the previous keyframe, or from the next if the gap is at the beginning. Emits a logWarn for each auto-filled property to make authoring errors visible.
|
inline |
Parse a color token.
| float ZenitUI::ZMarkup::parseDurationSec | ( | std::string_view | s | ) |
Parse a CSS duration ("200ms" → 0.2, "1.5s" → 1.5).
Bare numbers are treated as seconds. Used by both transition and animation shorthands.
|
inline |
Parse a 1-4 value shorthand.
|
inline |
Parse a single Value token.
| std::vector< std::string_view > ZenitUI::ZMarkup::splitBy | ( | std::string_view | s, |
| char | sep ) |
Split s on every occurrence of sep.
Empty parts are preserved.
| std::vector< std::string_view > ZenitUI::ZMarkup::splitWs | ( | std::string_view | s | ) |
Split s on any ASCII whitespace.
Empty parts are skipped.
| std::string ZenitUI::ZMarkup::stripComments | ( | std::string_view | src | ) |
Strip // line and block comments from src.
Respects string literals: a // inside a "..." is not treated as a comment. Preserves newlines for accurate line numbering in diagnostics.
|
nodiscard |
Suggest candidates within maxDistance edits of unknown.
| unknown | The misspelled identifier. |
| candidates | List of valid identifiers. |
| maxDistance | Maximum edit distance to consider. |
| maxSuggestions | Maximum number of suggestions to return. |