Rxi's Microui Port to Idiomatic Rust
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 , 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

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
Containerthat exposes high-level widgets (buttons, sliders, etc.) and lower-level drawing helpers. - Layout manager: controls how cells are sized.
Container::with_rowlets you scope a set of widgets to a row ofSizePolicys, while nested columns can be created withcontainer.column(|ui| { ... }). - Renderer: any backend that implements the
Renderertrait 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;
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?;
ui.button_ex2;
Image::Slotrenders an entry from the atlas and benefits from batching.Image::Texturetargets renderer-owned textures. The command list flushes before drawing the texture so the backend can bind the correct resource.WidgetFillOptioncontrols which interaction states draw a filled background; useWidgetFillOption::ALLto keep the default normal/hover/click fills.- Use
Context::load_image_rgba/load_image_fromandContext::free_imageto 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 andImageSource::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_wrapsupports explicit wrapping modes (TextWrap::NoneorTextWrap::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_textdirectly when precise placement is required, or usedraw_control_textto 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
- Runtime atlasser
- 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