TachyonUI 1.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 std::string text;
47 int line = 0;
48 bool important = false;
49 };
50
63
74 {
75 std::string name;
77 std::string category;
78 std::string label;
79 std::string description;
80 bool hasRange = false;
81 float min = 0.0f;
82 float max = 0.0f;
83 int line = 0;
84 };
85
87 struct FontFace
88 {
89 std::string family;
90 std::string src;
91 };
92
101
105 {
106 std::unordered_map<std::string, Style> styles;
109 std::unordered_map<std::string, ChildStyles> childStyles;
110 std::unordered_map<std::string, CustomProperty> customProperties;
113 std::vector<CustomPropertyInfo> propertyInfos;
116 std::vector<std::string> colorVariables; std::vector<FontFace> fontFaces;
118 std::vector<ParseError> errors;
119
121 bool HasErrors() const { return !errors.empty(); }
123 const Style* GetStyle(std::string_view name) const;
125 const CustomProperty* GetCustomProperty(std::string_view name) const;
128 const CustomPropertyInfo* GetPropertyInfo(std::string_view name) const;
129 };
130
134 StyleSheet ParseStyleSheet(std::string_view source);
135
137} // namespace tachyon
A fill: solid color, gradient or texture, as used for backgrounds, borders, text and icons.
Definition gui_style.h:527
float Length(float3 v)
Definition gui_math3d.h:22
CustomPropertyType
The kind of value an @property rule's syntax allows.
Definition gui_style_sheet.h:53
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
@ Corners
"<corners>": one to four lengths, a corner each, as border-radius takes them
Definition gui_style_sheet.h:60
@ Shadow
"<shadow>": a box-shadow, or none
Definition gui_style_sheet.h:61
@ Edges
"<edges>": one to four lengths, a side each, as border-width takes them
Definition gui_style_sheet.h:59
@ Number
"<number>": one number
Definition gui_style_sheet.h:56
@ Lengths
"<length>+": one to four lengths
Definition gui_style_sheet.h:58
@ Color
"<color>": a color or a gradient
Definition gui_style_sheet.h:55
@ Any
"*": anything, not checked
Definition gui_style_sheet.h:54
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:96
Style first
the first of several children
Definition gui_style_sheet.h:97
Style last
the last of several children
Definition gui_style_sheet.h:98
Style only
the only child: the first-, last- and only-child rules apply
Definition gui_style_sheet.h:99
Definition gui_style_sheet.h:74
std::string label
the name it's shown with, such as "Panel"
Definition gui_style_sheet.h:78
float max
the largest
Definition gui_style_sheet.h:82
float min
the smallest value a number or length may have
Definition gui_style_sheet.h:81
int line
the line of the rule
Definition gui_style_sheet.h:83
CustomPropertyType type
Definition gui_style_sheet.h:76
std::string description
what it's used for, a short sentence
Definition gui_style_sheet.h:79
std::string name
with the leading "--"
Definition gui_style_sheet.h:75
std::string category
the group it's shown in, such as "Surfaces"
Definition gui_style_sheet.h:77
bool hasRange
min and max are set
Definition gui_style_sheet.h:80
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
bool important
set with !important: a later plain declaration leaves it
Definition gui_style_sheet.h:48
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
int line
the line that set it
Definition gui_style_sheet.h:47
std::string text
the value as written, such as "#121418" or "4px 0px 0px 4px"
Definition gui_style_sheet.h:46
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:88
std::string src
as written; relative paths are relative to the stylesheet
Definition gui_style_sheet.h:90
std::string family
font-family name
Definition gui_style_sheet.h:89
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:105
Style baseStyle
what * rules set; styles start from it
Definition gui_style_sheet.h:117
std::unordered_map< std::string, Style > styles
keyed by class name, without the '.
Definition gui_style_sheet.h:106
std::unordered_map< std::string, CustomProperty > customProperties
keyed by name including the leading "--"
Definition gui_style_sheet.h:110
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:121
std::vector< ParseError > errors
in the order found
Definition gui_style_sheet.h:118
std::vector< FontFace > fontFaces
in source order
Definition gui_style_sheet.h:116
std::vector< CustomPropertyInfo > propertyInfos
What the @property rules say about the custom properties, in source order; a second rule for a name r...
Definition gui_style_sheet.h:113
const CustomProperty * GetCustomProperty(std::string_view name) const
A custom property by name (with the leading "--"); nullptr when not defined.
std::vector< std::string > colorVariables
The custom properties whose colors the styles use, numbered from 1 in this order: ColorStyle::variabl...
Definition gui_style_sheet.h:116
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:109
const CustomPropertyInfo * GetPropertyInfo(std::string_view name) const
The @property rule's facts for a custom property (with the leading "--"); nullptr when it has none.
A complete style, as parsed from CSS or built in code: layout properties plus the visual properties o...
Definition gui_style.h:699
Definition gui_base_types.h:383