Incular logoIncular
API ReferenceText & Media

Text

Text widget with style, alignment, wrapping, and overflow options.

Shaped during layout. Text::new uses the default style, Start alignment, wrapping on, no line limit, Clip overflow. Does not expand — wrap in Expanded to fill.

Constructors and setters

Every setter running — 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(
                Column::builder()
                    .main_axis_size(MainAxisSize::Min)
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Text::new("Hello").into(),
                        Text::new("Emphasis")
                                .style(
                                    TextStyle::new().bold().font_size(18.0),
                                ).into(),
                        Text::new("Red")
                                .color(Color::rgba(200, 30, 30, 255)).into(),
                        Text::new("Centered").align(TextAlign::Center).into(),
                        Text::new("No wrap").soft_wrap(false).into(),
                        Text::new("Two lines at most")
                                .max_lines(Some(2))
                                .overflow(TextOverflow::Ellipsis).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Setters: style(TextStyle), color(Color), align(TextAlign), soft_wrap(bool), max_lines(Option<usize>), overflow(TextOverflow).

Props

Prop

Type

TextAlign and TextOverflow

TextAlign: Start (default) / Center / End / Justify. TextOverflow: Clip (default) / Ellipsis / Visible / Fade.

For multi-style runs see RichText & Spans; for editing see EditableText.

Related: TextStyle, Fonts.

On this page