limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/System

    Text

    A line or a paragraph of passive text, sized by a role of the type scale and colored from the palette.

    Native componentGuide source

    Preview

    CodeSource
    fn view(palette: ComponentPalette) -> Element {
        Text::new("Saved a moment ago", palette).render()
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Outside the scale1 / 2
    CodeSource

    Read the source of this example.

    Outside the scale2 / 2
    CodeSource

    Read the source of this example.

    Ink and family
    CodeSource
    Text::eyebrow("EYEBROW", palette).render(),
    Text::new("Primary text", palette).render(),
    Text::new("Secondary text with muted()", palette).muted().render(),
    Text::new("Semantic ink with ink()", palette).ink(AlertColors::for_tone(AlertTone::Error, palette).accent).render(),
    Text::new("cargo test -p limn", palette).mono().render(),
    Weights1 / 4
    CodeSource

    Read the source of this example.

    Weights2 / 4
    CodeSource

    Read the source of this example.

    Weights3 / 4
    CodeSource

    Read the source of this example.

    Weights4 / 4
    CodeSource

    Read the source of this example.

    Marks and hints1 / 2
    CodeSource

    Read the source of this example.

    Marks and hints2 / 2
    CodeSource

    Read the source of this example.

    A limit of lines1 / 3
    CodeSource

    Read the source of this example.

    A limit of lines2 / 3
    CodeSource

    Read the source of this example.

    A limit of lines3 / 3
    CodeSource

    Read the source of this example.

    Inline pictures1 / 2
    CodeSource

    Read the source of this example.

    Inline pictures2 / 2
    CodeSource

    Read the source of this example.

    Long text
    CodeSource
    Element::column(vec![
        caption(cx, "truncate() with tooltip()"),
        Text::new(long, palette).truncate().tooltip("typography-truncated").render(),
        caption(cx, "fade()"),
        Text::new(long, palette).fade(32.0).render(),
        caption(cx, "No options: the paragraph wraps"),
        Text::new(long, palette).line_height(20.0).render(),
    ])
    .gap(6.0)
    .size(Some(width.min(280.0)), None)
    Soft focus
    CodeSource
    Element::column(
        [0.0, 1.0, 2.0, 3.5]
            .into_iter()
            .enumerate()
            .map(|(index, radius)| Text::new("The line that has not been sung yet", palette).font_size(20.0).render().soft_focus(format!("typography-soft:{index}"), radius))
            .collect(),
    )
    .gap(8.0)
    Unicode fallback
    CodeSource
    std::iter::once(
                caption(cx, "Mathematical alphabets and decorative symbols: bundled Noto Math and Symbols 2 fallbacks; no system font needed."),
            ).chain([
                ("Regular", limn::FontFamily::Sans),
                ("Italic", limn::FontFamily::SansItalic),
                ("Medium", limn::FontFamily::SansMedium),
                ("Bold", limn::FontFamily::SansBold),
                ("Monospace", limn::FontFamily::Monospace),
            ].into_iter().map(|(name, family)| {
                Element::text(format!("{name} · 𝖗𝖚𝖓𝖊 · ╭─ ✦ Lounge ❖ ➜"))
                    .font_family(family)
                    .font_size(16.0)
                    .foreground(palette.text)
            })).collect()
    Monochrome emoji1 / 2
    CodeSource

    Read the source of this example.

    Monochrome emoji2 / 2
    CodeSource

    Read the source of this example.

    Text

    A line or a paragraph of passive text, sized by a role of the type scale and colored from the palette.

    Import

    use limn::{Component, Text, TextRole};

    Usage

    Text needs its value and the palette. Without anything else it is caption-sized sans text in the palette’s text color, and it wraps.

    fn view(palette: ComponentPalette) -> Element {
        Text::new("Saved a moment ago", palette).render()
    }

    Roles

    Text::new("Projects", palette).role(TextRole::Heading).render()
    RoleSize
    Display18
    Heading16
    Body14
    Label13
    Caption12
    Small11
    Micro10
    Code14, monospaced

    A size off the scale

    Text::new("42", palette).mono().font_size(10.5).render()

    font_size(px) is for a step the host’s design has between two roles. The role still chooses the family. Prefer a role.

    Ink and family

    Text::new("Last run failed", palette).ink(error).render()
    Text::new("3 files changed", palette).muted().render()
    Text::new("cargo test -p limn", palette).mono().render()
    Text::eyebrow("RECENT", palette).render()

    muted paints in the palette’s muted color, for secondary copy. ink takes a color that carries meaning the host owns, such as an error or a warning. mono uses the monospaced family whatever the role. Text::eyebrow is the small monospaced muted label set above the group it names.

    Long text

    Text::new(title, palette).truncate().tooltip("file-title").render()
    Text::new(title, palette).fade(32.0).render()
    Text::new(paragraph, palette).line_height(20.0).render()

    truncate keeps the text to one line and ends it in an ellipsis when the width runs out. tooltip(id) shows the whole value in a tooltip, wrapped; the ID must be unique in the window, and it is ignored without truncate. fade(width) keeps to one line and fades out over the last width pixels instead; it takes precedence over truncate. line_height sets the leading of a wrapped paragraph.

    Weights

    Text has no weight. For the medium and bold faces, build the element and choose the family:

    Element::text("175.6K of 200K tokens")
        .font_family(FontFamily::SansBold)
        .font_size(15.0)
        .foreground(palette.text)

    FontFamily::SansMedium and FontFamily::SansBold are faces the host provides; a host without one paints Sans.

    Out of focus

    Text::new(line, palette).font_size(20.0).render().soft_focus("lyric:3", 2.0)

    soft_focus(id, radius) is a method of the rendered element. It paints the text out of focus by radius logical pixels, from 0 (sharp) to 8.

    Motion

    The radius of soft_focus is kept under its ID and springs to a new value; under reduced motion it changes at once.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/typography.rs.