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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
//! Per-frame UI entry point
//!
//! The `Ui` type exposes most user-facing Dear ImGui APIs for a single frame:
//! creating windows, drawing widgets, accessing draw lists, showing built-in
//! tools and more. Obtain it from [`Context::frame`].
//!
//! Example:
//! ```no_run
//! # use dear_imgui_rs::*;
//! let mut ctx = Context::create();
//! let ui = ctx.frame();
//! ui.text("Hello, world!");
//! ```
//!
use crate::Id;
use crate::draw::DrawListMut;
use crate::input::MouseCursor;
use crate::internal::RawWrapper;
use crate::string::UiBuffer;
use crate::sys;
use crate::texture::TextureRef;
use std::cell::UnsafeCell;
/// Represents the Dear ImGui user interface for one frame
#[derive(Debug)]
pub struct Ui {
/// Internal buffer for string operations
buffer: UnsafeCell<UiBuffer>,
}
impl Ui {
/// Returns a reference to the main Dear ImGui viewport (safe wrapper)
///
/// Same viewport used by `dockspace_over_main_viewport()`.
///
/// The returned reference is owned by the currently active ImGui context and
/// must not be used after the context is destroyed.
#[doc(alias = "GetMainViewport")]
pub fn main_viewport(&self) -> &crate::platform_io::Viewport {
unsafe {
let ptr = sys::igGetMainViewport();
if ptr.is_null() {
panic!("Ui::main_viewport() requires an active ImGui context");
}
crate::platform_io::Viewport::from_raw(ptr as *const sys::ImGuiViewport)
}
}
/// Creates a new Ui instance
///
/// This should only be called by Context::create()
pub(crate) fn new() -> Self {
Ui {
buffer: UnsafeCell::new(UiBuffer::new(1024)),
}
}
/// Returns an immutable reference to the inputs/outputs object
#[doc(alias = "GetIO")]
pub fn io(&self) -> &crate::io::Io {
unsafe {
let io = sys::igGetIO_Nil();
if io.is_null() {
panic!("Ui::io() requires an active ImGui context");
}
&*(io as *const crate::io::Io)
}
}
/// Internal method to push a single text to our scratch buffer.
pub(crate) fn scratch_txt(&self, txt: impl AsRef<str>) -> *const std::os::raw::c_char {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt(txt)
}
}
/// Helper method for two strings
pub(crate) fn scratch_txt_two(
&self,
txt_0: impl AsRef<str>,
txt_1: impl AsRef<str>,
) -> (*const std::os::raw::c_char, *const std::os::raw::c_char) {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt_two(txt_0, txt_1)
}
}
/// Helper method with one optional value
pub(crate) fn scratch_txt_with_opt(
&self,
txt_0: impl AsRef<str>,
txt_1: Option<impl AsRef<str>>,
) -> (*const std::os::raw::c_char, *const std::os::raw::c_char) {
unsafe {
let handle = &mut *self.buffer.get();
handle.scratch_txt_with_opt(txt_0, txt_1)
}
}
/// Get access to the scratch buffer for complex string operations
pub(crate) fn scratch_buffer(&self) -> &UnsafeCell<UiBuffer> {
&self.buffer
}
/// Display text
#[doc(alias = "TextUnformatted")]
pub fn text<T: AsRef<str>>(&self, text: T) {
let s = text.as_ref();
unsafe {
let start = s.as_ptr();
let end = start.add(s.len());
crate::sys::igTextUnformatted(
start as *const std::os::raw::c_char,
end as *const std::os::raw::c_char,
);
}
}
/// Set the viewport for the next window.
///
/// This is a convenience wrapper over `ImGui::SetNextWindowViewport`.
/// Useful when hosting a fullscreen DockSpace window inside the main viewport.
#[doc(alias = "SetNextWindowViewport")]
pub fn set_next_window_viewport(&self, viewport_id: Id) {
unsafe { sys::igSetNextWindowViewport(viewport_id.into()) }
}
/// Returns the viewport of the current window.
///
/// This requires a current window (i.e. must be called between `Begin`/`End`).
#[doc(alias = "GetWindowViewport")]
pub fn window_viewport(&self) -> &crate::platform_io::Viewport {
unsafe {
let ptr = sys::igGetWindowViewport();
if ptr.is_null() {
panic!("Ui::window_viewport() requires a current window");
}
crate::platform_io::Viewport::from_raw(ptr as *const sys::ImGuiViewport)
}
}
/// Find a viewport by ID.
#[doc(alias = "FindViewportByID")]
pub fn find_viewport_by_id(&self, viewport_id: Id) -> Option<&crate::platform_io::Viewport> {
unsafe {
let ptr = sys::igFindViewportByID(viewport_id.raw());
if ptr.is_null() {
None
} else {
Some(crate::platform_io::Viewport::from_raw(
ptr as *const sys::ImGuiViewport,
))
}
}
}
/// Find a viewport by its platform handle.
///
/// The platform handle type depends on the backend (e.g. `HWND` on Windows).
#[doc(alias = "FindViewportByPlatformHandle")]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn find_viewport_by_platform_handle(
&self,
platform_handle: *mut std::ffi::c_void,
) -> Option<&crate::platform_io::Viewport> {
unsafe {
let ptr = sys::igFindViewportByPlatformHandle(platform_handle);
if ptr.is_null() {
None
} else {
Some(crate::platform_io::Viewport::from_raw(
ptr as *const sys::ImGuiViewport,
))
}
}
}
/// Returns an ID from a string label in the current ID scope.
///
/// This mirrors `ImGui::GetID(label)`. Useful for building stable IDs
/// for widgets or dockspaces inside the current window/scope.
#[doc(alias = "GetID")]
pub fn get_id(&self, label: &str) -> Id {
unsafe { Id::from(sys::igGetID_Str(self.scratch_txt(label))) }
}
/// Access to the current window's draw list
#[doc(alias = "GetWindowDrawList")]
pub fn get_window_draw_list(&self) -> DrawListMut<'_> {
DrawListMut::window(self)
}
/// Access to the background draw list
#[doc(alias = "GetBackgroundDrawList")]
pub fn get_background_draw_list(&self) -> DrawListMut<'_> {
DrawListMut::background(self)
}
/// Access to the foreground draw list
#[doc(alias = "GetForegroundDrawList")]
pub fn get_foreground_draw_list(&self) -> DrawListMut<'_> {
DrawListMut::foreground(self)
}
/// Creates a window builder
pub fn window<'ui>(
&'ui self,
name: impl Into<std::borrow::Cow<'ui, str>>,
) -> crate::window::Window<'ui> {
crate::window::Window::new(self, name)
}
/// Renders a demo window (previously called a test window), which demonstrates most
/// Dear ImGui features.
#[doc(alias = "ShowDemoWindow")]
pub fn show_demo_window(&self, opened: &mut bool) {
unsafe {
crate::sys::igShowDemoWindow(opened);
}
}
/// Convenience: draw an image with background and tint (ImGui 1.92+)
///
/// Equivalent to using `image_config(...).build_with_bg(bg, tint)` but in one call.
#[doc(alias = "ImageWithBg")]
pub fn image_with_bg(
&self,
texture: impl Into<TextureRef>,
size: [f32; 2],
bg_color: [f32; 4],
tint_color: [f32; 4],
) {
crate::widget::image::Image::new(self, texture, size).build_with_bg(bg_color, tint_color)
}
/// Renders an about window.
///
/// Displays the Dear ImGui version/credits, and build/system information.
#[doc(alias = "ShowAboutWindow")]
pub fn show_about_window(&self, opened: &mut bool) {
unsafe {
crate::sys::igShowAboutWindow(opened);
}
}
/// Renders a metrics/debug window.
///
/// Displays Dear ImGui internals: draw commands (with individual draw calls and vertices),
/// window list, basic internal state, etc.
#[doc(alias = "ShowMetricsWindow")]
pub fn show_metrics_window(&self, opened: &mut bool) {
unsafe {
crate::sys::igShowMetricsWindow(opened);
}
}
/// Renders a style editor block (not a window) for the given `Style` structure
#[doc(alias = "ShowStyleEditor")]
pub fn show_style_editor(&self, style: &mut crate::style::Style) {
unsafe {
crate::sys::igShowStyleEditor(style.raw_mut());
}
}
/// Renders a style editor block (not a window) for the currently active style
#[doc(alias = "ShowStyleEditor")]
pub fn show_default_style_editor(&self) {
unsafe {
crate::sys::igShowStyleEditor(std::ptr::null_mut());
}
}
/// Renders a basic help/info block (not a window)
#[doc(alias = "ShowUserGuide")]
pub fn show_user_guide(&self) {
unsafe {
crate::sys::igShowUserGuide();
}
}
// Drag widgets
/// Creates a drag float slider
#[doc(alias = "DragFloat")]
pub fn drag_float(&self, label: impl AsRef<str>, value: &mut f32) -> bool {
crate::widget::drag::Drag::new(label).build(self, value)
}
/// Creates a drag float slider with configuration
#[doc(alias = "DragFloat")]
pub fn drag_float_config<L: AsRef<str>>(&self, label: L) -> crate::widget::drag::Drag<f32, L> {
crate::widget::drag::Drag::new(label)
}
/// Creates a drag int slider
#[doc(alias = "DragInt")]
pub fn drag_int(&self, label: impl AsRef<str>, value: &mut i32) -> bool {
crate::widget::drag::Drag::new(label).build(self, value)
}
/// Creates a drag int slider with configuration
#[doc(alias = "DragInt")]
pub fn drag_int_config<L: AsRef<str>>(&self, label: L) -> crate::widget::drag::Drag<i32, L> {
crate::widget::drag::Drag::new(label)
}
/// Creates a drag float range slider
#[doc(alias = "DragFloatRange2")]
pub fn drag_float_range2(&self, label: impl AsRef<str>, min: &mut f32, max: &mut f32) -> bool {
crate::widget::drag::DragRange::<f32, _>::new(label).build(self, min, max)
}
/// Creates a drag float range slider with configuration
#[doc(alias = "DragFloatRange2")]
pub fn drag_float_range2_config<L: AsRef<str>>(
&self,
label: L,
) -> crate::widget::drag::DragRange<f32, L> {
crate::widget::drag::DragRange::new(label)
}
/// Creates a drag int range slider
#[doc(alias = "DragIntRange2")]
pub fn drag_int_range2(&self, label: impl AsRef<str>, min: &mut i32, max: &mut i32) -> bool {
crate::widget::drag::DragRange::<i32, _>::new(label).build(self, min, max)
}
/// Creates a drag int range slider with configuration
#[doc(alias = "DragIntRange2")]
pub fn drag_int_range2_config<L: AsRef<str>>(
&self,
label: L,
) -> crate::widget::drag::DragRange<i32, L> {
crate::widget::drag::DragRange::new(label)
}
/// Returns the currently desired mouse cursor type
///
/// Returns `None` if no cursor should be displayed
#[doc(alias = "GetMouseCursor")]
pub fn mouse_cursor(&self) -> Option<MouseCursor> {
unsafe {
match sys::igGetMouseCursor() {
sys::ImGuiMouseCursor_Arrow => Some(MouseCursor::Arrow),
sys::ImGuiMouseCursor_TextInput => Some(MouseCursor::TextInput),
sys::ImGuiMouseCursor_ResizeAll => Some(MouseCursor::ResizeAll),
sys::ImGuiMouseCursor_ResizeNS => Some(MouseCursor::ResizeNS),
sys::ImGuiMouseCursor_ResizeEW => Some(MouseCursor::ResizeEW),
sys::ImGuiMouseCursor_ResizeNESW => Some(MouseCursor::ResizeNESW),
sys::ImGuiMouseCursor_ResizeNWSE => Some(MouseCursor::ResizeNWSE),
sys::ImGuiMouseCursor_Hand => Some(MouseCursor::Hand),
sys::ImGuiMouseCursor_NotAllowed => Some(MouseCursor::NotAllowed),
_ => None,
}
}
}
/// Sets the desired mouse cursor type
///
/// Passing `None` hides the mouse cursor
#[doc(alias = "SetMouseCursor")]
pub fn set_mouse_cursor(&self, cursor_type: Option<MouseCursor>) {
unsafe {
let val: sys::ImGuiMouseCursor = cursor_type
.map(|x| x as sys::ImGuiMouseCursor)
.unwrap_or(sys::ImGuiMouseCursor_None);
sys::igSetMouseCursor(val);
}
}
// ============================================================================
// Focus and Navigation
// ============================================================================
/// Focuses keyboard on the next widget.
///
/// This is the equivalent to [set_keyboard_focus_here_with_offset](Self::set_keyboard_focus_here_with_offset)
/// with `offset` set to 0.
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here(&self) {
self.set_keyboard_focus_here_with_offset(0);
}
/// Focuses keyboard on a widget relative to current position.
///
/// Use positive offset to focus on next widgets, negative offset to focus on previous widgets.
#[doc(alias = "SetKeyboardFocusHere")]
pub fn set_keyboard_focus_here_with_offset(&self, offset: i32) {
unsafe {
sys::igSetKeyboardFocusHere(offset);
}
}
/// Shows or hides the navigation cursor (a small marker indicating nav focus).
#[doc(alias = "SetNavCursorVisible")]
pub fn set_nav_cursor_visible(&self, visible: bool) {
unsafe { sys::igSetNavCursorVisible(visible) }
}
/// Focus a window by name, or clear focus from all windows.
///
/// Passing `None` is equivalent to `ImGui::SetWindowFocus(NULL)` in the C++ API.
/// This can be used to "unfocus" the entire UI (e.g. on Escape, to behave like
/// clicking outside of the UI).
#[doc(alias = "SetWindowFocus")]
pub fn set_window_focus(&self, name: Option<&str>) {
unsafe {
match name {
Some(name) => sys::igSetWindowFocus_Str(self.scratch_txt(name)),
None => sys::igSetWindowFocus_Nil(),
}
}
}
/// Sets the position of the current window.
#[doc(alias = "SetWindowPos")]
pub fn set_window_pos(&self, pos: [f32; 2]) {
self.set_window_pos_with_cond(pos, crate::Condition::Always);
}
/// Sets the position of the current window with a condition.
#[doc(alias = "SetWindowPos")]
pub fn set_window_pos_with_cond(&self, pos: [f32; 2], cond: crate::Condition) {
let pos_vec = sys::ImVec2_c {
x: pos[0],
y: pos[1],
};
unsafe { sys::igSetWindowPos_Vec2(pos_vec, cond as sys::ImGuiCond) }
}
/// Sets the position of a named window.
#[doc(alias = "SetWindowPos")]
pub fn set_window_pos_by_name(&self, name: impl AsRef<str>, pos: [f32; 2]) {
self.set_window_pos_by_name_with_cond(name, pos, crate::Condition::Always);
}
/// Sets the position of a named window with a condition.
#[doc(alias = "SetWindowPos")]
pub fn set_window_pos_by_name_with_cond(
&self,
name: impl AsRef<str>,
pos: [f32; 2],
cond: crate::Condition,
) {
let pos_vec = sys::ImVec2_c {
x: pos[0],
y: pos[1],
};
unsafe { sys::igSetWindowPos_Str(self.scratch_txt(name), pos_vec, cond as sys::ImGuiCond) }
}
/// Sets the size of the current window.
#[doc(alias = "SetWindowSize")]
pub fn set_window_size(&self, size: [f32; 2]) {
self.set_window_size_with_cond(size, crate::Condition::Always);
}
/// Sets the size of the current window with a condition.
#[doc(alias = "SetWindowSize")]
pub fn set_window_size_with_cond(&self, size: [f32; 2], cond: crate::Condition) {
let size_vec = sys::ImVec2_c {
x: size[0],
y: size[1],
};
unsafe { sys::igSetWindowSize_Vec2(size_vec, cond as sys::ImGuiCond) }
}
/// Sets the size of a named window.
#[doc(alias = "SetWindowSize")]
pub fn set_window_size_by_name(&self, name: impl AsRef<str>, size: [f32; 2]) {
self.set_window_size_by_name_with_cond(name, size, crate::Condition::Always);
}
/// Sets the size of a named window with a condition.
#[doc(alias = "SetWindowSize")]
pub fn set_window_size_by_name_with_cond(
&self,
name: impl AsRef<str>,
size: [f32; 2],
cond: crate::Condition,
) {
let size_vec = sys::ImVec2_c {
x: size[0],
y: size[1],
};
unsafe {
sys::igSetWindowSize_Str(self.scratch_txt(name), size_vec, cond as sys::ImGuiCond);
}
}
/// Collapses or expands the current window.
#[doc(alias = "SetWindowCollapsed")]
pub fn set_window_collapsed(&self, collapsed: bool) {
self.set_window_collapsed_with_cond(collapsed, crate::Condition::Always);
}
/// Collapses or expands the current window with a condition.
#[doc(alias = "SetWindowCollapsed")]
pub fn set_window_collapsed_with_cond(&self, collapsed: bool, cond: crate::Condition) {
unsafe { sys::igSetWindowCollapsed_Bool(collapsed, cond as sys::ImGuiCond) }
}
/// Collapses or expands a named window.
#[doc(alias = "SetWindowCollapsed")]
pub fn set_window_collapsed_by_name(&self, name: impl AsRef<str>, collapsed: bool) {
self.set_window_collapsed_by_name_with_cond(name, collapsed, crate::Condition::Always);
}
/// Collapses or expands a named window with a condition.
#[doc(alias = "SetWindowCollapsed")]
pub fn set_window_collapsed_by_name_with_cond(
&self,
name: impl AsRef<str>,
collapsed: bool,
cond: crate::Condition,
) {
unsafe {
sys::igSetWindowCollapsed_Str(
self.scratch_txt(name),
collapsed,
cond as sys::ImGuiCond,
);
}
}
/// Set next item to be open by default.
///
/// This is useful for tree nodes, collapsing headers, etc.
#[doc(alias = "SetNextItemOpen")]
pub fn set_next_item_open(&self, is_open: bool) {
unsafe {
sys::igSetNextItemOpen(is_open, 0); // 0 = ImGuiCond_Always
}
}
/// Set next item to be open by default with condition.
#[doc(alias = "SetNextItemOpen")]
pub fn set_next_item_open_with_cond(&self, is_open: bool, cond: crate::Condition) {
unsafe { sys::igSetNextItemOpen(is_open, cond as sys::ImGuiCond) }
}
/// Set next item width.
///
/// Set to 0.0 for default width, >0.0 for explicit width, <0.0 for relative width.
#[doc(alias = "SetNextItemWidth")]
pub fn set_next_item_width(&self, item_width: f32) {
unsafe {
sys::igSetNextItemWidth(item_width);
}
}
// ============================================================================
// Style Access
// ============================================================================
/// Returns a shared reference to the current [`Style`].
///
/// ## Safety
///
/// This function is tagged as `unsafe` because pushing via
/// [`push_style_color`](crate::Ui::push_style_color) or
/// [`push_style_var`](crate::Ui::push_style_var) or popping via
/// [`ColorStackToken::pop`](crate::ColorStackToken::pop) or
/// [`StyleStackToken::pop`](crate::StyleStackToken::pop) will modify the values in the returned
/// shared reference. Therefore, you should not retain this reference across calls to push and
/// pop. The [`clone_style`](Ui::clone_style) version may instead be used to avoid `unsafe`.
#[doc(alias = "GetStyle")]
pub unsafe fn style(&self) -> &crate::Style {
unsafe {
// safe because Style is a transparent wrapper around sys::ImGuiStyle
&*(sys::igGetStyle() as *const crate::Style)
}
}
/// Returns a copy of the current style.
///
/// This is a safe alternative to [`style`](Self::style) that avoids the lifetime issues.
#[doc(alias = "GetStyle")]
pub fn clone_style(&self) -> crate::Style {
unsafe { self.style().clone() }
}
/// Apply the built-in Dark style to the current style.
#[doc(alias = "StyleColorsDark")]
pub fn style_colors_dark(&self) {
unsafe { sys::igStyleColorsDark(std::ptr::null_mut()) }
}
/// Apply the built-in Light style to the current style.
#[doc(alias = "StyleColorsLight")]
pub fn style_colors_light(&self) {
unsafe { sys::igStyleColorsLight(std::ptr::null_mut()) }
}
/// Apply the built-in Classic style to the current style.
#[doc(alias = "StyleColorsClassic")]
pub fn style_colors_classic(&self) {
unsafe { sys::igStyleColorsClassic(std::ptr::null_mut()) }
}
/// Write the Dark style values into the provided [`Style`] object.
#[doc(alias = "StyleColorsDark")]
pub fn style_colors_dark_into(&self, dst: &mut crate::Style) {
unsafe { sys::igStyleColorsDark(dst.raw_mut() as *mut sys::ImGuiStyle) }
}
/// Write the Light style values into the provided [`Style`] object.
#[doc(alias = "StyleColorsLight")]
pub fn style_colors_light_into(&self, dst: &mut crate::Style) {
unsafe { sys::igStyleColorsLight(dst.raw_mut() as *mut sys::ImGuiStyle) }
}
/// Write the Classic style values into the provided [`Style`] object.
#[doc(alias = "StyleColorsClassic")]
pub fn style_colors_classic_into(&self, dst: &mut crate::Style) {
unsafe { sys::igStyleColorsClassic(dst.raw_mut() as *mut sys::ImGuiStyle) }
}
/// Returns DPI scale currently associated to the current window's viewport.
#[doc(alias = "GetWindowDpiScale")]
pub fn window_dpi_scale(&self) -> f32 {
unsafe { sys::igGetWindowDpiScale() }
}
/// Display a text label with a boolean value (for quick debug UIs).
#[doc(alias = "Value")]
pub fn value_bool(&self, prefix: impl AsRef<str>, v: bool) {
unsafe { sys::igValue_Bool(self.scratch_txt(prefix), v) }
}
/// Get current window width (shortcut for `GetWindowSize().x`).
#[doc(alias = "GetWindowWidth")]
pub fn window_width(&self) -> f32 {
unsafe { sys::igGetWindowWidth() }
}
/// Get current window height (shortcut for `GetWindowSize().y`).
#[doc(alias = "GetWindowHeight")]
pub fn window_height(&self) -> f32 {
unsafe { sys::igGetWindowHeight() }
}
/// Get current window position in screen space.
#[doc(alias = "GetWindowPos")]
pub fn window_pos(&self) -> [f32; 2] {
let v = unsafe { sys::igGetWindowPos() };
[v.x, v.y]
}
/// Get current window size.
#[doc(alias = "GetWindowSize")]
pub fn window_size(&self) -> [f32; 2] {
let v = unsafe { sys::igGetWindowSize() };
[v.x, v.y]
}
// ============================================================================
// Additional Demo, Debug, Information (non-duplicate methods)
// ============================================================================
/// Renders a debug log window.
///
/// Displays a simplified log of important dear imgui events.
#[doc(alias = "ShowDebugLogWindow")]
pub fn show_debug_log_window(&self, opened: &mut bool) {
unsafe {
sys::igShowDebugLogWindow(opened);
}
}
/// Renders an ID stack tool window.
///
/// Hover items with mouse to query information about the source of their unique ID.
#[doc(alias = "ShowIDStackToolWindow")]
pub fn show_id_stack_tool_window(&self, opened: &mut bool) {
unsafe {
sys::igShowIDStackToolWindow(opened);
}
}
/// Renders a style selector combo box.
///
/// Returns true when a different style was selected.
#[doc(alias = "ShowStyleSelector")]
pub fn show_style_selector(&self, label: impl AsRef<str>) -> bool {
unsafe { sys::igShowStyleSelector(self.scratch_txt(label)) }
}
/// Renders a font selector combo box.
#[doc(alias = "ShowFontSelector")]
pub fn show_font_selector(&self, label: impl AsRef<str>) {
unsafe {
sys::igShowFontSelector(self.scratch_txt(label));
}
}
/// Returns the Dear ImGui version string
#[doc(alias = "GetVersion")]
pub fn get_version(&self) -> &str {
unsafe {
let version_ptr = sys::igGetVersion();
if version_ptr.is_null() {
return "Unknown";
}
let c_str = std::ffi::CStr::from_ptr(version_ptr);
c_str.to_str().unwrap_or("Unknown")
}
}
}