Skip to content

ui::TextStyle

Header: winui/render/Text.hpp.

Everything a Renderer and TextMeasurer need to know about how a run of text looks: font, size, weight, alignment inside its box, wrapping, decorations and spacing.

A plain aggregate, filled in with designated initializers. Controls normally take their style from the theme's type ramp (see TextRole); passing one explicitly (TextControl::set_text_style(), ui::Text::style) pins it. Sizes are in DIPs.

Example:

const ui::TextStyle heading{
    .font_size   = 20.0f,
    .horizontal  = ui::TextAlign::Leading,
    .font_family = "Segoe UI Variable",
    .weight      = ui::FontWeight::SemiBold,
    .wrapping    = ui::TextWrapping::WrapWholeWords,
};

auto label = std::make_unique<ui::TextControl>("Account");
label->set_text_style(heading); // wins over the theme's role ramp from now on

// Or in a spec:
ui::Text{.text = "Account", .text_style = heading};

font_size

float font_size = 14.0f

Font size in DIPs (not points). Default 14.

horizontal

TextAlign horizontal = TextAlign::Center

Horizontal placement inside the drawing box; Center by default.

vertical

TextAlign vertical = TextAlign::Center

Vertical placement inside the drawing box; Center by default.

font_family

FontName font_family = "Segoe UI"

Font family name, looked up among the installed fonts.

weight

FontWeight weight = FontWeight::Regular

Font weight.

italic

bool italic = false

Italic face.

line_height

float line_height = 0.0f

Puts every line in a line box of this height in DIPs, whatever the font's natural metrics, as the Metro theme does (20 DIPs for body text, 40 for the 56px header). 0, the default, uses the font's natural line height.

effect

TextEffect effect {}

Defaults to no effect (a single plain pass); see TextEffect.

wrapping

TextWrapping wrapping = TextWrapping::NoWrap

NoWrap (the default) keeps every run on one line, whatever box it is drawn into. A wrapping style is measured with TextMeasurer::measure_wrapped() against the width it will be drawn in, and a renderer breaks its lines at that box's width.

underline

bool underline = false

A line under the run, at the font's own underline position and thickness. Never changes the measured size.

strikethrough

bool strikethrough = false

A line through the run, likewise.

character_spacing

int character_spacing = 0

Extra room after every character, in thousandths of an em (200 at 24px adds 4.8 DIPs a character). Negative values tighten. It is part of the run's advance, so it widens the measured size, the last character's included.

character_spacing_dips

float character_spacing_dips() const

character_spacing converted to DIPs per character at this style's font_size.