Text
Elements
Runs of text, and the two semantic shorthands over them.
Import
#include "gbui/widgets/text.hpp"Example
Text
text · Elements
NodeId text(Ui& ui, std::string_view value, const TextOptions& options = {});A run of text with the theme's colours applied — the common case that would otherwise be two structs at every call site.
Emphasis
emphasis · Elements
NodeId emphasis(Ui& ui, std::string_view value, TextOptions options = {});RichText
richText · Elements
NodeId richText(Ui& ui, const std::vector<TextSpan>& spans, const RichTextOptions& options = {});A line of text whose runs differ — in colour, weight, slant or decoration. Built as a row of runs sharing a line, which is the honest shape given that a node carries one style. With wrap it becomes a wrapping row, so the line breaks between spans — see the caveat on that option. A paragraph that has to break mid-sentence still wants text with TextOverflow::Wrap and one colour, or a gradient across the whole run. Runs are centred against each other rather than sitting on a shared baseline, because Align::Baseline is not implemented yet. Spans of one size — the usual case — look identical either way.
SectionHeading
sectionHeading · Elements
NodeId sectionHeading(Ui& ui, std::string_view value);Small, uppercase, muted: the "UNSTAGED (1)" kind of heading.
Strong
strong · Elements
NodeId strong(Ui& ui, std::string_view value, TextOptions options = {});Semantic shorthands, in the sense HTML gives them: strong is importance and emphasis is stress, and each happens to be drawn with a weight or a slant. They exist so a call site says what it means rather than how it looks, which is what lets the look change later.
API
TextOptions
| Option | Type | Default | What it does |
|---|---|---|---|
color | Token | Token::Text | |
weight | FontWeight | FontWeight::Regular | |
slant | FontSlant | FontSlant::Normal | |
role | FontRole | FontRole::Ui | |
size | float | kAuto | |
align | TextAlign | TextAlign::Start | |
grow | float | 0.0f | Give the run the leftover space on the main axis. A commit subject wants this: it takes what is left after the fixed columns and elides the rest, instead of pushing them off the row. |
overflow | TextOverflow | TextOverflow::Ellipsis | |
maxLines | int | 0 | With overflow = Wrap, how many lines the run may take. Zero is unlimited; a count clamps it and ellipsises the last line. |
lineHeight | float | 0.0f | A multiplier over the font size. Zero takes the face's own line height, which is tight for a paragraph and right for a single-line label. |
underline | bool | false | |
strikeThrough | bool | false | |
gradient | Gradient | A gradient across the run, instead of color. Two stops is the common case: Gradient::linear(Fill{Token::Accent}, Fill{Token::Text}, 90). |
RichTextOptions
| Option | Type | Default | What it does |
|---|---|---|---|
align | TextAlign | TextAlign::Start | |
grow | float | 0.0f | |
gap | float | 0.0f | Space between spans. Zero butts them together, which is what a sentence wants; the spaces come from the spans themselves. |
wrap | bool | false | Lets the line wrap between spans. Not the same as wrapping text: the break can only fall where one span ends and the next begins, so a single long span still overflows its line rather than breaking inside itself. Splitting a sentence into more spans gives the layout more places to break. Real wrapping through mixed runs needs an inline formatting context, which the engine does not have. |