dear-imgui-reflect
Reflection-based UI helpers for dear-imgui-rs: automatically generate Dear ImGui widgets for your Rust structs and enums, inspired by the C++ ImReflect library.
This crate exposes:
ImGuiValue– per-type editing widgets (low-level hook, similar toImInput<T>).ImGuiReflect– derive-based struct/enum editor that walks fields and dispatches toImGuiValue.ReflectSettings/MemberSettings– ImSettings-style configuration for numeric widgets, containers, tuples, maps, and more.
It is designed to integrate directly with dear-imgui-rs and the rest of this workspace.
Links
- Core ImGui bindings: https://crates.io/crates/dear-imgui-rs
- Examples (native):
examples/reflect_demo.rs - ImReflect (C++ reference library): https://github.com/Sven-vh/ImReflect
Compatibility
| Item | Version |
|---|---|
| Crate | 0.8.x |
| dear-imgui-rs | 0.8.x |
The optional glam and mint features track the same workspace versions as other crates in this repository.
See also: docs/COMPATIBILITY.md for the full workspace matrix.
Cargo Integration
Add the crate alongside dear-imgui-rs:
[]
= "0.8"
= "0.8"
Optional math interop:
[]
= "0.8"
= { = "0.8", = ["glam", "mint"] }
= "0.29" # or workspace version
= "0.5"
By default the derive feature is enabled so you can use #[derive(ImGuiReflect)].
Basic Usage
Define a struct and derive ImGuiReflect:
use dear_imgui_reflect as reflect;
use ImGuiReflect;
In your Dear ImGui frame, call reflect::input or the Ui extension:
use dear_imgui_reflect as reflect;
use ImGuiReflectExt;
use *; // re-export of dear-imgui-rs
Enums (C-like, no payload) can also derive ImGuiReflect and are rendered as combos or radios:
use ImGuiReflect;
// "combo" (default) or "radio"
Features Overview
- Derive-based struct/enum editing
#[derive(ImGuiReflect)]for named-field structs and C-like enums.- Field attributes for labels, skipping, numeric behavior, text widgets, tuples, and more.
- Numeric widgets (input / drag / slider)
- Per-field attributes:
as_input,as_drag,slider,slider_default_range. - Range and steps:
min,max,step,step_fast,speed. - Slider/drag flags:
log,wrap_around,clamp,always_clamp,no_input,no_round_to_format,clamp_on_input,clamp_zero_range,no_speed_tweaks. - Formatting helpers:
format = "...",hex,percentage,scientific,prefix = "...",suffix = "...". - Type-level defaults via
ReflectSettings::numerics_*. - Numeric presets via
NumericTypeSettingshelpers such aswith_float,with_hex,slider_0_to_1,slider_minus1_to_1,drag_with_speed, andpercentage_slider_0_to_1.
- Per-field attributes:
- Booleans
- Styles: checkbox (default), button, radio, dropdown.
- Per-field attributes:
bool_style = "checkbox|button|radio|dropdown",true_text,false_text.
- Text
- Single-line
String/ImStringwithhintandmin_width. - Multiline with
multiline, optionallines, andauto_resize. read_onlyfor non-editable text.display_onlyfor text labels without an input box (layout only).
- Single-line
- Containers & optionals
Option<T>– checkbox toggles presence; nested editor forSome(T).Vec<T>– insertable/removable/reorderable with tree-node dropdown.- Fixed arrays
[T; N](forT: ImGuiValue, currently tuned for small N). - Maps:
HashMap<String, V, S>andBTreeMap<String, V>with inline key+value editors, add/remove, optional table layout.
- Tuples
- Fixed tuples
(A, B),(A, B, C), … up to higher arity (up to 8 elements in the current implementation). - Global and per-member layout control: line vs grid, columns, dropdown, min width.
- Per-element overrides via
MemberSettingspaths like"tuple_field[0]".
- Fixed tuples
- Pointers & math types
Box<T>forwards toT: ImGuiReflect.Rc<T>/Arc<T>editable only when unique; otherwise rendered read-only.- Optional
glamandmintsupport (Vec2/3/4,mint::Vector2/3/4<f32>) viainput_float2/3/4.
- ImSettings-style configuration
- Global
ReflectSettingswith helpers:vec(),arrays(),maps(),tuples(),bools().numerics_i32(),numerics_f32(),numerics_u32(),numerics_f64().
- Per-member overrides via
ReflectSettings::for_member::<T>("field_name"). - Snapshot scope helper:
with_settings_scope(|| { ... }).
- Global
Field Attributes Cheat Sheet
These attributes are placed on struct fields inside a #[derive(ImGuiReflect)] type:
Containers & Maps
Option, Vec, Arrays
use ImGuiReflect;
Option<T>: a checkbox togglesSome(T)/None; when set toSome, a defaultT::default()is created and edited inline.Vec<T>: supports insertion (+), removal (-), and drag-to-reorder handles by default.- Arrays
[T; N](for supportedT) use similar layout, with optional reordering.
You can change the default behavior globally:
use dear_imgui_reflect as reflect;
with_settings;
Or override on a single member using MemberSettings:
use dear_imgui_reflect as reflect;
String-keyed Maps
dear-imgui-reflect supports:
HashMap<String, V, S>BTreeMap<String, V>
Example:
use ImGuiReflect;
use ;
Runtime behavior:
- The header shows
label [len]. - New entries are added via a
+button, opening a popup to edit both key and value before insertion. - Existing entries can be renamed by editing the key; the underlying map is updated.
- Right-clicking a row shows
Remove item(when allowed); right-clicking the header showsClear all. - Optional table layout via
MapSettings::use_table.
You can create const-maps (no insert/remove) globally or per member:
use dear_imgui_reflect as reflect;
Tuples & Per-Element Settings
Tuples are rendered as small groups of widgets. You can choose line or grid layout and override per-element behavior using MemberSettings.
use dear_imgui_reflect as reflect;
use ImGuiReflect;
Per-element numeric overrides use member paths of the form "field_name[index]":
use dear_imgui_reflect as reflect;
use ;
The same configuration can be expressed using MemberSettings helpers:
Global tuple defaults live in ReflectSettings::tuples():
use dear_imgui_reflect as reflect;
use TupleRenderMode;
with_settings;
Numeric Presets (Type-level Helpers)
NumericTypeSettings provides small helper methods to quickly configure
common slider/drag patterns without writing out all fields:
use dear_imgui_reflect as reflect;
use NumericTypeSettings;
These presets are thin convenience wrappers over the widget, range,
speed, clamp, and format fields and can be mixed with manual
configuration when needed.
glam / mint Integration
Enable the glam and/or mint features to get out-of-the-box ImGuiValue implementations for common math types:
[]
= { = "0.8", = ["glam", "mint"] }
= "0.29"
= "0.5"
use dear_imgui_reflect as reflect;
use ImGuiReflect;
use ;
use ;
These are rendered using input_float2/3/4 behind the scenes and participate in ImGuiReflect just like other supported field types.
Settings Scope Helper
ReflectSettings is stored globally (inside this crate) and can be modified at runtime. For localized overrides, use with_settings_scope, which snapshots settings, runs a closure, and then restores the previous state:
use dear_imgui_reflect as reflect;
use ;
Example Demo
The repository includes a full demo that exercises most features:
- File:
examples/reflect_demo.rs - Binary:
reflect_demo(part ofdear-imgui-examples)
Run it with:
ImReflect Compatibility (Overview)
dear-imgui-reflect is designed to closely mirror the behavior of the C++ ImReflect library for the covered Rust types.
A detailed checklist is maintained in docs/dear-imgui-reflect-compat.md. High-level status:
- Matched ([x])
- Primitive numerics: input/drag/slider selection,
as_input/as_drag/slider,min/max,step/step_fast,speed, log/clamp/wrap_around/flags, default half-range sliders. - Bool widgets: checkbox/button/radio/dropdown (including text labels).
- Text: single-line, multiline, hints,
read_only, display-only text. - Containers:
Option<T>,Vec<T>, small fixed arrays, string-keyed maps (HashMap<String, V>/BTreeMap<String, V>), including insertable/removable/reorderable and const-map configurations. - Tuples: line/grid layouts, dropdown wrapping, global defaults, per-member overrides, and per-element numeric overrides.
- Pointers:
Box<T>,Rc<T>,Arc<T>with unique/editable vs shared/read-only behavior. - Math interop:
glam::Vec2/3/4andmint::Vector2/3/4<f32>when features are enabled. - Global and member-level settings: ImSettings-style configuration for numerics, containers, tuples, bools, and read-only semantics.
- Primitive numerics: input/drag/slider selection,
- Implemented but more general / partially audited ([~])
- Core architecture: Rust traits + derive macros instead of a fully generic reflected type graph.
- Settings model: single global
ReflectSettingspluswith_settings_scopeinstead of a full push/pop stack ofImSettings.
- Intentionally incomplete or TODO ([ ])
- Non-string map keys and more exotic STL/container shapes.
- Additional math types (matrices, quaternions, etc.).
- Some of ImReflect's richer numeric/text formatting helpers.
When in doubt, refer to docs/dear-imgui-reflect-compat.md for the exact status of each feature and behavioral notes.
Limitations
- Derive macro currently supports:
- Structs with named fields.
- C-like enums without payloads.
- Map support is limited to
Stringkeys (forHashMap/BTreeMap); other key types need customImGuiValue+ wrappers. - Settings use a single global
ReflectSettingsinstance with manual snapshot helpers; there is no full push/pop stack like ImReflect'sImSettings, but common use-cases are covered. - For very deep or large object graphs, you may want to selectively
#[imgui(skip)]certain fields or use custom editors for performance.
License
MIT OR Apache-2.0