1- use baseview:: gl:: GlConfig ;
1+ use baseview:: gl:: { GlConfig , GlContext } ;
22use baseview:: {
33 Event , EventStatus , MouseEvent , PhyPoint , Size , Window , WindowEvent , WindowHandler , WindowInfo ,
44 WindowOpenOptions , WindowScalePolicy ,
@@ -7,42 +7,45 @@ use femtovg::renderer::OpenGl;
77use femtovg:: { Canvas , Color } ;
88
99struct FemtovgExample {
10+ _window : Window ,
11+ gl_context : GlContext ,
1012 canvas : Canvas < OpenGl > ,
1113 current_size : WindowInfo ,
1214 current_mouse_position : PhyPoint ,
1315 damaged : bool ,
1416}
1517
1618impl FemtovgExample {
17- fn new ( window : & mut Window ) -> Self {
18- let context = window. gl_context ( ) . unwrap ( ) ;
19- unsafe { context . make_current ( ) } ;
19+ fn new ( window : Window ) -> Self {
20+ let gl_context = window. gl_context ( ) . unwrap ( ) ;
21+ unsafe { gl_context . make_current ( ) } ;
2022
2123 let renderer =
22- unsafe { OpenGl :: new_from_function ( |s| context . get_proc_address ( s) ) } . unwrap ( ) ;
24+ unsafe { OpenGl :: new_from_function ( |s| gl_context . get_proc_address ( s) ) } . unwrap ( ) ;
2325
2426 let mut canvas = Canvas :: new ( renderer) . unwrap ( ) ;
2527 // TODO: get actual window width
2628 canvas. set_size ( 512 , 512 , 1.0 ) ;
2729
28- unsafe { context . make_not_current ( ) } ;
30+ unsafe { gl_context . make_not_current ( ) } ;
2931 Self {
3032 canvas,
3133 current_size : WindowInfo :: from_logical_size ( Size { width : 512.0 , height : 512.0 } , 1.0 ) ,
3234 current_mouse_position : PhyPoint { x : 256 , y : 256 } ,
3335 damaged : true ,
36+ _window : window,
37+ gl_context,
3438 }
3539 }
3640}
3741
3842impl WindowHandler for FemtovgExample {
39- fn on_frame ( & mut self , window : & mut Window ) {
43+ fn on_frame ( & mut self ) {
4044 if !self . damaged {
4145 return ;
4246 }
4347
44- let context = window. gl_context ( ) . unwrap ( ) ;
45- unsafe { context. make_current ( ) } ;
48+ unsafe { self . gl_context . make_current ( ) } ;
4649
4750 let screen_height = self . canvas . height ( ) ;
4851 let screen_width = self . canvas . width ( ) ;
@@ -70,12 +73,12 @@ impl WindowHandler for FemtovgExample {
7073
7174 // Tell renderer to execute all drawing commands
7275 self . canvas . flush ( ) ;
73- context . swap_buffers ( ) ;
74- unsafe { context . make_not_current ( ) } ;
76+ self . gl_context . swap_buffers ( ) ;
77+ unsafe { self . gl_context . make_not_current ( ) } ;
7578 self . damaged = false ;
7679 }
7780
78- fn on_event ( & mut self , _window : & mut Window , event : Event ) -> EventStatus {
81+ fn on_event ( & mut self , event : Event ) -> EventStatus {
7982 match event {
8083 Event :: Window ( WindowEvent :: Resized ( size) ) => {
8184 let phy_size = size. physical_size ( ) ;
0 commit comments