affineui 0.0.2

Safe, idiomatic Rust bindings for AffineUI — GPU-accelerated HTML/CSS UI for tools and engines. EXPERIMENTAL preview; APIs will change.
Documentation
//! Hello-world for the Rust bindings (app-owned mode), mirroring
//! bindings/python/examples/hello.py.
//!
//!   cargo run --example hello              # opens a native window
//!   cargo run --example hello -- --headless  # prints HTML + layout size

use affineui::{App, Config, Document, Theme, View};

/// The repo's `examples/` dir (framework CSS bundles), located from this
/// crate's source dir so the cargo run CWD doesn't matter.
fn repo_examples_dir() -> String {
    std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("../../../examples")
        .to_string_lossy()
        .into_owned()
}

fn main() {
    let headless = std::env::args().any(|a| a == "--headless");

    println!("AffineUI {} (C ABI ok)", affineui::version());

    let view = View::new(Theme::Bootstrap);
    view.build(|v| {
        v.heading(1, "Hello from Rust", "", "");
        v.paragraph("AffineUI native window driven through the C ABI.", "", "msg");
        v.button("Click me", true, "go").on_click(|| println!("clicked!"));
        v.slider("Amount", 0.5, 0.0, 1.0, "amount")
            .on_change(|value| println!("amount = {value}"));
        v.checkbox("Enable thing", true, "thing")
            .on_change(|value| println!("thing = {value}"));
    });

    if headless {
        println!("--- html fragment ---\n{}", view.to_html_fragment());
        let doc = Document::new();
        doc.set_html("<main><h1>Hello</h1><p>headless layout</p></main>");
        doc.layout(640, 480);
        let (w, h) = doc.content_size();
        println!("headless content size: {w}x{h}");
        return;
    }

    let assets = repo_examples_dir();
    let app = App::new(
        Config::default()
            .title("AffineUI Rust")
            .size(800, 600)
            .asset_folders(&[assets.as_str(), "."]),
    );
    app.load_view(&view);
    std::process::exit(app.run());
}