@@ -43,8 +43,10 @@ use std::sync::Arc;
43
43
use std:: time:: Instant ;
44
44
use surfman:: { Connection , ContextAttributeFlags , ContextAttributes , GLVersion as SurfmanGLVersion } ;
45
45
use surfman:: { SurfaceAccess , SurfaceType } ;
46
+
46
47
use winit:: dpi:: LogicalSize ;
47
- use winit:: { Event , EventsLoop , KeyboardInput , VirtualKeyCode , WindowBuilder , WindowEvent } ;
48
+ use winit:: platform:: run_return:: EventLoopExtRunReturn ;
49
+ use winit:: { event:: { Event , WindowEvent , KeyboardInput , VirtualKeyCode } , window:: WindowBuilder , event_loop:: { EventLoop , ControlFlow } } ;
48
50
49
51
#[ cfg( not( windows) ) ]
50
52
use jemallocator;
@@ -1465,14 +1467,14 @@ impl DemoData {
1465
1467
1466
1468
fn main ( ) {
1467
1469
// Open a window.
1468
- let mut event_loop = EventsLoop :: new ( ) ;
1470
+ let mut event_loop = EventLoop :: new ( ) ;
1469
1471
let window_size = Size2D :: new ( WINDOW_WIDTH , WINDOW_HEIGHT ) ;
1470
1472
let logical_size = LogicalSize :: new ( window_size. width as f64 , window_size. height as f64 ) ;
1471
1473
let window = WindowBuilder :: new ( ) . with_title ( "NanoVG example port" )
1472
- . with_dimensions ( logical_size)
1474
+ . with_inner_size ( logical_size)
1473
1475
. build ( & event_loop)
1474
1476
. unwrap ( ) ;
1475
- window. show ( ) ;
1477
+ // window.show();
1476
1478
1477
1479
// Create a `surfman` device. On a multi-GPU system, we'll request the low-power integrated
1478
1480
// GPU.
@@ -1490,17 +1492,17 @@ fn main() {
1490
1492
1491
1493
// Make the OpenGL context via `surfman`, and load OpenGL functions.
1492
1494
let surface_type = SurfaceType :: Widget { native_widget } ;
1493
- let mut gl_context = device. create_context ( & context_descriptor) . unwrap ( ) ;
1495
+ let mut gl_context = device. create_context ( & context_descriptor, None ) . unwrap ( ) ;
1494
1496
let surface = device. create_surface ( & gl_context, SurfaceAccess :: GPUOnly , surface_type)
1495
1497
. unwrap ( ) ;
1496
1498
device. bind_surface_to_context ( & mut gl_context, surface) . unwrap ( ) ;
1497
1499
device. make_context_current ( & gl_context) . unwrap ( ) ;
1498
1500
gl:: load_with ( |symbol_name| device. get_proc_address ( & gl_context, symbol_name) ) ;
1499
1501
1500
1502
// Get the real size of the window, taking HiDPI into account.
1501
- let hidpi_factor = window. get_current_monitor ( ) . get_hidpi_factor ( ) ;
1502
- let physical_size = logical_size. to_physical ( hidpi_factor) ;
1503
- let framebuffer_size = vec2i ( physical_size. width as i32 , physical_size. height as i32 ) ;
1503
+ let hidpi_factor = window. current_monitor ( ) . unwrap ( ) . scale_factor ( ) ;
1504
+ let physical_size = logical_size. to_physical :: < i32 > ( hidpi_factor) ;
1505
+ let framebuffer_size = vec2i ( physical_size. width , physical_size. height ) ;
1504
1506
1505
1507
// Load demo data.
1506
1508
let resources = FilesystemResourceLoader :: locate ( ) ;
@@ -1591,7 +1593,7 @@ fn main() {
1591
1593
gpu_graph. push ( gpu_time) ;
1592
1594
}
1593
1595
1594
- event_loop. poll_events ( |event| {
1596
+ event_loop. run_return ( |event, _ , control | {
1595
1597
match event {
1596
1598
Event :: WindowEvent { event : WindowEvent :: CloseRequested , .. } |
1597
1599
Event :: WindowEvent {
@@ -1604,7 +1606,9 @@ fn main() {
1604
1606
Event :: WindowEvent { event : WindowEvent :: CursorMoved { position, .. } , .. } => {
1605
1607
mouse_position = vec2f ( position. x as f32 , position. y as f32 ) ;
1606
1608
}
1607
- _ => { }
1609
+ _ => {
1610
+ * control = ControlFlow :: Exit ;
1611
+ }
1608
1612
}
1609
1613
} ) ;
1610
1614
}
0 commit comments