A Fusuma app is one crate, fusuma, and a platform crate that owns the window, the web canvas or the panel. This page builds the smallest app that does something, then shows how the same code reaches a microcontroller and a browser.
Not on crates.io yet. Fusuma is in early development and breaking changes are fine. Depend on the repository until the first release.
Add the crate
[dependencies]
# A desktop app: Vello on the CPU, the Inter and JetBrains Mono fonts.
fusuma = { git = "https://github.com/FusumaLabs/fusuma" }
fusuma-platform-desktop = { git = "https://github.com/FusumaLabs/fusuma" }
# A chip: the toolkit and the integer renderer, no standard library, no allocator.
# fusuma = { git = "https://github.com/FusumaLabs/fusuma", default-features = false, features = ["renderer-integer"] }Everything else is a cargo feature, so you link only what the device needs.
| Feature | What it adds |
|---|---|
std (default) | the standard library; without it the crate is no_std |
renderer-vello-cpu (default), renderer-vello-gpu, renderer-integer | the renderers; link one or several, the platform chooses among them |
fonts-fusuma (default), fonts-material, fonts-legible, … | the font presets (ten OFL families in the catalog) |
icons | the Lucide icon set, 2431 icons as a typed Icon enum |
box-model | min and max sizes, margins, justify, align_self; a node grows 16 bytes, so a chip leaves it off |
alloc | screens described as data (Ui) and views over a Vec |
async | Task::perform, Inbox, blocking: work that takes time; needs std |
multithreading | worker threads for the Vello CPU renderer |
toml | fusuma.toml: renderer, fonts and theme settings from a file |
vector | LottieBox and SvgBox |
A first program
The shape is Elm's: a state, the messages that can change it, one update, and a view that is a function of the state.
use fusuma::{Children, Env, Program, Runner, Task, button, text_fmt};
use fusuma_platform_desktop::{Options, run};
struct Counter;
#[derive(Clone, Copy)]
enum Msg {
Up,
Down,
}
impl Program for Counter {
type State = i32;
type Msg = Msg;
fn init() -> i32 {
0
}
fn update(count: &mut i32, msg: Msg) -> Task<Msg> {
match msg {
Msg::Up => *count += 1,
Msg::Down => *count -= 1,
}
Task::none()
}
fn view<'a>(count: &'a i32, _env: &Env) -> impl Children<Msg> + 'a {
(
text_fmt(format_args!("Count: {count}")).title(),
button("Up").primary().on_press(Msg::Up),
button("Down").on_press(Msg::Down),
)
}
}
fn main() -> anyhow::Result<()> {
run(
Runner::<Counter, 64, 16>::new,
Options {
title: "Counter",
..Options::default()
},
)
}Three things to notice.
MsgisCopy. A message is a small value, so a task, a subscription and a log can hold it. A value that comes with an event (a slider's position) is made by afn(..) -> Msg, such as a variant.Runner<Counter, 64, 16>is the program on a tree of 64 nodes with room for 16 message handlers. The sizes are constants, so nothing is allocated while the app runs.- The view returns a tuple of views. A view is a cheap value made on the stack, compared with the tree that is already there, and dropped.
The program model has the rest: tasks, subscriptions, work that takes time, and how the view reacts to the screen.
The same app elsewhere
The view code does not change between these builds. The cargo features, the platform crate and, on a chip, a board file do.
- Desktop.
run(make, options)opens a window withwinitand picks the renderer from the hardware.RUST_LOG=infosays what it chose and why. - A browser. The gallery is built for
wasm32withnu scripts/web.nu build. One<canvas>carries the picture; a hidden page of semantic HTML next to it carries what a screen reader needs. Run it. - A board. A board is a directory of files (pins, panel controller, touch controller), and most Waveshare ESP32 boards are only a file. See Platforms and Boards.
- A terminal. The same views draw as a grid of text cells, in a terminal, over a serial console or on a panel.
fusuma.toml
Settings are data. Every key is optional.
[render]
backend = "auto" # auto, integer, vello-cpu or vello-gpu
[fonts]
preset = "legible" # fusuma, material, legible, plex or noto
[theme]
palette = "washi" # one of 27Where to go next
- Architecture: the layers, and what happens in a frame.
- Components: every view function, with its signature, an example that runs as a test, and the widget running live.
- The gallery: the components in use on every page, each one running in your browser.