Fusuma

Docs

Getting started

Add one crate, write a program, run it on a desktop, a board or a page.

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.

FeatureWhat it adds
std (default)the standard library; without it the crate is no_std
renderer-vello-cpu (default), renderer-vello-gpu, renderer-integerthe 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)
iconsthe Lucide icon set, 2431 icons as a typed Icon enum
box-modelmin and max sizes, margins, justify, align_self; a node grows 16 bytes, so a chip leaves it off
allocscreens described as data (Ui) and views over a Vec
asyncTask::perform, Inbox, blocking: work that takes time; needs std
multithreadingworker threads for the Vello CPU renderer
tomlfusuma.toml: renderer, fonts and theme settings from a file
vectorLottieBox 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.

  • Msg is Copy. 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 a fn(..) -> 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 same app in three buildsOne Program builds for a microcontroller with the integer renderer and the ESP platform crate, for a desktop window with Vello and winit, and for a web page as WebAssembly with Vello and a canvas.One appa Program: State, Msg, update, viewA chipfusuma, default-features = falserenderer-integerfusuma-platform-espa board file: pins, panel, touchESP32-C6 · S3 · P4A desktop windowfusuma (defaults)renderer-vello-cpu or -gpufusuma-platform-desktopwinit: Linux · macOS · Windowsfusuma.toml picks the rendererA web pagefusuma, built for wasm32Vello: GPU, else CPUone canvas + hidden ARIA pageno JavaScript frameworkthe live demo on this siteFeatures add up in a build; the platform crate picks among the renderers that are linked.
The view code does not change; the cargo features and the platform crate do.

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 with winit and picks the renderer from the hardware. RUST_LOG=info says what it chose and why.
  • A browser. The gallery is built for wasm32 with nu 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 27

Where 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.