@@ -53,26 +53,25 @@ impl From<(f32, f32, f32)> for ImColor {
53
53
54
54
/// Object implementing the custom draw API.
55
55
///
56
- /// Called from [`Ui::get_window_draw_list`]. No more than one instance of this
57
- /// structure can live in a program at the same time.
56
+ /// Called from [`Ui::get_window_draw_list`], [`Ui::get_background_draw_list`] or [`Ui::get_foreground_draw_list`].
57
+ /// No more than one instance of this structure can live in a program at the same time.
58
58
/// The program will panic on creating a second instance.
59
- pub struct WindowDrawList < ' ui > {
59
+ pub struct DrawListMut < ' ui > {
60
60
draw_list : * mut ImDrawList ,
61
61
_phantom : PhantomData < & ' ui Ui < ' ui > > ,
62
62
}
63
63
64
- static WINDOW_DRAW_LIST_LOADED : std:: sync:: atomic:: AtomicBool =
65
- std:: sync:: atomic:: AtomicBool :: new ( false ) ;
64
+ static DRAW_LIST_LOADED : std:: sync:: atomic:: AtomicBool = std:: sync:: atomic:: AtomicBool :: new ( false ) ;
66
65
67
- impl < ' ui > Drop for WindowDrawList < ' ui > {
66
+ impl < ' ui > Drop for DrawListMut < ' ui > {
68
67
fn drop ( & mut self ) {
69
- WINDOW_DRAW_LIST_LOADED . store ( false , std:: sync:: atomic:: Ordering :: Release ) ;
68
+ DRAW_LIST_LOADED . store ( false , std:: sync:: atomic:: Ordering :: Release ) ;
70
69
}
71
70
}
72
71
73
- impl < ' ui > WindowDrawList < ' ui > {
74
- pub ( crate ) fn new ( _ : & Ui < ' ui > ) -> Self {
75
- let already_loaded = WINDOW_DRAW_LIST_LOADED
72
+ impl < ' ui > DrawListMut < ' ui > {
73
+ fn lock_draw_list ( ) {
74
+ let already_loaded = DRAW_LIST_LOADED
76
75
. compare_exchange (
77
76
false ,
78
77
true ,
@@ -81,21 +80,34 @@ impl<'ui> WindowDrawList<'ui> {
81
80
)
82
81
. is_err ( ) ;
83
82
if already_loaded {
84
- panic ! ( "WindowDrawList is already loaded! You can only load one instance of it!" )
83
+ panic ! ( "DrawListMut is already loaded! You can only load one instance of it!" )
85
84
}
85
+ }
86
+
87
+ pub ( crate ) fn window ( _: & Ui < ' ui > ) -> Self {
88
+ Self :: lock_draw_list ( ) ;
86
89
Self {
87
90
draw_list : unsafe { sys:: igGetWindowDrawList ( ) } ,
88
91
_phantom : PhantomData ,
89
92
}
90
93
}
91
94
92
- pub ( crate ) fn background ( self ) -> Self {
95
+ pub ( crate ) fn background ( _: & Ui < ' ui > ) -> Self {
96
+ Self :: lock_draw_list ( ) ;
93
97
Self {
94
98
draw_list : unsafe { sys:: igGetBackgroundDrawList ( ) } ,
95
99
_phantom : PhantomData ,
96
100
}
97
101
}
98
102
103
+ pub ( crate ) fn foreground ( _: & Ui < ' ui > ) -> Self {
104
+ Self :: lock_draw_list ( ) ;
105
+ Self {
106
+ draw_list : unsafe { sys:: igGetForegroundDrawList ( ) } ,
107
+ _phantom : PhantomData ,
108
+ }
109
+ }
110
+
99
111
/// Split into *channels_count* drawing channels.
100
112
/// At the end of the closure, the channels are merged. The objects
101
113
/// are then drawn in the increasing order of their channel number, and not
@@ -127,9 +139,9 @@ impl<'ui> WindowDrawList<'ui> {
127
139
128
140
/// Represent the drawing interface within a call to [`channels_split`].
129
141
///
130
- /// [`channels_split`]: WindowDrawList ::channels_split
142
+ /// [`channels_split`]: DrawListMut ::channels_split
131
143
pub struct ChannelsSplit < ' ui > {
132
- draw_list : & ' ui WindowDrawList < ' ui > ,
144
+ draw_list : & ' ui DrawListMut < ' ui > ,
133
145
channels_count : u32 ,
134
146
}
135
147
@@ -151,7 +163,7 @@ impl<'ui> ChannelsSplit<'ui> {
151
163
}
152
164
153
165
/// Drawing functions
154
- impl < ' ui > WindowDrawList < ' ui > {
166
+ impl < ' ui > DrawListMut < ' ui > {
155
167
/// Returns a line from point `p1` to `p2` with color `c`.
156
168
pub fn add_line < C > ( & ' ui self , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , c : C ) -> Line < ' ui >
157
169
where
@@ -291,11 +303,11 @@ pub struct Line<'ui> {
291
303
p2 : [ f32 ; 2 ] ,
292
304
color : ImColor ,
293
305
thickness : f32 ,
294
- draw_list : & ' ui WindowDrawList < ' ui > ,
306
+ draw_list : & ' ui DrawListMut < ' ui > ,
295
307
}
296
308
297
309
impl < ' ui > Line < ' ui > {
298
- fn new < C > ( draw_list : & ' ui WindowDrawList , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , c : C ) -> Self
310
+ fn new < C > ( draw_list : & ' ui DrawListMut , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , c : C ) -> Self
299
311
where
300
312
C : Into < ImColor > ,
301
313
{
@@ -338,11 +350,11 @@ pub struct Rect<'ui> {
338
350
flags : ImDrawCornerFlags ,
339
351
thickness : f32 ,
340
352
filled : bool ,
341
- draw_list : & ' ui WindowDrawList < ' ui > ,
353
+ draw_list : & ' ui DrawListMut < ' ui > ,
342
354
}
343
355
344
356
impl < ' ui > Rect < ' ui > {
345
- fn new < C > ( draw_list : & ' ui WindowDrawList , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , c : C ) -> Self
357
+ fn new < C > ( draw_list : & ' ui DrawListMut , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , c : C ) -> Self
346
358
where
347
359
C : Into < ImColor > ,
348
360
{
@@ -439,17 +451,11 @@ pub struct Triangle<'ui> {
439
451
color : ImColor ,
440
452
thickness : f32 ,
441
453
filled : bool ,
442
- draw_list : & ' ui WindowDrawList < ' ui > ,
454
+ draw_list : & ' ui DrawListMut < ' ui > ,
443
455
}
444
456
445
457
impl < ' ui > Triangle < ' ui > {
446
- fn new < C > (
447
- draw_list : & ' ui WindowDrawList ,
448
- p1 : [ f32 ; 2 ] ,
449
- p2 : [ f32 ; 2 ] ,
450
- p3 : [ f32 ; 2 ] ,
451
- c : C ,
452
- ) -> Self
458
+ fn new < C > ( draw_list : & ' ui DrawListMut , p1 : [ f32 ; 2 ] , p2 : [ f32 ; 2 ] , p3 : [ f32 ; 2 ] , c : C ) -> Self
453
459
where
454
460
C : Into < ImColor > ,
455
461
{
@@ -512,11 +518,11 @@ pub struct Circle<'ui> {
512
518
num_segments : u32 ,
513
519
thickness : f32 ,
514
520
filled : bool ,
515
- draw_list : & ' ui WindowDrawList < ' ui > ,
521
+ draw_list : & ' ui DrawListMut < ' ui > ,
516
522
}
517
523
518
524
impl < ' ui > Circle < ' ui > {
519
- pub fn new < C > ( draw_list : & ' ui WindowDrawList , center : [ f32 ; 2 ] , radius : f32 , color : C ) -> Self
525
+ pub fn new < C > ( draw_list : & ' ui DrawListMut , center : [ f32 ; 2 ] , radius : f32 , color : C ) -> Self
520
526
where
521
527
C : Into < ImColor > ,
522
528
{
@@ -588,12 +594,12 @@ pub struct BezierCurve<'ui> {
588
594
thickness : f32 ,
589
595
/// If num_segments is not set, the bezier curve is auto-tessalated.
590
596
num_segments : Option < u32 > ,
591
- draw_list : & ' ui WindowDrawList < ' ui > ,
597
+ draw_list : & ' ui DrawListMut < ' ui > ,
592
598
}
593
599
594
600
impl < ' ui > BezierCurve < ' ui > {
595
601
fn new < C > (
596
- draw_list : & ' ui WindowDrawList ,
602
+ draw_list : & ' ui DrawListMut ,
597
603
pos0 : [ f32 ; 2 ] ,
598
604
cp0 : [ f32 ; 2 ] ,
599
605
cp1 : [ f32 ; 2 ] ,
0 commit comments