microui-redux 0.3.1

Idiomatic Rust MicroUI (immediate mode GUI) library port
Documentation

Rxi's Microui Port to Idiomatic Rust

Crate

This was originally a port of Rxi's MicroUI to Rust language. We used C2Rust to create the initial code and iterated > 60 times to make microui-rs. This (microui-redux) builds on top of that by much more like custom rendering widget for 3D, dialogs, file dialog!

While we tried to keep the usage pattern as close to the original as possible, we wanted also to make it as idiomatic to Rust as possible (closures, safety, ...). In contrast with microui-rs, this version uses the standard library to give us more flexibity and switch to closures for all container related operations (Window, Panel, Columns, ...).

Demo

Clone and build the demo (SDL2 & glow) / Tested on linux:

$ cargo run --example demo-full

random

Key Concepts

  • Context: owns the atlas, renderer handle, user input and root windows. Each frame starts by feeding input into the context, then calling context.window(...) for every visible window or popup.
  • Container: describes one layout surface. Every window, panel, popup or custom widget receives a mutable Container that exposes high-level widgets (buttons, sliders, etc.) and lower-level drawing helpers.
  • Layout manager: controls how cells are sized. Container::with_row lets you scope a set of widgets to a row of SizePolicys, while nested columns can be created with container.column(|ui| { ... }).
  • Renderer: any backend that implements the Renderer trait can be used. The included SDL2 + glow example demonstrates how to batch the commands produced by a container and upload them to the GPU.
ctx.window(&mut main_window, ContainerOption::NONE, |ui| {
    let widths = [SizePolicy::Fixed(120), SizePolicy::Remainder(0)];
    ui.with_row(&widths, SizePolicy::Auto, |ui| {
        ui.label("Name");
        ui.textbox_ex(&mut self.name, WidgetOption::NONE);
    });
});

Images and textures

Widgets take an Image enum, which can reference either a slot or an uploaded texture at runtime:

let texture = ctx.load_image_from(ImageSource::Png { bytes: include_bytes!("assets/IMAGE.png") })?;
ui.button_ex2(
    "External Image",
    Some(Image::Texture(texture)),
    WidgetOption::NONE,
    WidgetFillOption::ALL,
);
  • Image::Slot renders an entry from the atlas and benefits from batching.
  • Image::Texture targets renderer-owned textures. The command list flushes before drawing the texture so the backend can bind the correct resource.
  • WidgetFillOption controls which interaction states draw a filled background; use WidgetFillOption::ALL to keep the default normal/hover/click fills.
  • Use Context::load_image_rgba/load_image_from and Context::free_image to manage the lifetime of external textures.

Cargo features

  • builder (default) – enables the runtime atlas builder and PNG decoding helpers used by the examples.
  • png_source – allows serialized atlases and ImageSource::Png { .. } uploads to stay compressed.
  • save-to-rust – emits the current atlas as Rust code so it can be embedded in your binary.

Disabling default features leaves only the raw RGBA upload path (ImageSource::Raw { .. }). The demos require builder, so run them with --features builder if you build with --no-default-features.

Text rendering and layout

  • Container text widgets automatically center the font’s baseline inside each cell, and every line gets a small vertical pad so glyphs never touch the widget borders.
  • Container::text_with_wrap supports explicit wrapping modes (TextWrap::None or TextWrap::Word) and renders wrapped lines back-to-back inside an internal column, so the block keeps the outer padding without adding extra spacing between lines.
  • Custom drawing code can call Container::draw_text directly when precise placement is required, or use draw_control_text to get automatic alignment/clip handling.

Version 0.3

  • Use std (Vec, parse, ...)
  • Containers contain clip stack and command list
  • Move begin_*, end_* functions to closures
  • Move to AtlasRenderer Trait
  • Remove/Refactor Pool
  • Change layout code
  • Treenode as tree
  • Manage windows lifetime & ownership outside of context (use root windows)
  • Manage containers lifetime & ownership outside of contaienrs
  • Software based textured rectangle clipping
  • Add Atlasser to the code
    • Runtime atlasser
      • Icon
      • Font (Hash Table)
    • Separate Atlas Builder from the Atlas
    • Builder feature
    • Save Atlas to rust
    • Atlas loader from const rust
  • Image widget
  • Png Atlas source
  • Pass-Through rendering command (for 3D viewports)
  • Custom Rendering widget
    • Mouse input event
    • Keyboard event
    • Text event
    • Drag outside of the region
    • Rendering
  • Dialog support
  • File dialog
  • API/Examples loop/iterations
    • Simple example
    • Full api use example (3d/dialog/..)
  • Documentation