Incular logoIncular
API ReferenceText & Media

TextStyle

Every font, spacing, decoration, and scaling setter with merging rules.

Immutable value with has_explicit_* inheritance tracking. Default: inherit = true, SystemUi family, default text size, NORMAL (400), Normal style, white, zero letter spacing.

Full setter tour

Every setter running on one style — copy, paste, and run:

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(Text::new("Styled text").style(
                TextStyle::new()
                    .font_family("Inter")
                    .font_size(18.0)
                    .font_weight(FontWeight::BOLD)
                    .font_style(FontStyle::Italic)
                    .color(Color::rgba(30, 32, 40, 255))
                    .line_height_multiplier(1.5)
                    .letter_spacing(0.5)
                    .decoration(TextDecoration::UNDERLINE)
                    .decoration_style(TextDecorationStyle::Wavy)
                    .overflow(TextOverflow::Ellipsis),
            ))
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

The remaining setters (fallback_families, background_color, line_height_absolute, word_spacing, locale, foreground, background, shadows, font_variations, font_features, decoration_color, decoration_thickness, debug_label, plus the with_* by-ref variants) share the same builder shape.

See Fonts for FontWeight / FontStyle / FontFamily, and TextDecoration for decoration flags.

Merging, apply, scale

use incular::prelude::*;

fn main() {
    let base = TextStyle::new().font_size(14.0);
    let override_ = TextStyle::new().font_size(18.0);
    let merged = base.merge(&override_);
    println!("merged size: {}", merged.size);
    println!("impact: {:?}", base.change_impact(&override_));
}

with_font_size, with_font_weight, with_color, with_letter_spacing, with_line_height, with_decoration are by-ref variants.

Setter groups

GroupSetters
Familyfont_family, family, fallback_families, fallback_family
Sizefont_size / size, with_font_size
Weight/Stylefont_weight, bold, font_style, italic, with_font_weight
Colorcolor, background_color, foreground, background, with_color
Line heightline_height, height, line_height_multiplier, line_height_absolute, line_height_mode, with_line_height
Spacingletter_spacing, word_spacing, with_letter_spacing
Baseline/Leadingtext_baseline, leading_distribution
Decorationdecoration, decoration_color, decoration_style, decoration_thickness, with_decoration
Shadows/Fontsshadows / shadow, font_variations, font_features
Misclocale, overflow, debug_label, inherit

TextBaseline: Alphabetic (default) / Ideographic. TextLeadingDistribution: Proportional (default) / Even. TextScaler: TextScaler::linear(1.2), TextScaler::no_scaling().

Supporting style types

StrutStyle (minimum strut box): font_family, font_size (clamped >= 0), font_weight, font_style, height, leading_distribution, force_strut_height. TextHeightBehavior { apply_height_to_first_ascent, apply_height_to_last_descent, leading_distribution }. TextWidthBasis: Parent (default) / LongestLine. LineHeight: Normal / Multiplier(f) / Absolute(px) (multiplier(), absolute()). FontFeature { tag: [u8;4], value: i32 } (enable, disable, tabular_figures, slashed_zero, …) and FontVariation { axis, value } (weight, italic, width, optical_size, …), each with to_css_setting().

Related: Text, EditableText.

On this page