TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_style_sheet.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <string>
6#include <string_view>
7#include <unordered_map>
8#include <vector>
9
10namespace tachyon
11{
14
15 // ============================================================================
16 // StyleSheet - result of parsing a CSS-inspired style file
17 // ============================================================================
18
21 {
22 std::string message;
23 int line = 0;
24 int column = 0;
25 };
26
30 {
33 bool hasColor = false;
34
37 uint16_t dims[4] {};
38 uint8_t dimCount = 0;
39 float number = 0.0f;
40 bool hasNumber = false;
41
44 bool hasShadow = false;
45 };
46
48 struct FontFace
49 {
50 std::string family;
51 std::string src;
52 };
53
62
66 {
67 std::unordered_map<std::string, Style> styles;
70 std::unordered_map<std::string, ChildStyles> childStyles;
71 std::unordered_map<std::string, CustomProperty> customProperties;
72 std::vector<FontFace> fontFaces;
74 std::vector<ParseError> errors;
75
77 bool HasErrors() const { return !errors.empty(); }
79 const Style* GetStyle(std::string_view name) const;
81 const CustomProperty* GetCustomProperty(std::string_view name) const;
82 };
83
87 StyleSheet ParseStyleSheet(std::string_view source);
88
90} // namespace tachyon
A fill: solid color, gradient or texture, as used for backgrounds, borders, text and icons.
Definition gui_style.h:524
StyleSheet ParseStyleSheet(std::string_view source)
Parses a theme's CSS (the subset TachyonUI supports, see docs/css.md) into a StyleSheet.
constexpr int kMaxBoxShadows
CSS box-shadow layers per state; the first is drawn on top.
Definition gui_style.h:114
Definition gui_logging.h:24
One CSS box-shadow layer, outside the border box.
Definition gui_style.h:121
A class's styles for where an element is among its parent's children, from its :first-child,...
Definition gui_style_sheet.h:57
Style first
the first of several children
Definition gui_style_sheet.h:58
Style last
the last of several children
Definition gui_style_sheet.h:59
Style only
the only child: the first-, last- and only-child rules apply
Definition gui_style_sheet.h:60
A resolved CSS custom property (:root { --name: value; }): a color, 1..4 numbers or a box-shadow.
Definition gui_style_sheet.h:30
uint8_t dimCount
number of values in dims, 0 = not numeric
Definition gui_style_sheet.h:38
ColorStyle colorStyle
the full value, which may be a gradient
Definition gui_style_sheet.h:32
bool hasColor
color / colorStyle are set
Definition gui_style_sheet.h:33
BoxShadow shadows[kMaxBoxShadows]
A box-shadow value (--shadow: 0 8px 20px rgba(0,0,0,0.35);, or none).
Definition gui_style_sheet.h:43
color4b color
the value as a solid color
Definition gui_style_sheet.h:31
uint16_t dims[4]
1..4 numeric values (--border-first: 2px 2px 2px 2px;), for shorthands such as border-width and borde...
Definition gui_style_sheet.h:37
bool hasShadow
shadows is set (all-empty for none)
Definition gui_style_sheet.h:44
float number
== dims[0] when dimCount >= 1
Definition gui_style_sheet.h:39
bool hasNumber
dimCount >= 1
Definition gui_style_sheet.h:40
One @font-face rule. Faces sharing a family name form one family.
Definition gui_style_sheet.h:49
std::string src
as written; relative paths are relative to the stylesheet
Definition gui_style_sheet.h:51
std::string family
font-family name
Definition gui_style_sheet.h:50
A problem found while parsing a style sheet; the parser skips the bad part and goes on.
Definition gui_style_sheet.h:21
std::string message
what is wrong
Definition gui_style_sheet.h:22
int column
column of the problem on that line
Definition gui_style_sheet.h:24
int line
1-based line of the problem in the parsed source
Definition gui_style_sheet.h:23
A parsed style sheet: named styles, custom properties and font faces.
Definition gui_style_sheet.h:66
Style baseStyle
what * rules set; styles start from it
Definition gui_style_sheet.h:73
std::unordered_map< std::string, Style > styles
keyed by class name, without the '.
Definition gui_style_sheet.h:67
std::unordered_map< std::string, CustomProperty > customProperties
keyed by name including the leading "--"
Definition gui_style_sheet.h:71
const Style * GetStyle(std::string_view name) const
The style of a class name (without the '.'); nullptr when not defined.
bool HasErrors() const
True when parsing reported any error.
Definition gui_style_sheet.h:77
std::vector< ParseError > errors
in the order found
Definition gui_style_sheet.h:74
std::vector< FontFace > fontFaces
in source order
Definition gui_style_sheet.h:72
const CustomProperty * GetCustomProperty(std::string_view name) const
A custom property by name (with the leading "--"); nullptr when not defined.
std::unordered_map< std::string, ChildStyles > childStyles
The classes with :first-child / :last-child / :only-child rules; register them with StyleManager::Reg...
Definition gui_style_sheet.h:70
A complete style, as parsed from CSS or built in code: layout properties plus the visual properties o...
Definition gui_style.h:687
Definition gui_base_types.h:384