nsh-cli 0.7.0

The nsh command line tool: build, package and run apps.
//! The app's Rust UI: its root component, which `nsh run`, `nsh package`
//! and `cargo run` mount.

use nsh_core::element::desktop::window as app_window;
use nsh_core::prelude::*;
use nsh_base::theme;

/// The app's UI set (`nsh.json` `"rust"`): what a TSX entry may import from
/// `__SPECIFIER__` (`README.md`, "Adding a TSX entry").
#[native_module("__SPECIFIER__")]
fn native(registry: &mut Registry) {
    registry.register::<App>();
}

/// The application's root component: the first window's content on the
/// desktops, the app's screen off them.
#[component]
pub fn App() -> impl IntoElement {
    let count = signal(0_u32);
    let content = move || {
        view()
            .flex_1()
            .bg(move || theme().background)
            .text_color(move || theme().foreground)
            .child(
                view()
                    .flex_1()
                    .p_safe_area()
                    .child(
                        view()
                            .flex_1()
                            .items_center()
                            .justify_center()
                            .gap_4()
                            .child(
                                text(move || format!("Count: {}", count.get())).text_size(px(28.0)),
                            )
                            .child(
                                view()
                                    .px_5()
                                    .py_3()
                                    .rounded(px(10.0))
                                    .bg(move || theme().primary)
                                    .active(|s| s.opacity(0.6))
                                    .on_press(move || count.update(|value| *value += 1))
                                    .child(
                                        text("Tap").text_size(px(17.0)).text_color(move || {
                                            theme().primary_foreground
                                        }),
                                    ),
                            ),
                    ),
            )
    };
    // One declaration everywhere: off the desktops `window()` shows its
    // content in the app's one surface.
    app_window().id("main").content(content)
}