oxiui-dioxus — Dioxus adapter for OxiUI
oxiui-dioxus is the Dioxus backend adapter for OxiUI. Dioxus is a reactive, component-based framework: components are functions that return Element via the rsx! macro. This adapter bridges that retained, reactive model onto OxiUI's immediate-mode UiCtx closure API via two pieces: DioxusCtx, a UiCtx implementation that collects each widget call into an ordered list, and run_dioxus, a driver that executes a content closure against that context with a supplied theme.
Dioxus is dual-licensed MIT OR Apache-2.0, so this adapter carries no copyleft obligations. The adapter is configured to use Dioxus's minimal feature set (macro, html, signals, hooks, launch) — all Pure Rust. The desktop feature (wry/tao/WebKit/Chromium) is intentionally excluded because it pulls in C/C++ system dependencies that violate the COOLJAPAN Pure-Rust policy. The crate is fully usable with default = [] (collection mode) and pulls in the dioxus crate only when you enable --features dioxus.
Milestone status: As of M5,
run_dioxusexecutes the content closure in headless collection mode (no display, no Dioxus runtime) and returnsOk(()). Full native rendering — translating collected items into anrsx!element tree and launching viadioxus-native(the Pure-Rust Blitz/Vello renderer) — is deferred to M6.
Installation
[]
# Collection mode only — no Dioxus dependency
= "0.1.2"
# Enable Dioxus rendering (minimal Pure-Rust feature set; no wry/tao/WebKit)
= { = "0.1.2", = ["dioxus"] }
Quick Start
Collection mode (no dioxus feature, fully testable)
use DioxusCtx;
use UiCtx;
let mut ctx = default;
ctx.heading;
ctx.label;
let _resp = ctx.button;
assert_eq!;
assert_eq!;
Driving a content closure with a theme
use run_dioxus;
use cooljapan_dark;
run_dioxus
.expect;
API Overview
Types
| Item | Kind | Description |
|---|---|---|
DioxusCtx |
struct | UiCtx adapter that records each widget call as a "<kind>:<text>" string in its public items: Vec<String> field. Derives Debug and Default. |
Functions
| Function | Signature | Description |
|---|---|---|
run_dioxus |
run_dioxus<F>(palette: &dyn oxiui_core::Theme, content: F) -> Result<(), UiError> where F: FnOnce(&mut dyn UiCtx) |
Runs one Dioxus-backed UI frame. Executes content against a DioxusCtx in collection mode. Returns Ok(()) in M5. |
DioxusCtx as a UiCtx
DioxusCtx implements the three required UiCtx methods. All other UiCtx widget methods (slider, checkbox, dropdown, text_input, …) fall back to their default trait implementations, which report supported == false so callers can detect non-support and degrade gracefully.
| Method | Behaviour in DioxusCtx |
|---|---|
heading(&mut self, text) |
Pushes "heading:<text>" onto items. |
label(&mut self, text) |
Pushes "label:<text>" onto items. |
button(&mut self, label) |
Pushes "button:<label>" onto items; returns ButtonResponse { clicked: false, hovered: false } (collection mode never registers clicks). |
The items entries use the format "<kind>:<text>" (e.g. "label:Hello", "button:Quit"), letting headless tests assert on the exact widget sequence without a display server.
Feature Flags
| Feature | Default | Effect |
|---|---|---|
dioxus |
off | Enables the optional dioxus dependency with the minimal feature set (macro, html, signals, hooks, launch) — all Pure Rust. The desktop feature (wry/tao/WebKit, C/C++ deps) is excluded. With this feature off, the crate has only oxiui-core as a dependency. |
Errors
run_dioxus returns Result<(), oxiui_core::UiError>. In M5 it is always Ok(()). From M6 onward it will return UiError::Backend if the Dioxus launch reports an error. UiError is #[non_exhaustive]; see oxiui-core for the full variant list.
Palette mapping note
Dioxus renders via CSS-in-Rust (inline style="" attributes). The palette argument to run_dioxus is available for downstream consumers who format style strings from the palette colours; it is not automatically injected in M5. A helper palette_to_css_vars() is planned for M6 to emit :root { --background: #rrggbb; … } global CSS.
Architecture note
Because Dioxus is reactive (not immediate-mode), the adapter operates in two phases:
- Collection pass — the content closure is executed against a
DioxusCtx, accumulating widget descriptions initems. - Render pass (M6) — those items are translated into a Dioxus
rsx!/Elementtree and handed todioxus::launch()running on the Pure-Rustdioxus-nativerenderer.
In M5 only the collection pass is active, which is what makes the crate headless-testable and example-buildable without a display or any C/C++ dependencies.
Related Crates
| Crate | Role |
|---|---|
oxiui |
Facade crate; select this adapter with Backend::Dioxus under --features dioxus. |
oxiui-core |
Defines UiCtx, Theme, Palette, ButtonResponse, and UiError. |
oxiui-theme |
COOLJAPAN theme constructors (cooljapan_dark, dark, light) used as the palette argument. |
oxiui-egui |
Default immediate-mode adapter (egui + wgpu). |
oxiui-iced |
Retained-mode iced adapter. |
oxiui-slint |
Slint adapter (same collection-mode pattern as this crate). |
License
Apache-2.0 — COOLJAPAN OU (Team Kitasan)