1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//! # 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
//!
//! ```no_run
//! 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::ImVec2`
//! - `mint::Vector2<f32>` (via `dear-imgui-sys` conversions)
//! - With the optional `glam` feature, `glam::Vec2` directly (via `impl From<glam::Vec2> for ImVec2` in `dear-imgui-sys`)
//!
//! Example:
//! ```no_run
//! # use dear_imgui_rs::*;
//! # fn demo(ui: &Ui) {
//! 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();
//! // And with glam::Vec2 when the `glam` feature is enabled
//! #[cfg(feature = "glam")]
//! {
//! let a = glam::Vec2::new(10.0, 20.0);
//! let b = glam::Vec2::new(30.0, 40.0);
//! dl.add_rect(a, b, [0.0, 1.0, 0.0, 1.0]).build();
//! }
//! # }
//! ```
//!
//! ## Textures (ImGui 1.92+)
//!
//! You can pass either a legacy `TextureId` or an ImGui-managed `TextureData` (preferred):
//!
//! ```no_run
//! # use dear_imgui_rs::*;
//! # fn demo(ui: &Ui) {
//! // 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]);
//! # }
//! ```
//!
//! Note: `DrawData::textures()` is built from ImGui's internal `PlatformIO.Textures[]` list. If you
//! create `TextureData` yourself (as above), call `Context::register_user_texture(&mut tex)` once
//! to register it, otherwise renderer backends may not receive texture requests for it.
//!
//! 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:
//! 1. Create `TextureData` and call `create(format, w, h)` to allocate pixels.
//! 2. Fill/modify pixels; call `set_status(WantCreate)` for initial upload, or `WantUpdates` with
//! `UpdateRect` for sub-updates. `TextureData::set_data()` is a convenience which copies data and
//! marks an update.
//! 3. Register user-created textures once via `Context::register_user_texture(&mut tex)`.
//! 4. Use the texture in UI via `ui.image(&mut tex, size)` or drawlist APIs.
//! 5. In your renderer, during `render()`, iterate `DrawData::textures()` and honor the requests
//! (Create/Update/Destroy), then set status back to `OK`/`Destroyed`.
//! - Alternatives: when you already have a GPU handle, pass `TextureId` directly.
//!
//! ## Renderer Integration (Modern Textures)
//!
//! When integrating a renderer backend (WGPU, OpenGL, etc.) with ImGui 1.92+:
//! - Set `BackendFlags::RENDERER_HAS_TEXTURES` on the ImGui `Io` before 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 to `OK`.
//! - `WantUpdates`: upload pending `UpdateRect`s, then set status to `OK`.
//! - `WantDestroy`: delete/free the GPU texture and set status to `Destroyed`.
//! - When binding textures for draw commands, do not rely only on `DrawCmdParams.texture_id`.
//! With the modern system it may be `0`. Resolve the effective id at bind time using
//! `ImDrawCmd_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 `ImTextureData` path.
//!
//! Pseudocode outline:
//! ```ignore
//! // 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()`:
//!
//! ```no_run
//! # use dear_imgui_rs::*;
//! # fn demo(ui: &Ui) {
//! // 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)` and
//! `ui.input_text_multiline(label, &mut String, size)`.
//! - Internally stage a growable UTF�? buffer for the call and copy the
//! edited bytes back into your `String` afterwards.
//! - For very large fields, use `.capacity_hint(bytes)` on the builder to
//! reduce reallocations, e.g.:
//! ```no_run
//! # use dear_imgui_rs::*;
//! # fn demo(ui: &Ui, big: &mut String) {
//! ui.input_text("Big", big)
//! .capacity_hint(64 * 1024)
//! .build();
//! # }
//! ```
//! - ImString-backed builders: `ui.input_text_imstr(label, &mut ImString)` and
//! `ui.input_text_multiline_imstr(label, &mut ImString, size)`.
//! - Zero‑copy: pass your `ImString` buffer directly to ImGui.
//! - Uses ImGui's `CallbackResize` under the hood to grow the same buffer the
//! widget edits �?no copy before/after the call.
//!
//! 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. Call `channels.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 an `FnOnce()`
//! 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_callback` allows passing a C callback and raw userdata; see
//! method docs for safety requirements.
// Re-export the sys crate for advanced users
pub extern crate dear_imgui_sys as sys;
/// Strongly-typed wrapper around ImGuiID.
///
/// This avoids leaking the `sys` type in safe APIs and improves clarity
/// when passing/returning identifiers (e.g., dock ids, viewport ids).
ImGuiID);
// Note: do not add From<u32> or From<Id> for u32 here to avoid
// overlapping/conflicting impls on platforms where ImGuiID == u32.
/// Condition for setting window/widget properties
// use std::cell;
// use std::os::raw::c_char;
// Core modules
pub use ;
pub use *;
// Note: draw types are now in render module
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Re-export utility flags/types for convenience
pub use ;
// Utility modules
pub use *;
// pub use self::math::*;
// Widget modules
pub use *;
pub use *;
// Stack management
pub use *;
// Layout and cursor control
pub use *;
// Drag and drop system
pub use *;
// Text filtering system
pub use *;
// Column layout system (included in layout module)
pub use *;
// Internal modules
// mod math;
// Token system for resource management
// Stack management
// Layout and cursor control
// Drag and drop system
// Text filtering system
// Column layout system
// Logging utilities
// Re-export public API
pub use *;
pub use *;
pub use *;
// Export draw-list helpers for extensions and downstream custom drawing.
pub use ;
pub use *;
// Note: draw types are now in render module, no need to export draw::*
pub use *;
pub use *;
// Version information
pub const VERSION: &str = env!;
/// Check if docking features are available
pub const HAS_DOCKING: bool = HAS_DOCKING;
/// Check if FreeType font rasterizer support is compiled in
pub const HAS_FREETYPE: bool = HAS_FREETYPE;
/// Check if WASM support is compiled in (sys layer)
pub const HAS_WASM: bool = HAS_WASM;
/// Returns the underlying Dear ImGui library version