tawasuyu

tawasuyu/llimphi

Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.

Rust 238TOML 102Markdown 83Shell 24178 Sutichaykuna

⎇ main llimphi-wasm-runner/examples/run_counter.rs Rust · 51 siq'ikuna · 1.4 KB Ñawpa willay Pi imata llamkarqan ch'uya

chore: refresco desde el monorepo — 27 crates nuevos (anim, lottie, svg, mesh, image, layer, test, wire-view, widgets rag-sidebar/router/lazy-list/rive-button) y sync de los 95 existentes 93253cc22 · Sergio ·

1//! Corre una app WASM Tier 3 dentro de una ventana Llimphi real.
2//!
3//! El `.wasm` está embebido (compilado por `scripts/build-wasm-demo.sh`). El
4//! host no sabe nada de la app: pide `wasm_view`, materializa el `WireNode`,
5//! rebota clicks y rutea el teclado al input enfocado. Toda la lógica vive del
6//! lado guest.
7//!
8//! `cargo run -p llimphi-wasm-runner --example run_counter --release`
9
10use llimphi_ui::{App, Handle, KeyEvent, View};
11use llimphi_wasm_runner::{RunnerMsg, WasmGuest};
12
13const COUNTER_WASM: &[u8] = include_bytes!("../assets/counter.wasm");
14
15struct Host;
16
17impl App for Host {
18    type Model = WasmGuest;
19    type Msg = RunnerMsg;
20
21    fn title() -> &'static str {
22        "llimphi · wasm runner — counter"
23    }
24
25    fn init(_: &Handle<Self::Msg>) -> Self::Model {
26        WasmGuest::load(COUNTER_WASM, 0).expect("cargar counter.wasm")
27    }
28
29    fn update(mut model: Self::Model, msg: Self::Msg, _: &Handle<Self::Msg>) -> Self::Model {
30        if let Err(e) = model.apply(&msg) {
31            eprintln!("wasm dispatch: {e}");
32        }
33        model
34    }
35
36    fn view(model: &Self::Model) -> View<Self::Msg> {
37        model.render()
38    }
39
40    fn on_key(model: &Self::Model, event: &KeyEvent) -> Option<Self::Msg> {
41        model.key_to_msg(event)
42    }
43
44    fn on_focus(_model: &Self::Model, id: Option<u64>) -> Option<Self::Msg> {
45        Some(WasmGuest::focus_msg(id))
46    }
47}
48
49fn main() {
50    llimphi_ui::run::<Host>();
51}