Skip to main content

Crate mirui

Crate mirui 

Source
Expand description

mirui — a no_std, ECS-driven UI framework for embedded, desktop, and (planned) WebAssembly. Renders with 24.8 fixed-point subpixel precision on a software rasterizer designed for MCUs without an FPU; optionally runs on top of SDL2 (CPU or hardware-accelerated) on desktop.

§Quick Start

[dependencies]
mirui = { version = "0.42", features = ["sdl"] }

The snippet below builds against mirui’s default features and is verified by cargo test --doc. Swap FramebufSurface for mirui::surface::sdl::SdlSurface::new("hello", 480, 320) (with the sdl feature) to run on a desktop window instead of into a user-supplied flush callback.

use mirui::prelude::*;
use mirui::surface::framebuf::FramebufSurface;
use mirui::render::texture::ColorFormat;
use mirui::types::Rect;

let backend = FramebufSurface::with_format(
    480, 320, ColorFormat::RGBA8888,
    |_bytes: &[u8], _area: &Rect| { /* push to your display */ },
);
let mut app = App::new(backend);
app.with_default_widgets().with_default_systems();

let root = app.spawn_root().id();

ui! {
    :(
        parent: root
        world: &mut app.world
    :)

    header (
        bg_color: ColorToken::Primary,
        text_color: ColorToken::OnPrimary,
        text: "Hello mirui!",
        border_radius: 8
    ) {}
};

app.run();

§Other targets

mirui also runs bare-metal on RISC-V and ARM Cortex-M MCUs through surface::framebuf::FramebufSurface, and a Cargo workspace template builds the same UI code on both desktop and embedded targets unchanged. The full walkthrough — including ESP32-C3 wiring, the workspace layout, and a recipe for adding new target crates — lives in docs/quickstart.md.

§Module map

  • app: the App entry point, the Plugin trait, and bundled plugins.
  • core: cross-cutting infrastructure — cache, resource, the reactive runtime (Signal / Computed / Effect), perf tracing, timer.
  • ecs: World, Entity, Component, Resource, Query, System, SystemScheduler.
  • [ui]: widget tree primitives (Style, View, Theme, Dirty), ui::layout (flexbox + absolute positioning), and ui::widgets (built-in widget instances — buttons, sliders, lazy lists, effects).
  • render: software rasterizer, paths, textures, draw commands, font, and concrete render::backends (sw / sdl_gpu / wgpu / web_canvas).
  • input: input dispatch, gestures, hit-testing, focus, and visual input::feedback overlays.
  • surface: backend trait + bundled SDL2 / framebuffer / SDL_GPU / wgpu / web_canvas / Linux / NuttX implementations.
  • anim: easing, springs, motion components.
  • types: Color / Dimension / Fixed / Point / Rect / Transform / Viewport.

Modules§

anim
app
core
Cross-cutting infrastructure shared by render, ui, app, and platform.
ecs
input
Input pipeline. event carries the raw stream + dispatch + gesture recognition + scroll / focus / hit-test. feedback paints overlay visualisations of the input the framework just routed.
prelude
Glob-imports the types and macros nearly every application file needs. Default prelude — use mirui::prelude::*;.
render
surface
types
ui
Widget kinds and their shared infrastructure.

Macros§

__mirui_log
debug
error
info
path
scene
t
Build a Localized from a key literal. Returned wrapper resolves lazily through the World’s I18n resource.
trace
trace_span
trace_span!("name") — RAII statement: guard lives until end of scope. Multiple calls in one scope each get a unique binding.
ui
Spawn a widget tree, or forward to another #[compose] function.
warn

Attribute Macros§

compose
Inject a cx: &mut UiScope first parameter into the annotated function.
system
Attach perf-aware metadata to a fn(&mut World).
trace_fn
#[trace_fn("name")] — equivalent to trace_span!("name"); as the first statement of the fn body.

Derive Macros§

Component