Tutorial

Tutorial 2: Layout and text

Chapter 2 of 5. The complete example is on this page; every line of code compiles as shown.

Compose a screen with col and row, then use modifiers to express spacing and growth. Here the two cards share the row's available space because both use .grow(1.). .gap and .pad use the authoring layer's spacing scale; they are not literal pixel counts. Text styles come from the theme, and .wrap_fit() allows prose to wrap inside its available width.

This example is a two-column composition, not a complete responsive breakpoint system. At very narrow widths a real app should switch to a column or use the SDK's responsive helpers. Do not shrink text to hide an overflow problem.

Complete example

Source: tutorial_layout_text.rs native/ui-host/examples/tutorial_layout_text.rs.

Rust
//! Run from native/: cargo run --locked -p aster-ui-host --example tutorial_layout_text
use aster_blueprint::ui::prelude::*;
use aster_native::{Options, RunWindow};

fn screen(_: &Store) -> El {
    col([
        text("Field notes").style(Type::Headline),
        text("A small collection of ideas, arranged with rows and columns.").wrap_fit(),
        row([
            card([
                text("Drafts").style(Type::Title),
                text("Three ideas ready to explore.").muted().wrap_fit(),
            ]).grow(1.),
            card([
                text("Published").style(Type::Title),
                text("One finished note.").muted().wrap_fit(),
            ]).grow(1.),
        ]).gap(4),
        text("Resize the window to see text wrap.").style(Type::Caption).muted(),
    ]).gap(4).pad(6)
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = App::new(&Theme::paper_dark(), Store::new())
        .size(760, 420).screen(screen)?;
    if std::env::args().any(|a| a == "--headless") {
        app.write_png("tutorial_layout_text.png")?;
        return Ok(());
    }
    app.run_window_with(Options {
        title: "Aster layout and text".into(), ..Options::default()
    }.from_env())
}

Run it

From the repository root:

Shell
cd native
cargo check --locked -p aster-ui-host --example tutorial_layout_text
cargo run --locked -p aster-ui-host --example tutorial_layout_text

Without a desktop display, run the image-producing path instead:

Shell
cargo run --locked -p aster-ui-host --example tutorial_layout_text -- --headless

PNG files are written in the command's current directory. For the animation example, append --reduced-motion after -- to compare the reduced-motion policy.

What you will see

The “Field notes” heading sits above two cards, “Drafts” and “Published”. The cards share their row. Resize the window to observe text wrapping.

Next steps

Replace the synthetic card content and inspect it at your app's minimum supported size. Continue with forms and input.