TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_style_text.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <cstring>
5#include <string_view>
6
7namespace tachyon
8{
11
13 enum class TextID : uint32_t { Invalid = 0 };
15 enum class IconID : uint32_t { Invalid = 0 };
16
20 enum class FontID : uint32_t { Invalid = 0 };
21
23 FontID FontIDFromName(std::string_view familyName);
24
29 {
30 char value[16] = {};
31
32 LanguageTag() = default;
34 explicit LanguageTag(std::string_view tag) noexcept
35 {
36 if (tag.size() < sizeof(value))
37 std::memcpy(value, tag.data(), tag.size());
38 }
39
41 bool empty() const noexcept { return value[0] == '\0'; }
43 const char* c_str() const noexcept { return value; }
45 std::string_view view() const noexcept { return value; }
46 bool operator==(const LanguageTag& other) const noexcept { return view() == other.view(); }
47 };
48
49
51 enum class TextDirection : uint8_t
52 {
56 };
57
59 enum class TextWrap : uint8_t
60 {
61 NoWrap = 0,
64 };
65
67 enum class TextAlign : uint8_t
68 {
69 Start = 0,
76 };
77
91
93 enum class DecorationStyle : uint8_t
94 {
95 Solid = 0,
100 };
101
112
133
135 enum class FontStyle : uint8_t
136 {
137 Normal = 0,
140 };
141
155
164
166 enum class VerticalTrim : uint8_t
167 {
170 };
171
174 enum class WordWrap : uint8_t
175 {
179 };
180
182 enum class TextOverflow : uint8_t
183 {
186 };
187
190 {
191 public:
203
204 uint64_t GetHashCode() const noexcept;
205
206 inline bool operator==(const TextLayoutStyle& other) const noexcept
207 {
208 return textDirection == other.textDirection &&
209 textWrapping == other.textWrapping &&
210 horizontalAlignment == other.horizontalAlignment &&
211 verticalAlignment == other.verticalAlignment &&
212 baseline == other.baseline &&
213 verticalTrim == other.verticalTrim &&
214 textOverflow == other.textOverflow &&
215 wrapMode == other.wrapMode;
216 }
217 };
218
220 enum class DecorationLine : uint8_t
221 {
226 };
227
232 {
233 public:
234 uint16_t thickness = 0;
235 uint16_t offset = 0;
237
238 uint64_t GetHashCode() const noexcept;
239
240 inline bool operator==(const TextDecoration& other) const noexcept
241 {
242 if (thickness > 0)
243 {
244 if (other.thickness == 0) return false;
245 } else
246 {
247 return other.thickness == 0; // if both are inactive other values are irrelevant
248 }
249 return style == other.style &&
250 thickness == other.thickness &&
251 offset == other.offset;
252 }
253 };
254
260 {
261 public:
262 float fontSize = 0;
265 float lineHeight = 1.25f;
266 float letterSpacing = 0.0f;
267 float wordSpacing = 0.0f;
276
281
282 uint64_t GetHashCode() const noexcept;
283
284 bool operator==(const TextStyle& other) const noexcept
285 {
286 return family == other.family &&
287 fontSize == other.fontSize &&
288 weight == other.weight &&
289 style == other.style &&
290 stretch == other.stretch &&
291 lineHeightType == other.lineHeightType &&
292 lineHeight == other.lineHeight &&
293 letterSpacing == other.letterSpacing &&
294 wordSpacing == other.wordSpacing &&
295 fontId == other.fontId &&
296 language == other.language &&
297 throughLine == other.throughLine &&
298 bottomLine == other.bottomLine &&
299 underLine == other.underLine &&
300 overLine == other.overLine;
301 }
302
305 inline float CalcLineHeight() const
306 {
307 switch (lineHeightType)
308 {
309 case LineHeight::Absolute: return lineHeight;
313 default: return fontSize;
314 }
315 }
316 };
317
319}//namespace tachyon
One text decoration line (underline, overline, ...).
Definition gui_style_text.h:232
DecorationStyle style
line style
Definition gui_style_text.h:236
uint64_t GetHashCode() const noexcept
uint16_t thickness
line thickness in CSS px; 0 = no line
Definition gui_style_text.h:234
uint16_t offset
CSS px from the default position; grows down for under / bottom lines, up otherwise.
Definition gui_style_text.h:235
How a text block is laid out in its box; shared by all states of a Style.
Definition gui_style_text.h:190
WordWrap wrapMode
not read by the text system; see textWrapping
Definition gui_style_text.h:201
uint64_t GetHashCode() const noexcept
TextOverflow textOverflow
CSS: text-overflow.
Definition gui_style_text.h:200
VerticalTrim verticalTrim
CSS: -tachyon-vertical-trim.
Definition gui_style_text.h:202
TextDirection textDirection
CSS: direction.
Definition gui_style_text.h:192
TextBaseline baseline
CSS: -tachyon-text-baseline, dominant-baseline or vertical-align.
Definition gui_style_text.h:199
TextWrap textWrapping
CSS: text-wrap.
Definition gui_style_text.h:193
TextAlign horizontalAlignment
CSS: text-align.
Definition gui_style_text.h:194
TextAlign verticalAlignment
Vertical position of the text (+ icon) block in its box; only Start / Center / End (and their aliases...
Definition gui_style_text.h:197
What text is measured and laid out from: font, metrics and decoration lines.
Definition gui_style_text.h:260
float letterSpacing
CSS px; stored and scaled, not applied by the text system.
Definition gui_style_text.h:266
float wordSpacing
CSS px; stored and scaled, not applied by the text system.
Definition gui_style_text.h:267
LanguageTag language
Picks regional letterforms (e.g. CJK); empty = the text system's default.
Definition gui_style_text.h:275
TextDecoration throughLine
through the text
Definition gui_style_text.h:277
FontStretch stretch
Definition gui_style_text.h:271
float CalcLineHeight() const
Line pitch in the style's units.
Definition gui_style_text.h:305
float lineHeight
CSS: line-height, read per lineHeightType (by default a multiple of fontSize).
Definition gui_style_text.h:265
float fontSize
CSS: font-size, in CSS px.
Definition gui_style_text.h:262
TextDecoration bottomLine
under the descender
Definition gui_style_text.h:278
LineHeight lineHeightType
how lineHeight is interpreted
Definition gui_style_text.h:272
FontFamily family
generic family, used when fontId isn't registered
Definition gui_style_text.h:268
TextDecoration overLine
over the ascender
Definition gui_style_text.h:280
FontWeight weight
Definition gui_style_text.h:269
FontStyle style
Definition gui_style_text.h:270
FontID fontId
overrides family when set
Definition gui_style_text.h:273
TextDecoration underLine
under the alphabetic baseline
Definition gui_style_text.h:279
uint64_t GetHashCode() const noexcept
@ None
Definition gui_element_flags.h:19
@ Invalid
Definition gui_image.h:37
@ End
Definition gui_input_enums.h:202
@ Default
Definition gui_command_manager.h:26
@ Right
Definition gui_input_enums.h:42
@ Left
Definition gui_input_enums.h:40
@ Middle
Definition gui_input_enums.h:41
FontFamily
Generic font family, used when TextStyle::fontId names no registered family.
Definition gui_style_text.h:104
DecorationStyle
Line style of a TextDecoration.
Definition gui_style_text.h:94
FontWeight
Font weight (CSS: font-weight); the CSS weight is in parentheses.
Definition gui_style_text.h:115
FontID FontIDFromName(std::string_view familyName)
Case-insensitive, like CSS family names. Returns FontID::Invalid for an empty name.
TextWrap
How text wraps in its box (CSS: text-wrap).
Definition gui_style_text.h:60
FontStretch
Font width (CSS: font-stretch); the width factor is in parentheses.
Definition gui_style_text.h:144
TextBaseline
Font baseline that text aligns on (TextLayoutStyle::baseline).
Definition gui_style_text.h:80
LineHeight
How TextStyle::lineHeight is read.
Definition gui_style_text.h:158
WordWrap
Word wrapping mode of TextLayoutStyle::wrapMode.
Definition gui_style_text.h:175
FontID
Handle for a font family registered with ITextSystem::RegisterFontFamily().
Definition gui_style_text.h:20
TextID
Handle for text registered with the text system (ITextSystem::RegisterText and friends).
Definition gui_style_text.h:13
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
DecorationLine
The decoration lines of a TextStyle; indexes StyleState::decorationColors.
Definition gui_style_text.h:221
TextOverflow
What happens to text that doesn't fit its box (CSS: text-overflow).
Definition gui_style_text.h:183
TextAlign
Alignment of text in its box (CSS: text-align, -tachyon-vertical-text-align).
Definition gui_style_text.h:68
FontStyle
Font slant (CSS: font-style).
Definition gui_style_text.h:136
TextDirection
Writing direction of text (CSS: direction).
Definition gui_style_text.h:52
VerticalTrim
Font metrics that bound a line for vertical alignment (CSS: -tachyon-vertical-trim).
Definition gui_style_text.h:167
@ Serif
serif
Definition gui_style_text.h:108
@ Emoji
emoji; assigned to emoji automatically
Definition gui_style_text.h:106
@ Default
the text system's default family
Definition gui_style_text.h:105
@ Monospace
monospace
Definition gui_style_text.h:109
@ Math
math
Definition gui_style_text.h:110
@ SansSerif
sans-serif
Definition gui_style_text.h:107
@ Wavy
wavy line
Definition gui_style_text.h:99
@ Dotted
dotted line
Definition gui_style_text.h:97
@ Double
double line
Definition gui_style_text.h:96
@ Solid
solid line
Definition gui_style_text.h:95
@ Dashed
dashed line
Definition gui_style_text.h:98
@ UltraBlack
Ultra black (950).
Definition gui_style_text.h:131
@ UltraLight
Ultra light (200).
Definition gui_style_text.h:119
@ DemiBold
Demibold (600).
Definition gui_style_text.h:123
@ Bold
Bold (700).
Definition gui_style_text.h:125
@ SemiBold
Semibold (600).
Definition gui_style_text.h:124
@ Medium
Medium (500).
Definition gui_style_text.h:122
@ Normal
Normal (400); the zero-initialized default.
Definition gui_style_text.h:116
@ Light
Light (300).
Definition gui_style_text.h:120
@ ExtraBold
Extra bold (800).
Definition gui_style_text.h:126
@ Thin
Thin (100).
Definition gui_style_text.h:117
@ Regular
Regular (400).
Definition gui_style_text.h:121
@ ExtraBlack
Extra black (950).
Definition gui_style_text.h:130
@ Black
Black (900).
Definition gui_style_text.h:128
@ ExtraLight
Extra light (200).
Definition gui_style_text.h:118
@ UltraBold
Ultra bold (800).
Definition gui_style_text.h:127
@ Heavy
Heavy (900).
Definition gui_style_text.h:129
@ NoWrap
a single line (nowrap)
Definition gui_style_text.h:61
@ WordChar
at word boundaries; a word longer than the box breaks between characters (word-char)
Definition gui_style_text.h:63
@ UltraExpanded
Ultra expanded (2.0).
Definition gui_style_text.h:153
@ ExtraExpanded
Extra expanded (1.5).
Definition gui_style_text.h:152
@ SemiExpanded
Semi expanded (1.125).
Definition gui_style_text.h:150
@ UltraCondensed
Ultra condensed (0.5).
Definition gui_style_text.h:146
@ Expanded
Expanded (1.25).
Definition gui_style_text.h:151
@ Normal
Normal (1.0); the zero-initialized default.
Definition gui_style_text.h:145
@ ExtraCondensed
Extra condensed (0.625).
Definition gui_style_text.h:147
@ Condensed
Condensed (0.75).
Definition gui_style_text.h:148
@ SemiCondensed
Semi condensed (0.875).
Definition gui_style_text.h:149
@ Central
ideographic central baseline
Definition gui_style_text.h:83
@ Mathematical
mathematical baseline
Definition gui_style_text.h:85
@ Ideographic
ideographic baseline
Definition gui_style_text.h:82
@ Max
count, not a baseline
Definition gui_style_text.h:89
@ TextBottom
bottom of the text
Definition gui_style_text.h:88
@ Hanging
hanging baseline
Definition gui_style_text.h:84
@ TextTop
top of the text
Definition gui_style_text.h:87
@ Alphabetic
alphabetic (roman) baseline
Definition gui_style_text.h:81
@ Normal
the font's metrics; lineHeight is ignored
Definition gui_style_text.h:159
@ Absolute
the value itself
Definition gui_style_text.h:162
@ FontSizeRelative
a multiple of the font size
Definition gui_style_text.h:161
@ MetricsRelative
a multiple of the font's metric line height
Definition gui_style_text.h:160
@ Normal
break at word boundaries
Definition gui_style_text.h:177
@ BreakWord
break within words when needed
Definition gui_style_text.h:178
@ Absolute
out of flow in content space; scrolls with the parent
Definition gui_style.h:218
@ Invalid
Definition gui_style_text.h:20
@ Bottom
Definition gui_style.h:255
@ Top
Definition gui_style.h:254
@ Under
TextStyle::underLine.
Definition gui_style_text.h:222
@ Through
TextStyle::throughLine.
Definition gui_style_text.h:225
@ Over
TextStyle::overLine.
Definition gui_style_text.h:224
@ NoWrap
Single line.
Definition gui_style.h:174
@ Wrap
Multi-line.
Definition gui_style.h:175
@ Clip
clip the text
Definition gui_style_text.h:184
@ Ellipsis
end with "..."
Definition gui_style_text.h:185
@ Start
Horizontal: the language's start (left for LTR, right for RTL). Vertical: top.
Definition gui_style_text.h:69
@ Oblique
oblique
Definition gui_style_text.h:139
@ Italic
italic
Definition gui_style_text.h:138
@ Normal
upright
Definition gui_style_text.h:137
@ Auto
inferred from the text
Definition gui_style_text.h:53
@ RightToLeft
Definition gui_style_text.h:55
@ LeftToRight
Definition gui_style_text.h:54
@ Auto
align-self only: inherit from container's align-items
Definition gui_style.h:182
@ Center
Center on cross axis.
Definition gui_style.h:185
@ CapToBaseline
cap height to baseline; tight, visually centered for widgets
Definition gui_style_text.h:169
@ Default
ascender to descender; leaves room for accents
Definition gui_style_text.h:168
Definition gui_logging.h:24
A BCP 47 language tag ("ja", "zh-Hant", "ko-KR") stored inline, so text styles stay plain values.
Definition gui_style_text.h:29
bool operator==(const LanguageTag &other) const noexcept
Definition gui_style_text.h:46
bool empty() const noexcept
No tag set.
Definition gui_style_text.h:41
const char * c_str() const noexcept
The tag as a null-terminated string.
Definition gui_style_text.h:43
char value[16]
null-terminated tag
Definition gui_style_text.h:30
std::string_view view() const noexcept
The tag as a string view.
Definition gui_style_text.h:45
LanguageTag(std::string_view tag) noexcept
Copies tag; a tag of 16 characters or more leaves it empty.
Definition gui_style_text.h:34