11use std:: cell:: { Cell , RefCell } ;
22use std:: num:: NonZeroU32 ;
3+ use std:: thread;
34use std:: time:: Duration ;
45
56use rtrb:: { Consumer , RingBuffer } ;
@@ -8,8 +9,8 @@ use rtrb::{Consumer, RingBuffer};
89use baseview:: copy_to_clipboard;
910use baseview:: dpi:: { LogicalSize , PhysicalPosition } ;
1011use baseview:: {
11- Event , EventStatus , HandlerError , MouseEvent , Window , WindowContext , WindowHandler ,
12- WindowSettings , WindowSize ,
12+ Event , EventStatus , HandlerError , MouseEvent , Notification , Window , WindowContext ,
13+ WindowHandler , WindowSettings , WindowSize ,
1314} ;
1415
1516#[ derive( Debug , Clone ) ]
@@ -46,6 +47,8 @@ impl WindowHandler for OpenWindowExample {
4647 return Ok ( ( ) ) ;
4748 }
4849
50+ eprintln ! ( "Redraw!" ) ;
51+
4952 let mut surface = self . surface . borrow_mut ( ) ;
5053 let mut pixels = surface. buffer_mut ( ) ?;
5154 let size = self . window_context . size ( ) ;
@@ -137,6 +140,14 @@ impl WindowHandler for OpenWindowExample {
137140
138141 EventStatus :: Captured
139142 }
143+
144+ fn notify ( & self , notification : Notification ) -> Result < ( ) , HandlerError > {
145+ if let Notification :: Shown = notification {
146+ self . damaged . set ( true ) ;
147+ }
148+
149+ Ok ( ( ) )
150+ }
140151}
141152
142153fn main ( ) -> Result < ( ) , baseview:: Error > {
@@ -152,7 +163,7 @@ fn main() -> Result<(), baseview::Error> {
152163 }
153164 } ) ;
154165
155- Window :: create ( window_open_options, |window| {
166+ let w = Window :: create ( window_open_options, |window| {
156167 let ctx = softbuffer:: Context :: new ( window. clone ( ) ) ?;
157168 let mut surface = softbuffer:: Surface :: new ( & ctx, window. clone ( ) ) ?;
158169 let size = window. size ( ) . physical ;
@@ -166,8 +177,11 @@ fn main() -> Result<(), baseview::Error> {
166177 is_cursor_inside : false . into ( ) ,
167178 damaged : true . into ( ) ,
168179 } )
169- } ) ?
170- . run_until_closed ( ) ?;
180+ } ) ?;
181+
182+ thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
183+
184+ w. run_until_closed ( ) ?;
171185
172186 Ok ( ( ) )
173187}
0 commit comments