oxiui-egui — egui/eframe adapter for OxiUI
oxiui-egui is the egui/eframe adapter for OxiUI. It bridges OxiUI's backend-agnostic widget model to [egui] — the popular immediate-mode GUI library — and its [eframe] application shell. The adapter implements [oxiui_core::UiCtx] in terms of an egui::Ui, converts an OxiUI [Palette] / [oxiui_theme::DesignTokens] into egui::Visuals / egui::Style, loads OxiFont bytes into egui's font system, and forwards OxiUI [UiEvent]s into egui's input queue.
Both egui and eframe are Pure Rust GUI frameworks, so this adapter keeps the OxiUI stack C/C++-free. (eframe's default rendering goes through wgpu, the Rust graphics boundary, which dispatches to OS-provided GPU drivers at runtime.) Because egui is immediate-mode while OxiUI's UiCtx is also immediate-mode, the mapping is direct: each UiCtx call forwards straight to its egui equivalent. #![forbid(unsafe_code)] is enforced crate-wide.
Installation
[]
= "0.2.1"
oxiui-egui depends only on [egui] itself (plus oxiui-core/oxiui-text/oxiui-theme) —
bring your own [eframe] (or other windowing/event-loop shell) if you need a full
native application; every function here takes an &egui::Context / &mut egui::Ui
so it works the same whether that context comes from eframe or a hand-rolled
egui-winit + wgpu loop.
Quick Start
Wrap an egui::Ui as an OxiUI [UiCtx] and render OxiUI widgets directly:
use UiCtx;
use EguiUiCtx;
Applying an OxiUI palette to an egui context
use ;
use palette_to_egui_visuals;
Caching adapter for an eframe app
use StatefulEguiAdapter;
let mut adapter = new
.with_palette
.with_design_tokens
.with_font_bytes;
// In your eframe::App::update():
adapter.apply; // cheap after the first frame if the theme is unchanged
API Overview
EguiUiCtx<'a> — the UiCtx implementation
Wraps an &mut egui::Ui and implements [oxiui_core::UiCtx], forwarding each widget call to its egui equivalent.
| Method | Description |
|---|---|
EguiUiCtx::new(ui) |
Wrap an egui Ui reference |
response() |
The egui Response of the most recently rendered widget |
clipboard_get() |
Read the most-recently-copied text from egui's output queue (intra-frame) |
clipboard_set(text) |
Queue a copy-to-clipboard command via egui |
Implemented UiCtx widgets (all forwarding to egui): heading, label, button, text_input, checkbox, slider, dropdown, image, separator, spacer, scroll_area, tooltip, popup, modal, horizontal, vertical, grid, menu_bar, rich_text, drag_source, drop_target.
Theme conversion functions
| Function | Description |
|---|---|
palette_to_egui_visuals(&Palette) -> egui::Visuals |
Map an OxiUI palette to an egui colour scheme |
palette_to_egui_visuals_with_tokens(&Palette, &DesignTokens) -> egui::Style |
Palette visuals plus token-driven spacing and corner radius |
tokens_to_egui_style(&DesignTokens, &TypographyScale) -> egui::Style |
Full token + typography mapping to all five egui::TextStyle variants |
Font loading
| Function | Description |
|---|---|
load_font_into_egui(&egui::Context, Vec<u8>) -> Result<(), UiError> |
Validate and install a single font as the "OxiFont" family |
load_fonts_into_egui(&[(&str, Vec<u8>)], &egui::Context) -> Result<(), UiError> |
Install multiple named "OxiFont-<name>" families |
Both validate font bytes via [oxiui_text::TextPipeline::from_bytes] and return [UiError::Render] on invalid input.
Event forwarding
| Function | Description |
|---|---|
forward_event_to_egui(&egui::Context, &UiEvent) |
Forward an OxiUI [UiEvent] (IME, keyboard, pointer, resize) into egui's input queue |
Handled families: IME (ImePreedit, ImeCommit), keyboard (KeyDown, KeyUp, KeyPress), pointer (MouseMove, Mouse, MouseDown, MouseUp), and Resize (noted only — egui resize is driven by RawInput.screen_rect). Other variants are silently ignored.
Widget bridge
| Item | Description |
|---|---|
OxiWidget<'a> |
Wraps a &mut dyn oxiui_core::Widget so it can be placed in an egui layout via ui.add(...); implements egui::Widget. OxiWidget::new(widget) |
Adapters
| Item | Description |
|---|---|
EguiAdapter |
Stateless builder: new(), with_palette(p), build() -> impl Fn(&egui::Context) |
StatefulEguiAdapter |
Per-frame caching adapter (see below) |
StatefulEguiAdapter
Caches expensive operations across frames so repeated apply calls are cheap when the theme is stable.
| Method | Description |
|---|---|
new() |
Empty adapter |
with_palette(p) |
Set the palette (visuals recomputed only on change) |
with_design_tokens(tokens, typography) |
Apply a token-driven style once on the first frame |
with_font_bytes(bytes) |
Load fonts once on the first frame |
set_palette(p) |
Update the live palette (marks visuals stale) |
apply(&egui::Context) |
Apply state for one frame (fonts/tokens once, visuals on change) |
visuals_recompute_count (field) |
Number of times visuals were recomputed (instrumentation) |
fonts_load_count (field) |
Number of set_fonts calls (≤ 1 in normal use) |
Accessibility bridge (a11y feature)
Bridges oxiui-accessibility's A11yTree into accesskit::TreeUpdates, feeding
egui's built-in AccessKit integration (forward the update to the platform adapter,
e.g. accesskit_winit::Adapter::update_if_active).
| Item | Description |
|---|---|
oxiui_tree_to_accesskit(&A11yNode) -> TreeUpdate |
Full (non-diff) conversion of an OxiUI a11y tree. |
diff_a11y_trees(&A11yTree, &A11yTree) -> TreeUpdate |
Minimal diff between two tree states. |
A11yEguiBridge |
Stateful bridge that retains the previous tree; new(), update(&root) -> TreeUpdate (full on the first frame, diff thereafter), set_focus(Option<NodeId>) -> TreeUpdate. |
Table bridge (table feature)
Convenience wrappers around oxiui-table's Table::render_egui / EguiTableState.
| Item | Description |
|---|---|
render_sorted_table(&mut Table<S>, &mut Ui, &mut HeaderSortState, &mut EguiTableState) -> Vec<TableEvent> |
Renders the table and applies any TableEvent::SortChanged to sort_state automatically. |
apply_selection_events(&[TableEvent], &mut SelectionModel) -> bool |
Applies TableEvent::RowSelected events to a selection model; returns true if selection changed. |
Feature Flags
default is empty — both features below are opt-in.
| Feature | Pulls in | Description |
|---|---|---|
table |
oxiui-table (egui-table feature) |
Enables the table_bridge module: render_sorted_table, apply_selection_events. |
a11y |
oxiui-accessibility, accesskit |
Enables the a11y module: bridges an OxiUI A11yTree into accesskit::TreeUpdates for egui's built-in AccessKit integration. |
Errors
Functions that can fail return [oxiui_core::UiError]. Font-loading helpers use the UiError::Render variant for invalid font bytes; see the oxiui-core error table for all variants.
Adapter Notes and Deviations
The adapter is faithful to egui 0.35's API; a few mappings are approximate and documented inline:
Key::Character/Key::Namedare forwarded viaegui::Key::from_name; unrecognised names fall back toegui::Key::F12.rich_texthonours span colour, size, and italics;egui0.35'sTextFormathas no per-span bold field, so bold spans render at the default weight.Palettecarries no error/warning/success colours (those live onoxiui_theme::ExtendedPalette), so egui'swarn_fg_color/error_fg_colorkeep their defaults.- IME preedit cursor. egui 0.35's
ImeEvent::Preeditgained anactive_range_chars: Option<Range<usize>>field.forward_event_to_eguiconvertsUiEvent::ImePreedit's byte-offsetcursorrange into that char-offset range (the same conversionegui-winitapplies to raw OS IME events), usingstr::getso a range landing off a UTF-8 char boundary degrades toNoneinstead of panicking. On egui ≤ 0.34 there was nowhere to put this —ImeEvent::Preeditwas a bareString— so the cursor position was always dropped; it is now forwarded.
Related Crates
oxiui— the OxiUI facade crate.oxiui-core—UiCtx,Widget,Palette,UiEvent,UiError, response types.oxiui-theme—DesignTokens,TypographyScale, theming primitives.oxiui-text— font validation used by the font loaders.oxiui-iced— the alternative iced framework adapter.
License
Apache-2.0 — COOLJAPAN OU (Team Kitasan)