Skip to content

Text

Elements

Runs of text, and the two semantic shorthands over them.

Import

cpp
#include "gbui/widgets/text.hpp"

Example

Text

text · Elements

Nothing is downloaded until you press it.

cpp
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

Nothing is downloaded until you press it.

cpp
NodeId emphasis(Ui& ui, std::string_view value, TextOptions options = {});

RichText

richText · Elements

Nothing is downloaded until you press it.

cpp
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

Nothing is downloaded until you press it.

cpp
NodeId sectionHeading(Ui& ui, std::string_view value);

Small, uppercase, muted: the "UNSTAGED (1)" kind of heading.

Strong

strong · Elements

Nothing is downloaded until you press it.

cpp
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

OptionTypeDefaultWhat it does
colorTokenToken::Text
weightFontWeightFontWeight::Regular
slantFontSlantFontSlant::Normal
roleFontRoleFontRole::Ui
sizefloatkAuto
alignTextAlignTextAlign::Start
growfloat0.0fGive 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.
overflowTextOverflowTextOverflow::Ellipsis
maxLinesint0With overflow = Wrap, how many lines the run may take. Zero is unlimited; a count clamps it and ellipsises the last line.
lineHeightfloat0.0fA 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.
underlineboolfalse
strikeThroughboolfalse
gradientGradientA gradient across the run, instead of color. Two stops is the common case: Gradient::linear(Fill{Token::Accent}, Fill{Token::Text}, 90).

RichTextOptions

OptionTypeDefaultWhat it does
alignTextAlignTextAlign::Start
growfloat0.0f
gapfloat0.0fSpace between spans. Zero butts them together, which is what a sentence wants; the spaces come from the spans themselves.
wrapboolfalseLets 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.

Released under the LGPL-3.0-or-later licence.