Skip to main content

Crate mirui

Crate mirui 

Source
Expand description

mirui — a no_std, ECS-driven UI framework for embedded, mobile, desktop, Linux, and WebAssembly targets. Layout, hit testing, and draw geometry use 24.8 fixed point before submission to the software framebuffer, SDL GPU, WGPU, Web Canvas, Linux framebuffer/DRM, and NuttX backends.

§Quick Start

[dependencies]
mirui = { version = "0.46", 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::PhysicalRect;

let backend = FramebufSurface::with_format(
    480, 320, ColorFormat::RGBA8888,
    |_bytes: &[u8], _area: PhysicalRect| { /* 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 in browsers through Web Canvas, on Android and iOS through direct WGPU or bounded software rasterization, on Linux framebuffer/DRM devices, on NuttX, and on bare-metal RISC-V and ARM Cortex-M MCUs through surface::framebuf::FramebufSurface. The mobile, ESP32-C3, and multi-target walkthrough 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.
  • text: bounded Unicode layout, shaping contracts, and font-format adapters.
  • anim: easing, springs, motion components.
  • audio (feature audio): fixed-capacity commands, static scores, parameterized tones, sinks, and integer PCM mixing.
  • 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
text
Bounded Unicode layout and shaping shared by widget measurement and render backends.
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