dear-imgui-rs 0.12.0

High-level Rust bindings to Dear ImGui v1.92.7 with docking, WGPU/GL backends, and extensions (ImPlot/ImPlot3D, ImNodes, ImGuizmo, file browser, reflection-based UI)
Documentation
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
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
//! Styling and colors
//!
//! High-level access to Dear ImGui style parameters and color table. Use this
//! module to read or tweak padding, rounding, sizes and retrieve or modify
//! named colors via [`StyleColor`].
//!
//! Example:
//! ```no_run
//! # use dear_imgui_rs::*;
//! # let mut ctx = Context::create();
//! // Adjust style before building a frame
//! {
//!     let style = ctx.style_mut();
//!     style.set_window_rounding(6.0);
//!     style.set_color(StyleColor::WindowBg, [0.10, 0.10, 0.12, 1.0]);
//! }
//! // Optionally show the style editor for the current style
//! # let ui = ctx.frame();
//! ui.show_default_style_editor();
//! ```
//!
//! Quick example (temporary style color):
//! ```no_run
//! # use dear_imgui_rs::*;
//! # let mut ctx = Context::create();
//! # let ui = ctx.frame();
//! let c = ui.push_style_color(StyleColor::Text, [0.2, 1.0, 0.2, 1.0]);
//! ui.text("green text");
//! c.pop();
//! ```
//!
#![allow(
    clippy::cast_possible_truncation,
    clippy::cast_sign_loss,
    clippy::as_conversions
)]
use crate::Context;
use crate::internal::RawWrapper;
use crate::sys;
use crate::utils::HoveredFlags;
use crate::widget::TreeNodeFlags;
use crate::widget::{TableFlags, TableRowFlags};
use crate::window::WindowFlags;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::cell::UnsafeCell;

/// User interface style/colors
///
/// Note: This is a transparent wrapper over `sys::ImGuiStyle` (v1.92+ layout).
/// Do not assume field layout here; use accessors or `raw()/raw_mut()` if needed.
#[repr(transparent)]
#[derive(Debug)]
pub struct Style(pub(crate) UnsafeCell<sys::ImGuiStyle>);

// Ensure the wrapper stays layout-compatible with the sys bindings.
const _: [(); std::mem::size_of::<sys::ImGuiStyle>()] = [(); std::mem::size_of::<Style>()];
const _: [(); std::mem::align_of::<sys::ImGuiStyle>()] = [(); std::mem::align_of::<Style>()];

impl Style {
    #[inline]
    fn inner(&self) -> &sys::ImGuiStyle {
        // Safety: `Style` is a view into ImGui-owned style data. Dear ImGui can update style state
        // (e.g. via push/pop stacks or user code) while Rust holds `&Style`, so we store it behind
        // `UnsafeCell` to make that interior mutability explicit.
        unsafe { &*self.0.get() }
    }

    #[inline]
    fn inner_mut(&mut self) -> &mut sys::ImGuiStyle {
        // Safety: caller has `&mut Style`, so this is a unique Rust borrow for this wrapper.
        unsafe { &mut *self.0.get() }
    }

    /// Get a color by style color identifier
    pub fn color(&self, color: StyleColor) -> [f32; 4] {
        let c = self.inner().Colors[color as usize];
        [c.x, c.y, c.z, c.w]
    }

    /// Set a color by style color identifier
    pub fn set_color(&mut self, color: StyleColor, value: [f32; 4]) {
        self.inner_mut().Colors[color as usize] = sys::ImVec4 {
            x: value[0],
            y: value[1],
            z: value[2],
            w: value[3],
        };
    }

    /// Get main font scale (formerly io.FontGlobalScale)
    pub fn font_scale_main(&self) -> f32 {
        self.inner().FontScaleMain
    }

    /// Set main font scale (formerly io.FontGlobalScale)
    pub fn set_font_scale_main(&mut self, scale: f32) {
        self.inner_mut().FontScaleMain = scale;
    }

    /// Get DPI font scale (auto-overwritten if ConfigDpiScaleFonts=true)
    pub fn font_scale_dpi(&self) -> f32 {
        self.inner().FontScaleDpi
    }

    /// Set DPI font scale
    pub fn set_font_scale_dpi(&mut self, scale: f32) {
        self.inner_mut().FontScaleDpi = scale;
    }

    /// Base size used by style for font sizing
    pub fn font_size_base(&self) -> f32 {
        self.inner().FontSizeBase
    }

    pub fn set_font_size_base(&mut self, sz: f32) {
        self.inner_mut().FontSizeBase = sz;
    }

    // Common style accessors (typed, convenient)

    pub fn alpha(&self) -> f32 {
        self.inner().Alpha
    }
    pub fn set_alpha(&mut self, v: f32) {
        self.inner_mut().Alpha = v;
    }

    pub fn disabled_alpha(&self) -> f32 {
        self.inner().DisabledAlpha
    }
    pub fn set_disabled_alpha(&mut self, v: f32) {
        self.inner_mut().DisabledAlpha = v;
    }

    pub fn window_padding(&self) -> [f32; 2] {
        [self.inner().WindowPadding.x, self.inner().WindowPadding.y]
    }
    pub fn set_window_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().WindowPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn window_rounding(&self) -> f32 {
        self.inner().WindowRounding
    }
    pub fn set_window_rounding(&mut self, v: f32) {
        self.inner_mut().WindowRounding = v;
    }

    pub fn window_border_size(&self) -> f32 {
        self.inner().WindowBorderSize
    }
    pub fn set_window_border_size(&mut self, v: f32) {
        self.inner_mut().WindowBorderSize = v;
    }

    pub fn window_min_size(&self) -> [f32; 2] {
        [self.inner().WindowMinSize.x, self.inner().WindowMinSize.y]
    }
    pub fn set_window_min_size(&mut self, v: [f32; 2]) {
        self.inner_mut().WindowMinSize = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn window_title_align(&self) -> [f32; 2] {
        [
            self.inner().WindowTitleAlign.x,
            self.inner().WindowTitleAlign.y,
        ]
    }
    pub fn set_window_title_align(&mut self, v: [f32; 2]) {
        self.inner_mut().WindowTitleAlign = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn window_menu_button_position(&self) -> Direction {
        Direction::from(self.inner().WindowMenuButtonPosition)
    }
    pub fn set_window_menu_button_position(&mut self, d: Direction) {
        self.inner_mut().WindowMenuButtonPosition = d.into();
    }

    pub fn child_rounding(&self) -> f32 {
        self.inner().ChildRounding
    }
    pub fn set_child_rounding(&mut self, v: f32) {
        self.inner_mut().ChildRounding = v;
    }

    pub fn child_border_size(&self) -> f32 {
        self.inner().ChildBorderSize
    }
    pub fn set_child_border_size(&mut self, v: f32) {
        self.inner_mut().ChildBorderSize = v;
    }

    pub fn popup_rounding(&self) -> f32 {
        self.inner().PopupRounding
    }
    pub fn set_popup_rounding(&mut self, v: f32) {
        self.inner_mut().PopupRounding = v;
    }

    pub fn popup_border_size(&self) -> f32 {
        self.inner().PopupBorderSize
    }
    pub fn set_popup_border_size(&mut self, v: f32) {
        self.inner_mut().PopupBorderSize = v;
    }

    pub fn frame_padding(&self) -> [f32; 2] {
        [self.inner().FramePadding.x, self.inner().FramePadding.y]
    }
    pub fn set_frame_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().FramePadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn frame_rounding(&self) -> f32 {
        self.inner().FrameRounding
    }
    pub fn set_frame_rounding(&mut self, v: f32) {
        self.inner_mut().FrameRounding = v;
    }

    pub fn image_rounding(&self) -> f32 {
        self.inner().ImageRounding
    }
    pub fn set_image_rounding(&mut self, v: f32) {
        self.inner_mut().ImageRounding = v;
    }

    pub fn frame_border_size(&self) -> f32 {
        self.inner().FrameBorderSize
    }
    pub fn set_frame_border_size(&mut self, v: f32) {
        self.inner_mut().FrameBorderSize = v;
    }

    pub fn item_spacing(&self) -> [f32; 2] {
        [self.inner().ItemSpacing.x, self.inner().ItemSpacing.y]
    }
    pub fn set_item_spacing(&mut self, v: [f32; 2]) {
        self.inner_mut().ItemSpacing = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn item_inner_spacing(&self) -> [f32; 2] {
        [
            self.inner().ItemInnerSpacing.x,
            self.inner().ItemInnerSpacing.y,
        ]
    }
    pub fn set_item_inner_spacing(&mut self, v: [f32; 2]) {
        self.inner_mut().ItemInnerSpacing = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn cell_padding(&self) -> [f32; 2] {
        [self.inner().CellPadding.x, self.inner().CellPadding.y]
    }
    pub fn set_cell_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().CellPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn touch_extra_padding(&self) -> [f32; 2] {
        [
            self.inner().TouchExtraPadding.x,
            self.inner().TouchExtraPadding.y,
        ]
    }
    pub fn set_touch_extra_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().TouchExtraPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn indent_spacing(&self) -> f32 {
        self.inner().IndentSpacing
    }
    pub fn set_indent_spacing(&mut self, v: f32) {
        self.inner_mut().IndentSpacing = v;
    }

    pub fn columns_min_spacing(&self) -> f32 {
        self.inner().ColumnsMinSpacing
    }
    pub fn set_columns_min_spacing(&mut self, v: f32) {
        self.inner_mut().ColumnsMinSpacing = v;
    }

    pub fn scrollbar_size(&self) -> f32 {
        self.inner().ScrollbarSize
    }
    pub fn set_scrollbar_size(&mut self, v: f32) {
        self.inner_mut().ScrollbarSize = v;
    }

    pub fn scrollbar_rounding(&self) -> f32 {
        self.inner().ScrollbarRounding
    }
    pub fn set_scrollbar_rounding(&mut self, v: f32) {
        self.inner_mut().ScrollbarRounding = v;
    }

    pub fn grab_min_size(&self) -> f32 {
        self.inner().GrabMinSize
    }
    pub fn set_grab_min_size(&mut self, v: f32) {
        self.inner_mut().GrabMinSize = v;
    }

    pub fn grab_rounding(&self) -> f32 {
        self.inner().GrabRounding
    }
    pub fn set_grab_rounding(&mut self, v: f32) {
        self.inner_mut().GrabRounding = v;
    }

    pub fn log_slider_deadzone(&self) -> f32 {
        self.inner().LogSliderDeadzone
    }
    pub fn set_log_slider_deadzone(&mut self, v: f32) {
        self.inner_mut().LogSliderDeadzone = v;
    }

    pub fn tab_rounding(&self) -> f32 {
        self.inner().TabRounding
    }
    pub fn set_tab_rounding(&mut self, v: f32) {
        self.inner_mut().TabRounding = v;
    }

    pub fn tab_border_size(&self) -> f32 {
        self.inner().TabBorderSize
    }
    pub fn set_tab_border_size(&mut self, v: f32) {
        self.inner_mut().TabBorderSize = v;
    }

    pub fn color_button_position(&self) -> Direction {
        Direction::from(self.inner().ColorButtonPosition)
    }
    pub fn set_color_button_position(&mut self, d: Direction) {
        self.inner_mut().ColorButtonPosition = d.into();
    }

    pub fn button_text_align(&self) -> [f32; 2] {
        [
            self.inner().ButtonTextAlign.x,
            self.inner().ButtonTextAlign.y,
        ]
    }
    pub fn set_button_text_align(&mut self, v: [f32; 2]) {
        self.inner_mut().ButtonTextAlign = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn selectable_text_align(&self) -> [f32; 2] {
        [
            self.inner().SelectableTextAlign.x,
            self.inner().SelectableTextAlign.y,
        ]
    }
    pub fn set_selectable_text_align(&mut self, v: [f32; 2]) {
        self.inner_mut().SelectableTextAlign = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn display_window_padding(&self) -> [f32; 2] {
        [
            self.inner().DisplayWindowPadding.x,
            self.inner().DisplayWindowPadding.y,
        ]
    }
    pub fn set_display_window_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().DisplayWindowPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn display_safe_area_padding(&self) -> [f32; 2] {
        [
            self.inner().DisplaySafeAreaPadding.x,
            self.inner().DisplaySafeAreaPadding.y,
        ]
    }
    pub fn set_display_safe_area_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().DisplaySafeAreaPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn mouse_cursor_scale(&self) -> f32 {
        self.inner().MouseCursorScale
    }
    pub fn set_mouse_cursor_scale(&mut self, v: f32) {
        self.inner_mut().MouseCursorScale = v;
    }

    pub fn anti_aliased_lines(&self) -> bool {
        self.inner().AntiAliasedLines
    }
    pub fn set_anti_aliased_lines(&mut self, v: bool) {
        self.inner_mut().AntiAliasedLines = v;
    }

    pub fn anti_aliased_lines_use_tex(&self) -> bool {
        self.inner().AntiAliasedLinesUseTex
    }
    pub fn set_anti_aliased_lines_use_tex(&mut self, v: bool) {
        self.inner_mut().AntiAliasedLinesUseTex = v;
    }

    pub fn anti_aliased_fill(&self) -> bool {
        self.inner().AntiAliasedFill
    }
    pub fn set_anti_aliased_fill(&mut self, v: bool) {
        self.inner_mut().AntiAliasedFill = v;
    }

    pub fn curve_tessellation_tol(&self) -> f32 {
        self.inner().CurveTessellationTol
    }
    pub fn set_curve_tessellation_tol(&mut self, v: f32) {
        self.inner_mut().CurveTessellationTol = v;
    }

    pub fn circle_tessellation_max_error(&self) -> f32 {
        self.inner().CircleTessellationMaxError
    }
    pub fn set_circle_tessellation_max_error(&mut self, v: f32) {
        self.inner_mut().CircleTessellationMaxError = v;
    }

    // Newly exposed 1.92+ or less-common fields

    pub fn window_border_hover_padding(&self) -> f32 {
        self.inner().WindowBorderHoverPadding
    }
    pub fn set_window_border_hover_padding(&mut self, v: f32) {
        self.inner_mut().WindowBorderHoverPadding = v;
    }

    pub fn scrollbar_padding(&self) -> f32 {
        self.inner().ScrollbarPadding
    }
    pub fn set_scrollbar_padding(&mut self, v: f32) {
        self.inner_mut().ScrollbarPadding = v;
    }

    pub fn image_border_size(&self) -> f32 {
        self.inner().ImageBorderSize
    }
    pub fn set_image_border_size(&mut self, v: f32) {
        self.inner_mut().ImageBorderSize = v;
    }

    pub fn tab_min_width_base(&self) -> f32 {
        self.inner().TabMinWidthBase
    }
    pub fn set_tab_min_width_base(&mut self, v: f32) {
        self.inner_mut().TabMinWidthBase = v;
    }

    pub fn tab_min_width_shrink(&self) -> f32 {
        self.inner().TabMinWidthShrink
    }
    pub fn set_tab_min_width_shrink(&mut self, v: f32) {
        self.inner_mut().TabMinWidthShrink = v;
    }

    pub fn tab_close_button_min_width_selected(&self) -> f32 {
        self.inner().TabCloseButtonMinWidthSelected
    }
    pub fn set_tab_close_button_min_width_selected(&mut self, v: f32) {
        self.inner_mut().TabCloseButtonMinWidthSelected = v;
    }

    pub fn tab_close_button_min_width_unselected(&self) -> f32 {
        self.inner().TabCloseButtonMinWidthUnselected
    }
    pub fn set_tab_close_button_min_width_unselected(&mut self, v: f32) {
        self.inner_mut().TabCloseButtonMinWidthUnselected = v;
    }

    pub fn tab_bar_border_size(&self) -> f32 {
        self.inner().TabBarBorderSize
    }
    pub fn set_tab_bar_border_size(&mut self, v: f32) {
        self.inner_mut().TabBarBorderSize = v;
    }

    pub fn tab_bar_overline_size(&self) -> f32 {
        self.inner().TabBarOverlineSize
    }
    pub fn set_tab_bar_overline_size(&mut self, v: f32) {
        self.inner_mut().TabBarOverlineSize = v;
    }

    pub fn table_angled_headers_angle(&self) -> f32 {
        self.inner().TableAngledHeadersAngle
    }
    pub fn set_table_angled_headers_angle(&mut self, v: f32) {
        self.inner_mut().TableAngledHeadersAngle = v;
    }

    pub fn table_angled_headers_text_align(&self) -> [f32; 2] {
        [
            self.inner().TableAngledHeadersTextAlign.x,
            self.inner().TableAngledHeadersTextAlign.y,
        ]
    }
    pub fn set_table_angled_headers_text_align(&mut self, v: [f32; 2]) {
        self.inner_mut().TableAngledHeadersTextAlign = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn tree_lines_flags(&self) -> TreeNodeFlags {
        TreeNodeFlags::from_bits_truncate(self.inner().TreeLinesFlags as i32)
    }
    pub fn set_tree_lines_flags(&mut self, flags: TreeNodeFlags) {
        self.inner_mut().TreeLinesFlags = flags.bits() as sys::ImGuiTreeNodeFlags;
    }

    pub fn tree_lines_size(&self) -> f32 {
        self.inner().TreeLinesSize
    }
    pub fn set_tree_lines_size(&mut self, v: f32) {
        self.inner_mut().TreeLinesSize = v;
    }

    pub fn tree_lines_rounding(&self) -> f32 {
        self.inner().TreeLinesRounding
    }
    pub fn set_tree_lines_rounding(&mut self, v: f32) {
        self.inner_mut().TreeLinesRounding = v;
    }

    pub fn separator_size(&self) -> f32 {
        self.inner().SeparatorSize
    }
    pub fn set_separator_size(&mut self, v: f32) {
        self.inner_mut().SeparatorSize = v;
    }

    pub fn separator_text_border_size(&self) -> f32 {
        self.inner().SeparatorTextBorderSize
    }
    pub fn set_separator_text_border_size(&mut self, v: f32) {
        self.inner_mut().SeparatorTextBorderSize = v;
    }

    pub fn separator_text_align(&self) -> [f32; 2] {
        [
            self.inner().SeparatorTextAlign.x,
            self.inner().SeparatorTextAlign.y,
        ]
    }
    pub fn set_separator_text_align(&mut self, v: [f32; 2]) {
        self.inner_mut().SeparatorTextAlign = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn separator_text_padding(&self) -> [f32; 2] {
        [
            self.inner().SeparatorTextPadding.x,
            self.inner().SeparatorTextPadding.y,
        ]
    }
    pub fn set_separator_text_padding(&mut self, v: [f32; 2]) {
        self.inner_mut().SeparatorTextPadding = sys::ImVec2 { x: v[0], y: v[1] };
    }

    pub fn docking_node_has_close_button(&self) -> bool {
        self.inner().DockingNodeHasCloseButton
    }
    pub fn set_docking_node_has_close_button(&mut self, v: bool) {
        self.inner_mut().DockingNodeHasCloseButton = v;
    }

    pub fn docking_separator_size(&self) -> f32 {
        self.inner().DockingSeparatorSize
    }
    pub fn set_docking_separator_size(&mut self, v: f32) {
        self.inner_mut().DockingSeparatorSize = v;
    }

    pub fn hover_stationary_delay(&self) -> f32 {
        self.inner().HoverStationaryDelay
    }
    pub fn set_hover_stationary_delay(&mut self, v: f32) {
        self.inner_mut().HoverStationaryDelay = v;
    }

    pub fn hover_delay_short(&self) -> f32 {
        self.inner().HoverDelayShort
    }
    pub fn set_hover_delay_short(&mut self, v: f32) {
        self.inner_mut().HoverDelayShort = v;
    }

    pub fn hover_delay_normal(&self) -> f32 {
        self.inner().HoverDelayNormal
    }
    pub fn set_hover_delay_normal(&mut self, v: f32) {
        self.inner_mut().HoverDelayNormal = v;
    }

    pub fn hover_flags_for_tooltip_mouse(&self) -> HoveredFlags {
        HoveredFlags::from_bits_truncate(self.inner().HoverFlagsForTooltipMouse as i32)
    }
    pub fn set_hover_flags_for_tooltip_mouse(&mut self, flags: HoveredFlags) {
        self.inner_mut().HoverFlagsForTooltipMouse = flags.bits() as sys::ImGuiHoveredFlags;
    }

    pub fn hover_flags_for_tooltip_nav(&self) -> HoveredFlags {
        HoveredFlags::from_bits_truncate(self.inner().HoverFlagsForTooltipNav as i32)
    }
    pub fn set_hover_flags_for_tooltip_nav(&mut self, flags: HoveredFlags) {
        self.inner_mut().HoverFlagsForTooltipNav = flags.bits() as sys::ImGuiHoveredFlags;
    }
}

// HoveredFlags are defined in utils.rs and re-exported at crate root.

/// A cardinal direction
#[repr(i32)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Direction {
    None = sys::ImGuiDir_None as i32,
    Left = sys::ImGuiDir_Left as i32,
    Right = sys::ImGuiDir_Right as i32,
    Up = sys::ImGuiDir_Up as i32,
    Down = sys::ImGuiDir_Down as i32,
}

impl From<sys::ImGuiDir> for Direction {
    fn from(d: sys::ImGuiDir) -> Self {
        match d as i32 {
            x if x == sys::ImGuiDir_Left as i32 => Direction::Left,
            x if x == sys::ImGuiDir_Right as i32 => Direction::Right,
            x if x == sys::ImGuiDir_Up as i32 => Direction::Up,
            x if x == sys::ImGuiDir_Down as i32 => Direction::Down,
            _ => Direction::None,
        }
    }
}

impl From<Direction> for sys::ImGuiDir {
    fn from(d: Direction) -> Self {
        match d {
            Direction::None => sys::ImGuiDir_None,
            Direction::Left => sys::ImGuiDir_Left,
            Direction::Right => sys::ImGuiDir_Right,
            Direction::Up => sys::ImGuiDir_Up,
            Direction::Down => sys::ImGuiDir_Down,
        }
    }
}

/// Style color identifier
#[repr(i32)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum StyleColor {
    Text = sys::ImGuiCol_Text as i32,
    TextDisabled = sys::ImGuiCol_TextDisabled as i32,
    WindowBg = sys::ImGuiCol_WindowBg as i32,
    ChildBg = sys::ImGuiCol_ChildBg as i32,
    PopupBg = sys::ImGuiCol_PopupBg as i32,
    Border = sys::ImGuiCol_Border as i32,
    BorderShadow = sys::ImGuiCol_BorderShadow as i32,
    FrameBg = sys::ImGuiCol_FrameBg as i32,
    FrameBgHovered = sys::ImGuiCol_FrameBgHovered as i32,
    FrameBgActive = sys::ImGuiCol_FrameBgActive as i32,
    TitleBg = sys::ImGuiCol_TitleBg as i32,
    TitleBgActive = sys::ImGuiCol_TitleBgActive as i32,
    TitleBgCollapsed = sys::ImGuiCol_TitleBgCollapsed as i32,
    MenuBarBg = sys::ImGuiCol_MenuBarBg as i32,
    ScrollbarBg = sys::ImGuiCol_ScrollbarBg as i32,
    ScrollbarGrab = sys::ImGuiCol_ScrollbarGrab as i32,
    ScrollbarGrabHovered = sys::ImGuiCol_ScrollbarGrabHovered as i32,
    ScrollbarGrabActive = sys::ImGuiCol_ScrollbarGrabActive as i32,
    CheckMark = sys::ImGuiCol_CheckMark as i32,
    SliderGrab = sys::ImGuiCol_SliderGrab as i32,
    SliderGrabActive = sys::ImGuiCol_SliderGrabActive as i32,
    Button = sys::ImGuiCol_Button as i32,
    ButtonHovered = sys::ImGuiCol_ButtonHovered as i32,
    ButtonActive = sys::ImGuiCol_ButtonActive as i32,
    Header = sys::ImGuiCol_Header as i32,
    HeaderHovered = sys::ImGuiCol_HeaderHovered as i32,
    HeaderActive = sys::ImGuiCol_HeaderActive as i32,
    Separator = sys::ImGuiCol_Separator as i32,
    SeparatorHovered = sys::ImGuiCol_SeparatorHovered as i32,
    SeparatorActive = sys::ImGuiCol_SeparatorActive as i32,
    ResizeGrip = sys::ImGuiCol_ResizeGrip as i32,
    ResizeGripHovered = sys::ImGuiCol_ResizeGripHovered as i32,
    ResizeGripActive = sys::ImGuiCol_ResizeGripActive as i32,
    Tab = sys::ImGuiCol_Tab as i32,
    TabHovered = sys::ImGuiCol_TabHovered as i32,
    // Newly added tab colors in docking branch
    TabSelected = sys::ImGuiCol_TabSelected as i32,
    TabSelectedOverline = sys::ImGuiCol_TabSelectedOverline as i32,
    TabDimmed = sys::ImGuiCol_TabDimmed as i32,
    TabDimmedSelected = sys::ImGuiCol_TabDimmedSelected as i32,
    TabDimmedSelectedOverline = sys::ImGuiCol_TabDimmedSelectedOverline as i32,
    DockingPreview = sys::ImGuiCol_DockingPreview as i32,
    DockingEmptyBg = sys::ImGuiCol_DockingEmptyBg as i32,
    PlotLines = sys::ImGuiCol_PlotLines as i32,
    PlotLinesHovered = sys::ImGuiCol_PlotLinesHovered as i32,
    PlotHistogram = sys::ImGuiCol_PlotHistogram as i32,
    PlotHistogramHovered = sys::ImGuiCol_PlotHistogramHovered as i32,
    TableHeaderBg = sys::ImGuiCol_TableHeaderBg as i32,
    TableBorderStrong = sys::ImGuiCol_TableBorderStrong as i32,
    TableBorderLight = sys::ImGuiCol_TableBorderLight as i32,
    TableRowBg = sys::ImGuiCol_TableRowBg as i32,
    TableRowBgAlt = sys::ImGuiCol_TableRowBgAlt as i32,
    TextSelectedBg = sys::ImGuiCol_TextSelectedBg as i32,
    TextLink = sys::ImGuiCol_TextLink as i32,
    TreeLines = sys::ImGuiCol_TreeLines as i32,
    InputTextCursor = sys::ImGuiCol_InputTextCursor as i32,
    DragDropTarget = sys::ImGuiCol_DragDropTarget as i32,
    DragDropTargetBg = sys::ImGuiCol_DragDropTargetBg as i32,
    UnsavedMarker = sys::ImGuiCol_UnsavedMarker as i32,
    NavCursor = sys::ImGuiCol_NavCursor as i32,
    NavWindowingHighlight = sys::ImGuiCol_NavWindowingHighlight as i32,
    NavWindowingDimBg = sys::ImGuiCol_NavWindowingDimBg as i32,
    ModalWindowDimBg = sys::ImGuiCol_ModalWindowDimBg as i32,
}

impl StyleColor {
    pub const COUNT: usize = sys::ImGuiCol_COUNT as usize;
}

impl Clone for Style {
    fn clone(&self) -> Self {
        Self(UnsafeCell::new(*self.inner()))
    }
}

impl PartialEq for Style {
    fn eq(&self, other: &Self) -> bool {
        *self.inner() == *other.inner()
    }
}

impl RawWrapper for Style {
    type Raw = sys::ImGuiStyle;

    unsafe fn raw(&self) -> &Self::Raw {
        self.inner()
    }

    unsafe fn raw_mut(&mut self) -> &mut Self::Raw {
        self.inner_mut()
    }
}

/// A temporary change in user interface style
#[derive(Copy, Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum StyleVar {
    /// Global alpha applies to everything
    Alpha(f32),
    /// Additional alpha multiplier applied to disabled elements
    DisabledAlpha(f32),
    /// Padding within a window
    WindowPadding([f32; 2]),
    /// Rounding radius of window corners
    WindowRounding(f32),
    /// Thickness of border around windows
    WindowBorderSize(f32),
    /// Minimum window size
    WindowMinSize([f32; 2]),
    /// Alignment for title bar text
    WindowTitleAlign([f32; 2]),
    /// Rounding radius of child window corners
    ChildRounding(f32),
    /// Thickness of border around child windows
    ChildBorderSize(f32),
    /// Rounding radius of popup window corners
    PopupRounding(f32),
    /// Thickness of border around popup/tooltip windows
    PopupBorderSize(f32),
    /// Padding within a framed rectangle (used by most widgets)
    FramePadding([f32; 2]),
    /// Rounding radius of frame corners (used by most widgets)
    FrameRounding(f32),
    /// Rounding radius of image corners (used by Image() and ImageButton() widgets)
    ImageRounding(f32),
    /// Thickness of border around frames
    FrameBorderSize(f32),
    /// Horizontal and vertical spacing between widgets/lines
    ItemSpacing([f32; 2]),
    /// Horizontal and vertical spacing between within elements of a composed widget
    ItemInnerSpacing([f32; 2]),
    /// Horizontal indentation when e.g. entering a tree node
    IndentSpacing(f32),
    /// Padding within a table cell
    CellPadding([f32; 2]),
    /// Width of the vertical scrollbar, height of the horizontal scrollbar
    ScrollbarSize(f32),
    /// Rounding radius of scrollbar corners
    ScrollbarRounding(f32),
    /// Minimum width/height of a grab box for slider/scrollbar
    GrabMinSize(f32),
    /// Rounding radius of grabs corners
    GrabRounding(f32),
    /// Rounding radius of upper corners of tabs
    TabRounding(f32),
    /// Alignment of button text when button is larger than text
    ButtonTextAlign([f32; 2]),
    /// Alignment of selectable text when selectable is larger than text
    SelectableTextAlign([f32; 2]),
    /// Thickness of border in `Separator()`
    SeparatorSize(f32),
}

/// Which base preset to start from when applying a [`Theme`].
///
/// This controls which built-in Dear ImGui color set is used as a starting
/// point before applying any overrides.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ThemePreset {
    /// Do not touch existing style colors; only apply explicit overrides.
    None,
    /// Use Dear ImGui's built-in dark preset.
    Dark,
    /// Use Dear ImGui's built-in light preset.
    Light,
    /// Use Dear ImGui's classic preset.
    Classic,
}

impl Default for ThemePreset {
    fn default() -> Self {
        ThemePreset::None
    }
}

/// A single color override for a given [`StyleColor`] entry.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct ColorOverride {
    /// Target style color to override.
    pub id: StyleColor,
    /// New RGBA color (0.0-1.0 range) to apply.
    pub rgba: [f32; 4],
}

/// High-level style tweaks that can be applied on top of a preset.
///
/// This does not expose the full `ImGuiStyle` surface, only the most commonly
/// themed fields. All fields are optional; `None` means "leave unchanged".
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct StyleTweaks {
    pub window_rounding: Option<f32>,
    pub frame_rounding: Option<f32>,
    pub tab_rounding: Option<f32>,

    pub window_padding: Option<[f32; 2]>,
    pub frame_padding: Option<[f32; 2]>,
    pub cell_padding: Option<[f32; 2]>,
    pub item_spacing: Option<[f32; 2]>,
    pub item_inner_spacing: Option<[f32; 2]>,

    pub scrollbar_size: Option<f32>,
    pub grab_min_size: Option<f32>,

    pub indent_spacing: Option<f32>,
    pub separator_size: Option<f32>,
    pub scrollbar_rounding: Option<f32>,
    pub grab_rounding: Option<f32>,
    pub window_border_size: Option<f32>,
    pub child_border_size: Option<f32>,
    pub popup_border_size: Option<f32>,
    pub frame_border_size: Option<f32>,
    pub tab_border_size: Option<f32>,
    pub child_rounding: Option<f32>,
    pub popup_rounding: Option<f32>,

    pub anti_aliased_lines: Option<bool>,
    pub anti_aliased_fill: Option<bool>,
}

impl Default for StyleTweaks {
    fn default() -> Self {
        Self {
            window_rounding: None,
            frame_rounding: None,
            tab_rounding: None,
            window_padding: None,
            frame_padding: None,
            cell_padding: None,
            item_spacing: None,
            item_inner_spacing: None,
            scrollbar_size: None,
            grab_min_size: None,
            indent_spacing: None,
            separator_size: None,
            scrollbar_rounding: None,
            grab_rounding: None,
            window_border_size: None,
            child_border_size: None,
            popup_border_size: None,
            frame_border_size: None,
            tab_border_size: None,
            child_rounding: None,
            popup_rounding: None,
            anti_aliased_lines: None,
            anti_aliased_fill: None,
        }
    }
}

impl StyleTweaks {
    /// Apply these tweaks to the given style.
    pub fn apply(&self, style: &mut Style) {
        if let Some(v) = self.window_rounding {
            style.set_window_rounding(v);
        }
        if let Some(v) = self.frame_rounding {
            style.set_frame_rounding(v);
        }
        if let Some(v) = self.tab_rounding {
            style.set_tab_rounding(v);
        }

        if let Some(v) = self.window_padding {
            style.set_window_padding(v);
        }
        if let Some(v) = self.frame_padding {
            style.set_frame_padding(v);
        }
        if let Some(v) = self.cell_padding {
            style.set_cell_padding(v);
        }
        if let Some(v) = self.item_spacing {
            style.set_item_spacing(v);
        }
        if let Some(v) = self.item_inner_spacing {
            style.set_item_inner_spacing(v);
        }

        if let Some(v) = self.scrollbar_size {
            style.set_scrollbar_size(v);
        }
        if let Some(v) = self.grab_min_size {
            style.set_grab_min_size(v);
        }

        if let Some(v) = self.indent_spacing {
            style.set_indent_spacing(v);
        }
        if let Some(v) = self.separator_size {
            style.set_separator_size(v);
        }
        if let Some(v) = self.scrollbar_rounding {
            style.set_scrollbar_rounding(v);
        }
        if let Some(v) = self.grab_rounding {
            style.set_grab_rounding(v);
        }
        if let Some(v) = self.window_border_size {
            style.set_window_border_size(v);
        }
        if let Some(v) = self.child_border_size {
            style.set_child_border_size(v);
        }
        if let Some(v) = self.popup_border_size {
            style.set_popup_border_size(v);
        }
        if let Some(v) = self.frame_border_size {
            style.set_frame_border_size(v);
        }
        if let Some(v) = self.tab_border_size {
            style.set_tab_border_size(v);
        }
        if let Some(v) = self.child_rounding {
            style.set_child_rounding(v);
        }
        if let Some(v) = self.popup_rounding {
            style.set_popup_rounding(v);
        }

        if let Some(v) = self.anti_aliased_lines {
            style.set_anti_aliased_lines(v);
        }
        if let Some(v) = self.anti_aliased_fill {
            style.set_anti_aliased_fill(v);
        }
    }
}

/// Window-related theme defaults (flags/behavior).
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct WindowTheme {
    /// Default flags for top-level windows.
    pub default_window_flags: Option<WindowFlags>,
    /// Default flags for popups/modals.
    pub popup_window_flags: Option<WindowFlags>,
}

/// Table-related theme defaults (flags/behavior).
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct TableTheme {
    /// Default flags for tables created via `Ui::table` / `Ui::begin_table`.
    pub default_table_flags: Option<TableFlags>,
    /// Default row flags for data tables.
    pub default_row_flags: Option<TableRowFlags>,
}

/// High-level theme configuration for Dear ImGui.
///
/// A theme is applied in three stages:
/// 1) Choose a base preset (`Dark`/`Light`/`Classic` or `None`).
/// 2) Apply any explicit color overrides.
/// 3) Apply a small set of style tweaks.
///
/// Window/table defaults are provided as data and can be used by higher-level
/// helpers when building windows and tables.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Theme {
    /// Base preset to start from, before applying overrides.
    #[cfg_attr(feature = "serde", serde(default))]
    pub preset: ThemePreset,

    /// Color overrides on top of the preset.
    #[cfg_attr(feature = "serde", serde(default))]
    pub colors: Vec<ColorOverride>,

    /// Optional style tweaks on top of the preset.
    #[cfg_attr(feature = "serde", serde(default))]
    pub style: StyleTweaks,

    /// Window-related defaults (flags/behavior).
    #[cfg_attr(feature = "serde", serde(default))]
    pub windows: WindowTheme,

    /// Table-related defaults (flags/behavior).
    #[cfg_attr(feature = "serde", serde(default))]
    pub tables: TableTheme,
}

impl Theme {
    /// Apply this theme to a given style.
    ///
    /// This does not touch fonts or IO; it only updates `ImGuiStyle`.
    pub fn apply_to_style(&self, style: &mut Style) {
        // 1) Base preset
        match self.preset {
            ThemePreset::None => {}
            ThemePreset::Dark => unsafe {
                sys::igStyleColorsDark(style.raw_mut());
            },
            ThemePreset::Light => unsafe {
                sys::igStyleColorsLight(style.raw_mut());
            },
            ThemePreset::Classic => unsafe {
                sys::igStyleColorsClassic(style.raw_mut());
            },
        }

        // 2) Color overrides
        for c in &self.colors {
            style.set_color(c.id, c.rgba);
        }

        // 3) Common style tweaks
        self.style.apply(style);
    }

    /// Apply this theme to the given context (current style).
    pub fn apply_to_context(&self, ctx: &mut Context) {
        let style = ctx.style_mut();
        self.apply_to_style(style);
    }
}