Expand description
§Dear ImGui - Rust Bindings with Docking Support
High-level Rust bindings for Dear ImGui, the immediate mode GUI library. This crate provides safe, idiomatic Rust bindings with full support for docking and multi-viewport features.
§Features
- Safe, idiomatic Rust API
- Full docking and multi-viewport support
- Builder pattern for widgets
- Memory-safe string handling
- Integration with modern Rust graphics ecosystems
§Quick Start
use dear_imgui_rs::*;
let mut ctx = Context::create();
let ui = ctx.frame();
ui.window("Hello World")
.size([300.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text("Hello, world!");
ui.text("This is Dear ImGui with docking support!");
});§Math Interop (mint/glam)
Many drawing and coordinate-taking APIs accept impl Into<sys::ImVec2> so you can pass:
[f32; 2]or(f32, f32)dear_imgui_sys::ImVec2mint::Vector2<f32>(viadear-imgui-sysconversions)- With optional integrations,
glam::Vec2via your ownInto<ImVec2>
Example:
let dl = ui.get_window_draw_list();
dl.add_line([0.0, 0.0], [100.0, 100.0], [1.0, 1.0, 1.0, 1.0]).build();
// Also works with mint::Vector2<f32>
let a = mint::Vector2 { x: 10.0, y: 20.0 };
let b = mint::Vector2 { x: 30.0, y: 40.0 };
dl.add_rect(a, b, [1.0, 0.0, 0.0, 1.0]).build();§Textures (ImGui 1.92+)
You can pass either a legacy TextureId or an ImGui-managed TextureData (preferred):
// 1) Legacy handle
let tex_id = texture::TextureId::new(0x1234);
ui.image(tex_id, [64.0, 64.0]);
// 2) Managed texture (created/updated/destroyed via DrawData::textures())
let mut tex = texture::TextureData::new();
tex.create(texture::TextureFormat::RGBA32, 256, 256);
// fill pixels / request updates ...
ui.image(&mut *tex, [256.0, 256.0]);Lifetime note: when using &TextureData, ensure it remains alive through rendering of the frame.
§Texture Management Guide
- Concepts:
TextureId: legacy plain handle (e.g., GL texture name, Vk descriptor).TextureData: managed CPU-side description with status flags and pixel buffer.TextureRef: a small wrapper used by widgets/drawlist, constructed from either of the above.
- Basic flow:
- Create
TextureDataand callcreate(format, w, h)to allocate pixels. - Fill/modify pixels; call
set_status(WantCreate)for initial upload, orWantUpdateswithUpdateRectfor sub-updates.TextureData::set_data()is a convenience which copies data and marks an update. - Use the texture in UI via
ui.image(&mut tex, size)or drawlist APIs. - In your renderer, during
render(), iterateDrawData::textures()and honor the requests (Create/Update/Destroy), then set status back toOK/Destroyed.
- Create
- Alternatives: when you already have a GPU handle, pass
TextureIddirectly.
§Renderer Integration (Modern Textures)
When integrating a renderer backend (WGPU, OpenGL, etc.) with ImGui 1.92+:
- Set
BackendFlags::RENDERER_HAS_TEXTURESon the ImGuiIobefore building the font atlas. - Each frame, iterate
DrawData::textures()and honor all requests:WantCreate: create a GPU texture, upload pixels, assign a non-zero TexID back to ImGui, then set status toOK.WantUpdates: upload pendingUpdateRects, then set status toOK.WantDestroy: delete/free the GPU texture and set status toDestroyed.
- When binding textures for draw commands, do not rely only on
DrawCmdParams.texture_id. With the modern system it may be0. Resolve the effective id at bind time usingImDrawCmd_GetTexID(raw_cmd)along with your renderer state. - Optional: some backends perform a font-atlas fallback upload on initialization.
This affects only the font texture for the first frame; user textures go through
the modern
ImTextureDatapath.
Pseudocode outline:
// 1) Configure context
io.backend_flags |= BackendFlags::RENDERER_HAS_TEXTURES;
// 2) Per-frame: handle texture requests
for tex in draw_data.textures() {
match tex.status() {
WantCreate => { create_gpu_tex(tex); tex.set_tex_id(id); tex.set_ok(); }
WantUpdates => { upload_rects(tex); tex.set_ok(); }
WantDestroy => { destroy_gpu_tex(tex); tex.set_destroyed(); }
_ => {}
}
}
// 3) Rendering: resolve texture at bind-time
for cmd in draw_list.commands() {
match cmd {
Elements { cmd_params, raw_cmd, .. } => {
let effective = unsafe { sys::ImDrawCmd_GetTexID(raw_cmd) };
bind_texture(effective);
draw(cmd_params);
}
_ => { /* ... */ }
}
}§Colors (ImU32 ABGR)
Dear ImGui uses a packed 32-bit color in ABGR order for low-level APIs (aka ImU32).
When you need a packed color (e.g. TableSetBgColor), use colors::Color::to_imgui_u32():
// Pack RGBA floats to ImGui ABGR (ImU32)
let abgr = Color::rgb(1.0, 0.0, 0.0).to_imgui_u32();
ui.table_set_bg_color_u32(TableBgTarget::CellBg, abgr, -1);For draw-list helpers you can continue to pass [f32;4] or use draw::ImColor32 which
represents the same ABGR packed value in a convenient wrapper.
§Text Input (String vs ImString)
This crate offers two ways to edit text:
- String-backed builders:
ui.input_text(label, &mut String)andui.input_text_multiline(label, &mut String, size).- Internally stage a growable UTF‑8 buffer for the call and copy the
edited bytes back into your
Stringafterwards. - For very large fields, use
.capacity_hint(bytes)on the builder to reduce reallocations, e.g.:ui.input_text("Big", big) .capacity_hint(64 * 1024) .build();
- Internally stage a growable UTF‑8 buffer for the call and copy the
edited bytes back into your
- ImString-backed builders:
ui.input_text_imstr(label, &mut ImString)andui.input_text_multiline_imstr(label, &mut ImString, size).- Zero‑copy: pass your
ImStringbuffer directly to ImGui. - Uses ImGui’s
CallbackResizeunder the hood to grow the same buffer the widget edits — no copy before/after the call.
- Zero‑copy: pass your
Choose String for convenience (especially for small/medium inputs). Prefer ImString when you want to avoid copies for large or frequently edited text.
§Low-level Draw APIs
Draw list wrappers expose both high-level primitives and some low-level building blocks:
-
Concave polygons (ImGui 1.92+):
DrawListMut::add_concave_poly_filled(&[P], color)fills an arbitrary concave polygon.DrawListMut::path_fill_concave(color)fills the current path using the concave tessellator.- Note: requires Dear ImGui 1.92 or newer in
dear-imgui-sys.
-
Channels splitting:
DrawListMut::channels_split(count, |channels| { ... })splits draw into multiple channels and automatically merges on scope exit. Callchannels.set_current(i)to select a channel.
-
Clipping helpers:
push_clip_rect,push_clip_rect_full_screen,pop_clip_rect,with_clip_rect,clip_rect_min,clip_rect_max.
-
Unsafe prim API (for custom geometry):
prim_reserve,prim_unreserve,prim_rect,prim_rect_uv,prim_quad_uv,prim_write_vtx,prim_write_idx,prim_vtx.- Safety: these mirror ImGui’s low-level geometry functions. Callers must respect vertex/index counts, write exactly the reserved amounts, and ensure valid topology. Prefer high-level helpers unless you need exact control.
-
Callbacks during draw:
- Safe builder:
DrawListMut::add_callback_safe(|| { ... }).build()registers anFnOnce()that runs when the draw list is rendered. Resources captured by the closure are freed when the callback runs. If the draw list is never rendered, the callback will not run and its resources won’t be reclaimed. - Raw:
unsafe DrawListMut::add_callbackallows passing a C callback and raw userdata; see method docs for safety requirements.
- Safe builder:
Re-exports§
pub extern crate dear_imgui_sys as sys;
Re-exports§
pub use crate::Direction as ArrowDirection;pub use self::input::*;pub use self::platform_io::*;pub use render::*;pub use texture::*;
Modules§
- atlas
- Font atlas management for Dear ImGui v1.92+
- button
- Buttons
- color
- Color widgets
- combo
- Combo boxes
- drag
- Drag slider widgets for numeric input
- font
- Font runtime data and operations
- glyph
- Font glyph data structures
- glyph_
ranges Deprecated - Deprecated glyph ranges helpers.
- image
- Image widgets
- input
- Input types (mouse, keyboard, cursors)
- internal
- Internal low-level types
- list_
box - List boxes
- logging
- Logging utilities for Dear ImGui
- menu
- Menus and menu bars
- misc
- Miscellaneous widgets
- platform_
io - Platform IO functionality for Dear ImGui
- plot
- Basic plots
- popup
- Popups and modals
- progress
- Progress bars
- render
- Rendering system for Dear ImGui
- selectable
- Selectable items
- slider
- Sliders
- tab
- Tabs
- table
- Tables
- text
- Text helpers
- texture
- Texture management for Dear ImGui
- tooltip
- Tooltips
- tree
- Trees and collapsing headers
Macros§
- create_
token - This is a macro used internally by dear-imgui to create StackTokens representing various global state in Dear ImGui.
- im_str
- Creates an ImString from a string literal at compile time
- imgui_
debug - Macro for conditional debug logging
- imgui_
error - Macro for conditional error logging
- imgui_
info - Macro for conditional info logging
- imgui_
trace - Macro for conditional tracing
- imgui_
warn - Macro for conditional warning logging
Structs§
- Angle
Slider - Builder for an angle slider widget.
- Backend
Flags - Backend capabilities
- Button
- Builder for button widget
- Button
Flags - Flags for invisible buttons
- Clip
Rect Token - Tracks a pushed clip rect that will be popped on drop.
- Color
- RGBA color with 32-bit floating point components
- Color
Button - Builder for a color button widget
- Color
Edit3 - Builder for a 3-component color edit widget
- Color
Edit4 - Builder for a 4-component color edit widget
- Color
Edit Flags - Flags for color edit widgets
- Color
Picker3 - Builder for a 3-component color picker widget
- Color
Picker4 - Builder for a 4-component color picker widget
- Color
Stack Token - Tracks a color pushed to the color stack that can be popped by calling
.end()or by dropping. - Column
Builder - Chainable builder for a single column. Use
.done()to return to the table builder. - Combo
Box - Builder for a combo box widget
- Combo
BoxFlags - Flags for combo box widgets
- Combo
BoxToken - Tracks a combo box that can be ended by calling
.end()or by dropping - Config
Flags - Configuration flags
- Context
- An imgui context.
- Disabled
Token - Tracks a disabled scope begun with
Ui::begin_disabledand ended on drop. - Dock
Builder - DockBuilder API for programmatic dock layout creation
- Dock
Flags - Flags for dock nodes
- Dock
Node - Opaque reference to an ImGui dock node, valid for the duration of the current frame.
- Dock
Node Flags - Flags for dock nodes
- Drag
- Builder for a drag slider widget
- Drag
Drop Flags - Flags for drag and drop operations
- Drag
Drop Payload - Raw payload data
- Drag
Drop Payload Empty - Empty payload (no data, just notification)
- Drag
Drop Payload Pod - Typed payload with data
- Drag
Drop Source - Builder for creating drag drop sources
- Drag
Drop Source Tooltip - Token representing an active drag source tooltip
- Drag
Drop Target - Drag drop target for accepting payloads
- Drag
Range - Builder for a drag range slider widget
- Draw
List Mut - Object implementing the custom draw API.
- Dummy
Clipboard Backend - Non-functioning placeholder clipboard backend
- Focus
Scope Token - Tracks a pushed focus scope, popped on drop.
- Font
- A font instance with runtime data
- Font
Atlas - Font atlas that manages multiple fonts and their texture data
- Font
Atlas Texture - Handle to a font atlas texture
- Font
Config - Font configuration for loading fonts with v1.92+ features
- FontId
- A font identifier
- Font
Loader - Font loader interface for custom font backends
- Font
Loader Flags - Font loader flags for controlling font loading behavior
- Font
Stack Token - Tracks a font pushed to the font stack that can be popped by calling
.end()or by dropping. - Glyph
- A single font glyph with its rendering data
- Glyph
Ranges Deprecated - Predefined glyph ranges for common character sets
- Glyph
Ranges Builder Deprecated - Builder for creating custom glyph ranges
- Group
Token - Tracks a layout group that can be ended with
endor by dropping. - Hovered
Flags - Flags for hovering detection
- Id
- Strongly-typed wrapper around ImGuiID.
- IdStack
Token - Tracks an ID pushed to the ID stack that can be popped by calling
.pop()or by dropping. Seecrate::Ui::push_idfor more details. - ImString
- A UTF-8 encoded, growable, implicitly nul-terminated string.
- Image
- Builder for an image widget
- Image
Button - Builder for an image button widget
- Input
Double - Builder for double input widget
- Input
Float - Builder for float input widget
- Input
Float2 - Builder for a 2-component float input widget.
- Input
Float3 - Builder for a 3-component float input widget.
- Input
Float4 - Builder for a 4-component float input widget.
- Input
Int - Builder for integer input widget
- Input
Int2 - Builder for a 2-component int input widget.
- Input
Int3 - Builder for a 3-component int input widget.
- Input
Int4 - Builder for a 4-component int input widget.
- Input
Scalar - Builder for an input scalar widget.
- Input
ScalarN - Builder for an input scalar array widget.
- Input
Text - Builder for a text input widget
- Input
Text Callback - Callback flags for InputText widgets
- Input
Text ImStr - Builder for a text input backed by ImString (zero-copy)
- Input
Text Multiline - Builder for multiline text input widget
- Input
Text Multiline ImStr - Builder for multiline text input backed by ImString (zero-copy)
- Input
Text Multiline With Cb - Multiline InputText with attached callback handler
- Io
- Settings and inputs/outputs for imgui-rs This is a transparent wrapper around ImGuiIO
- Item
Width Stack Token - Tracks a change made with
Ui::push_item_widththat can be popped by callingItemWidthStackToken::endor dropping. - ListBox
- Builder for a list box widget
- List
BoxToken - Tracks a list box that can be ended by calling
.end()or by dropping - List
Clipper - Used to render only the visible items when displaying a long list of items in a scrollable area.
- List
Clipper Iterator - List
Clipper Token - List clipper is a mechanism to efficiently implement scrolling of large lists with random access.
- Main
Menu BarToken - Tracks a main menu bar that can be ended by calling
.end()or by dropping - Menu
BarToken - Tracks a menu bar that can be ended by calling
.end()or by dropping - Menu
Token - Tracks a menu that can be ended by calling
.end()or by dropping - Modal
Popup - Builder for a modal popup
- Modal
Popup Token - Tracks a modal popup that can be ended by calling
.end()or by dropping - Node
Rect - Rectangle in screen space.
- OldColumn
Flags - Flags for old columns system
- Passthrough
Callback - This is a ZST which implements InputTextCallbackHandler as a passthrough.
- Payload
IsWrong Type - Error type for payload type mismatches
- Plot
Histogram - Builder for a plot histogram widget
- Plot
Lines - Builder for a plot lines widget
- Popup
Flags - Flags for popup functions
- Popup
Token - Tracks a popup that can be ended by calling
.end()or by dropping - Progress
Bar - Builder for a progress bar widget.
- Selectable
- Builder for a selectable widget.
- Selectable
Flags - Flags for selectables
- Shared
Font Atlas - A shared font atlas that can be used across multiple contexts
- Slider
- Builder for slider widgets
- Slider
Flags - Flags for slider widgets
- Style
- User interface style/colors
- Style
Stack Token - Tracks a style pushed to the style stack that can be popped by calling
.end()or by dropping. - Suspended
Context - A suspended Dear ImGui context
- TabBar
- Builder for a tab bar
- TabBar
Flags - Flags for tab bar widgets
- TabBar
Token - Token representing an active tab bar
- TabItem
- Builder for a tab item
- TabItem
Flags - Flags for tab item widgets
- TabItem
Token - Token representing an active tab item
- Table
Builder - Builder for ImGui tables with columns + headers + sizing/freeze options.
- Table
Column Flags - Flags for table columns
- Table
Column Setup - Table column setup information
- Table
Column Sort Spec - One column sort spec.
- Table
Flags - Flags for table widgets
- Table
Header Data - Safe description of a single angled header cell.
- Table
RowFlags - Flags for table rows
- Table
Sort Specs - Table sort specs view.
- Table
Sort Specs Iter - Iterator over
TableColumnSortSpec. - Table
Token - Tracks a table that can be ended by calling
.end()or by dropping - Text
Callback Data - This struct provides methods to edit the underlying text buffer that Dear ImGui manipulates. Primarily, it gives remove_chars, insert_chars, and mutable access to what text is selected.
- Text
Filter - Helper to parse and apply text filters
- Text
Wrap PosStack Token - Tracks a change made with
Ui::push_text_wrap_posthat can be popped by callingTextWrapPosStackToken::endor dropping. - Tooltip
Token - Tracks a tooltip that can be ended by calling
.end()or by dropping - Tree
Node - Builder for a tree node widget
- Tree
Node Flags - Flags for tree node widgets
- Tree
Node Token - Tracks a tree node that can be popped by calling
.pop()or by dropping - Ui
- Represents the Dear ImGui user interface for one frame
- UiBuffer
- Internal buffer for UI string operations
- Vertical
Slider - Builder for a vertical slider widget.
- Window
- Represents a window that can be built
- Window
Class - Window class for docking configuration
- Window
Flags - Configuration flags for windows
- Window
Token - Token representing an active window
Enums§
- Condition
- Condition for setting window/widget properties
- Direction
- A cardinal direction
- Font
Source - A source for font data with v1.92+ dynamic font support
- History
Direction - Direction for history navigation
- ImGui
Error - Errors that can occur in Dear ImGui operations
- Sort
Direction - Sorting direction for table columns.
- Split
Direction - Direction for splitting dock nodes
- Style
Color - Style color identifier
- Style
Var - A temporary change in user interface style
- Table
BgTarget - Target for table background colors.
- Tree
Node Id - Tree node ID that can be constructed from different types
Constants§
- HAS_
DOCKING - Check if docking features are available
- HAS_
FREETYPE - Check if FreeType font rasterizer support is compiled in
- HAS_
WASM - Check if WASM support is compiled in (sys layer)
- VERSION
Traits§
- Clipboard
Backend - Trait for clipboard backends
- ImGui
Platform - Trait for platform backends with unified error handling
- ImGui
Renderer - Trait for backend renderers with unified error handling
- Input
Text Callback Handler - This trait provides an interface which ImGui will call on InputText callbacks.
- Into
ImGui Error - Trait for converting backend errors to ImGuiError
- Safe
String Conversion - Helper trait for safe string conversion
Functions§
- dear_
imgui_ version - Returns the underlying Dear ImGui library version
Type Aliases§
- ImGui
Result - Result type for Dear ImGui operations
- ImStr
- Represents a borrowed string that can be either a Rust string slice or an ImString