Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Text

Layer: atom · Path: src/atoms/text.rs · Exports: text::{Text, TextRole}

A run of text at a typography role, in a theme color. Every visual comes from a token: font/size/line-height/tracking from a typography type style, color from the [Theme]. The DS’s universal text primitive; many other atoms compose it for their labels.

Design

  • Purpose / when to use — all body copy, labels, captions, inline code, and key glyphs. For titles use Heading.

  • Anatomy — a non-selectable egui::Label built from RichText with the role’s font_id + tracking + color, optional underline, and a wrap mode.

  • Variants / sizes / states

    TextRole → type style:

    RoleStyle
    Body (default)typography::body()
    BodyStrongbody_strong()
    Labellabel()
    LabelStronglabel_strong()
    Captioncaption()
    Codecode()
    Kbdkbd()

    Color: theme.foreground (default), .muted()muted_foreground, .color(c) → explicit. .wrap() enables wrapping (and line-height); .underline() for links; .italic() for asides/hints (combines freely, e.g. .muted().italic()). No interactive states.

  • Tokens consumedtheme.foreground / theme.muted_foreground (color), the per-role typography style.

  • Accessibility — rendered non-selectable so UI text never captures the pointer (it would steal clicks from interactive parents and show a text cursor).

API

SignatureEffect
Text::new(content: impl Into<String>) -> SelfConstruct with text.
.role(role: TextRole) -> SelfSet role.
.body_strong() / .label() / .label_strong() / .caption() / .code() / .kbd()Role shorthands.
.muted(self) -> SelfUse muted_foreground.
.color(color: Color32) -> SelfExplicit color (e.g. theme.success).
.wrap(self) -> SelfWrap on available width (default: extend/no wrap).
.underline(self) -> SelfUnderline (e.g. a link).
.italic(self) -> SelfItalicize (e.g. an aside/hint nuance).
.show(self, ui: &mut Ui) -> ResponseRender and return the Response.

TextRole (enum): Body (default), BodyStrong, Label, LabelStrong, Caption, Code, Kbd.

Usage

#![allow(unused)]
fn main() {
use ouroboros_ui::atoms::Text;

Text::new("Hello world").show(ui);
}
#![allow(unused)]
fn main() {
use ouroboros_ui::atoms::Text;

Text::new("Saved").caption().color(theme.success).show(ui);
Text::new("A long paragraph that should wrap…").wrap().show(ui);
Text::new("No layers selected").muted().italic().show(ui);
}

Composition

Atom: renders directly via egui::Label/RichText with token styling. It is itself composed by Checkbox, Radio, and Tooltip for their labels.

Notes

  • Default wrap mode is Extend (no wrap); line-height is only applied when .wrap() is set — applying leading to a single line inflates the row and decenters the glyph inside parents like buttons.
  • .color() wins over .muted().

See tokens · theming · typography.