@@ -13,7 +13,6 @@ use crate::{
13
13
views:: { BoxedView , CircularFocus , Layer , ShadowView } ,
14
14
Printer , Vec2 , With ,
15
15
} ;
16
- use std:: cell;
17
16
use std:: ops:: Deref ;
18
17
19
18
/// Simple stack of views.
@@ -26,7 +25,7 @@ pub struct StackView {
26
25
// and therefore need redrawing.
27
26
// TODO: this is broken! Transparent views could change their content and lead to weirdness.
28
27
// Instead, just rely on buffered backend.
29
- bg_dirty : cell :: Cell < bool > ,
28
+ bg_dirty : std :: sync :: atomic :: AtomicBool ,
30
29
}
31
30
32
31
// This is a poor man's optional parameter, or kinda builder pattern.
@@ -310,7 +309,7 @@ impl StackView {
310
309
StackView {
311
310
layers : Vec :: new ( ) ,
312
311
last_size : Vec2 :: zero ( ) ,
313
- bg_dirty : cell :: Cell :: new ( true ) ,
312
+ bg_dirty : std :: sync :: atomic :: AtomicBool :: new ( true ) ,
314
313
}
315
314
}
316
315
@@ -514,7 +513,7 @@ impl StackView {
514
513
///
515
514
/// If the given position is out of bounds.
516
515
pub fn remove_layer ( & mut self , position : LayerPosition ) -> Box < dyn View > {
517
- self . bg_dirty . set ( true ) ;
516
+ self . set_dirty ( ) ;
518
517
let i = self . get_index ( position) . unwrap ( ) ;
519
518
self . layers
520
519
. remove ( i)
@@ -526,9 +525,23 @@ impl StackView {
526
525
. unwrap ( )
527
526
}
528
527
528
+ fn set_dirty ( & self ) {
529
+ self . bg_dirty
530
+ . store ( true , std:: sync:: atomic:: Ordering :: Relaxed ) ;
531
+ }
532
+
533
+ fn undirty ( & self ) {
534
+ self . bg_dirty
535
+ . store ( false , std:: sync:: atomic:: Ordering :: Relaxed ) ;
536
+ }
537
+
538
+ fn is_dirty ( & self ) -> bool {
539
+ self . bg_dirty . load ( std:: sync:: atomic:: Ordering :: Relaxed )
540
+ }
541
+
529
542
/// Remove the top-most layer.
530
543
pub fn pop_layer ( & mut self ) -> Option < Box < dyn View > > {
531
- self . bg_dirty . set ( true ) ;
544
+ self . set_dirty ( ) ;
532
545
self . layers
533
546
. pop ( )
534
547
. map ( |child| child. view )
@@ -621,7 +634,7 @@ impl StackView {
621
634
match child. placement {
622
635
Placement :: Floating ( _) => {
623
636
child. placement = Placement :: Floating ( position) ;
624
- self . bg_dirty . set ( true ) ;
637
+ self . set_dirty ( ) ;
625
638
}
626
639
Placement :: Fullscreen => ( ) ,
627
640
}
@@ -642,15 +655,15 @@ impl StackView {
642
655
/// You probably just want to call draw()
643
656
pub fn draw_bg ( & self , printer : & Printer ) {
644
657
// If the background is dirty draw a new background
645
- if self . bg_dirty . get ( ) {
658
+ if self . is_dirty ( ) {
646
659
for y in 0 ..printer. size . y {
647
660
printer. with_style ( PaletteStyle :: Background , |printer| {
648
661
printer. print_hline ( ( 0 , y) , printer. size . x , " " ) ;
649
662
} ) ;
650
663
}
651
664
652
665
// set background as clean, so we don't need to do this every frame
653
- self . bg_dirty . set ( false ) ;
666
+ self . undirty ( ) ;
654
667
}
655
668
}
656
669
@@ -732,7 +745,7 @@ impl View for StackView {
732
745
733
746
fn on_event ( & mut self , event : Event ) -> EventResult {
734
747
if event == Event :: WindowResize {
735
- self . bg_dirty . set ( true ) ;
748
+ self . set_dirty ( ) ;
736
749
}
737
750
738
751
// Use the stack position iterator to get the offset of the top layer.
0 commit comments