|
ZenitUI
Retained-mode C++20 UI framework
|
CSS-like stylesheet parser and applier. More...
#include "Common.hpp"#include "Style.hpp"#include "Theme.hpp"#include "Media.hpp"#include "Diagnostics.hpp"#include <filesystem>#include <optional>#include <string>#include <string_view>#include <unordered_map>#include <vector>Go to the source code of this file.
Classes | |
| 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... | |
| struct | ZenitUI::ZMarkup::StyleSheet::Rule |
| One selector-plus-declarations entry. More... | |
| struct | ZenitUI::ZMarkup::StyleSheet::KfFrame |
| One from/to/N% frame inside @keyframes. More... | |
| struct | ZenitUI::ZMarkup::StyleSheet::KfRule |
| One @keyframes name { ... } block. 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... | |
Functions | |
| 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. | |
CSS-like stylesheet parser and applier.
Parses CSS-style source into a StyleSheet, then merges it into a Theme:
Supported features:
Not supported: @import, :nth-child(), @supports, nested :not().
Error handling: the parser produces diagnostics through an optional DiagnosticSink. Without a sink, warnings are logged via logWarn. loadStyleString / loadStyleFile return false if any error was reported (errors only — warnings do not fail the load).
Implementation lives in src/StyleParser.cpp (compiled into libZenitUI).