Tutorial

Tutorial 1: Hello window

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

A screen function turns a Store into an element tree. App owns the scene, layout and interaction state. The native host opens the operating-system window and forwards its events to that App.

Type::Headline and Theme::paper_dark() select theme tokens. The numbers passed to size are the initial logical size, not a promise about physical pixels on every display. Options::from_env() lets the existing host consume its normal diagnostic environment variables.

Complete example

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

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

fn screen(_: &Store) -> El {
    col([
        text("Hello, Aster").style(Type::Headline),
        text("Your first native window.").muted(),
    ]).gap(3).pad(6)
}

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

Run it

From the repository root:

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

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

Shell
cargo run --locked -p aster-ui-host --example tutorial_hello_window -- --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

A dark window titled “Hello, Aster” contains a heading and a short sentence. Close the window to exit. No file is written in window mode.

Next steps

Change the heading, then try a different initial size. Continue with layout and text to build a more structured screen.