ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
StyleSpecs.hpp
Go to the documentation of this file.
1#pragma once
2
13
14#include "Style.hpp"
15#include "Diagnostics.hpp"
16
17#include <cstddef>
18#include <string_view>
19#include <vector>
20
21namespace ZenitUI
22{
26
28 enum class ParseResult
29 {
33 };
34
36 struct ParseCtx
37 {
38 SourceSpan span{};
39 DiagnosticSink *sink{nullptr};
40 bool strict{false};
41 };
42
43 using StyleApplyFn = ParseResult (*)(Style &, std::string_view, const ParseCtx &);
44
46 struct PropSpec
47 {
48 std::string_view name;
49 std::string_view group;
50 std::string_view syntax;
51 std::string_view example;
52 std::vector<std::string_view> sets;
53 std::string_view description;
54 StyleApplyFn apply{nullptr};
55 std::string_view prelude{};
56 std::string_view defaultText{};
57 };
58
61 {
62 std::string_view name;
63 std::string_view syntax;
64 std::string_view description;
65 std::string_view example{};
66 };
67
69 [[nodiscard]] const std::vector<PropSpec> &stylePropSpecs();
70
72 [[nodiscard]] const PropSpec *findStylePropSpec(std::string_view key);
73
75 [[nodiscard]] std::size_t countUnmigratedStyleSpecs();
76
78 [[nodiscard]] const std::vector<StyleNameDoc> &styleValueSyntaxDocs();
79
81 [[nodiscard]] const std::vector<StyleNameDoc> &styleSelectorDocs();
82
84 [[nodiscard]] const std::vector<StyleNameDoc> &styleConstructDocs();
85
87 [[nodiscard]] const std::vector<StyleNameDoc> &stylePseudoClassDocs();
88
90 [[nodiscard]] const std::vector<StyleNameDoc> &styleMediaFeatureDocs();
91
94 {
95 std::string_view name;
96 std::string_view syntax;
97 std::string_view description;
98 std::string_view example;
99 bool functional{false};
100 bool SimpleSelector::*selectorFlag{nullptr};
101 bool SimpleSelector::NegatedItem::*negatedFlag{nullptr};
102 };
103
105 enum class MediaFeatureId
106 {
107 MinWidth,
108 MaxWidth,
109 MinHeight,
110 MaxHeight,
111 Orientation,
112 MinAspectRatio,
113 MaxAspectRatio
114 };
115
118 {
119 std::string_view name;
120 std::string_view syntax;
121 std::string_view description;
122 std::string_view example;
124 };
125
126 [[nodiscard]] const std::vector<PseudoClassSpec> &stylePseudoClassSpecs();
127 [[nodiscard]] const PseudoClassSpec *findPseudoClassSpec(std::string_view name);
128
129 [[nodiscard]] const std::vector<MediaFeatureSpec> &styleMediaFeatureSpecs();
130 [[nodiscard]] const MediaFeatureSpec *findMediaFeatureSpec(std::string_view name);
131
133} // namespace ZenitUI
Structured diagnostics for the CSS parser and style resolver.
The Style / ComputedStyle pair and all style-related value types.
Abstract destination for diagnostics.
Definition Diagnostics.hpp:127
std::size_t countUnmigratedStyleSpecs()
Number of specs whose apply pointer is still nullptr (migration audit).
const std::vector< StyleNameDoc > & styleMediaFeatureDocs()
Supported @media features (min-width, orientation, ...).
const std::vector< StyleNameDoc > & styleSelectorDocs()
Selector syntax (Button, .cls, #id, >, +, ~, *, part).
const std::vector< StyleNameDoc > & stylePseudoClassDocs()
Supported pseudo-classes (:hover, :pressed, :focus, :disabled, :checked, :not()).
MediaFeatureId
Canonical identifier for each supported @media feature.
Definition StyleSpecs.hpp:106
const std::vector< StyleNameDoc > & styleValueSyntaxDocs()
Shared value types (<value>, <color>, <time>, <easing>).
const std::vector< PropSpec > & stylePropSpecs()
All documented & executable ZStyle keys (properties, shorthands, aliases).
ParseResult
Outcome of applying a single property value via a PropSpec.
Definition StyleSpecs.hpp:29
const PropSpec * findStylePropSpec(std::string_view key)
O(1) lookup by ZStyle key; returns nullptr if unknown.
const std::vector< StyleNameDoc > & styleConstructDocs()
Top-level ZStyle constructs (:root, --custom, var(), @keyframes, @media, part).
@ Invalid
Value malformed; caller should emit InvalidValue.
Definition StyleSpecs.hpp:31
@ Reported
Parser already emitted a specific diagnostic (e.g. missing prelude).
Definition StyleSpecs.hpp:32
@ Ok
Value parsed and applied cleanly.
Definition StyleSpecs.hpp:30
Executable + documentation descriptor for a @media feature.
Definition StyleSpecs.hpp:118
Context passed to executable property parsers.
Definition StyleSpecs.hpp:37
Executable + documentation descriptor for one ZStyle key.
Definition StyleSpecs.hpp:47
std::string_view group
Reference section ("Sizing", "Flex", ...).
Definition StyleSpecs.hpp:49
std::string_view syntax
Value grammar (auto-derived for Keyword enums).
Definition StyleSpecs.hpp:50
std::string_view example
Valid literal value checked by tests.
Definition StyleSpecs.hpp:51
std::string_view prelude
Required preceding declaration (e.g. transition longhands).
Definition StyleSpecs.hpp:55
StyleApplyFn apply
Executable parser for this key.
Definition StyleSpecs.hpp:54
std::string_view description
One or two sentences.
Definition StyleSpecs.hpp:53
std::vector< std::string_view > sets
camelCase Style fields written by this key.
Definition StyleSpecs.hpp:52
std::string_view defaultText
Optional human-readable override for the default column.
Definition StyleSpecs.hpp:56
std::string_view name
ZStyle key (kebab-case), e.g. "justify".
Definition StyleSpecs.hpp:48
Executable + documentation descriptor for a pseudo-class (:hover, :not(), ...).
Definition StyleSpecs.hpp:94
Single compound argument inside a :not(...) pseudo-class.
Definition Style.hpp:643
One component of a CSS selector chain.
Definition Style.hpp:632
Source location for a diagnostic.
Definition Diagnostics.hpp:41
Documentation entry for a language construct (value syntax, selector, pseudo-class,...
Definition StyleSpecs.hpp:61
std::string_view example
Optional parseable snippet verified by tests.
Definition StyleSpecs.hpp:65
Sparse style: every property is Opt<T>, unset by default.
Definition Style.hpp:932