From fb4a7968cab89a38870642d7528cb32943d07785 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jan 2020 03:56:13 +0100 Subject: Update `winit` to `0.20` --- winit/src/application.rs | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 4b21a930..31561689 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -138,10 +138,7 @@ pub trait Application: Sized { window_builder = window_builder .with_title(&title) - .with_inner_size(winit::dpi::LogicalSize { - width: f64::from(width), - height: f64::from(height), - }) + .with_inner_size(winit::dpi::LogicalSize { width, height }) .with_resizable(settings.window.resizable) .with_decorations(settings.window.decorations) .with_fullscreen(conversion::fullscreen( @@ -161,18 +158,22 @@ pub trait Application: Sized { window_builder.build(&event_loop).expect("Open window") }; - let dpi = window.hidpi_factor(); - let mut size = window.inner_size(); + let mut scale_factor = window.scale_factor(); + let mut size = window.inner_size().to_logical::(scale_factor); let mut resized = false; let clipboard = Clipboard::new(&window); let mut renderer = Self::Renderer::new(renderer_settings); let mut target = { - let (width, height) = to_physical(size, dpi); + let (width, height) = to_physical(size, scale_factor); ::Target::new( - &window, width, height, dpi as f32, &renderer, + &window, + width, + height, + scale_factor as f32, + &renderer, ) }; @@ -191,6 +192,7 @@ pub trait Application: Sized { let mut cache = Some(user_interface.into_cache()); let mut events = Vec::new(); let mut mouse_cursor = MouseCursor::OutOfBounds; + let mut modifiers = winit::event::ModifiersState::default(); debug.startup_finished(); window.request_redraw(); @@ -303,13 +305,12 @@ pub trait Application: Sized { debug.render_started(); if resized { - let dpi = window.hidpi_factor(); - let (width, height) = to_physical(size, dpi); + let (width, height) = to_physical(size, scale_factor); target.resize( width, height, - window.hidpi_factor() as f32, + scale_factor as f32, &renderer, ); @@ -337,18 +338,21 @@ pub trait Application: Sized { .. } => match window_event { WindowEvent::Resized(new_size) => { + size = new_size.to_logical(scale_factor); + events.push(Event::Window(window::Event::Resized { - width: new_size.width.round() as u32, - height: new_size.height.round() as u32, + width: size.width.round() as u32, + height: size.height.round() as u32, })); - size = new_size; resized = true; } WindowEvent::CloseRequested => { *control_flow = ControlFlow::Exit; } WindowEvent::CursorMoved { position, .. } => { + let position = position.to_logical::(scale_factor); + events.push(Event::Mouse(mouse::Event::CursorMoved { x: position.x as f32, y: position.y as f32, @@ -397,7 +401,6 @@ pub trait Application: Sized { winit::event::KeyboardInput { virtual_keycode: Some(virtual_keycode), state, - modifiers, .. }, .. @@ -427,8 +430,20 @@ pub trait Application: Sized { WindowEvent::HoveredFileCancelled => { events.push(Event::Window(window::Event::FilesHoveredLeft)); } + WindowEvent::ScaleFactorChanged { + scale_factor: new_scale_factor, + .. + } => { + scale_factor = new_scale_factor; + } _ => {} }, + event::Event::DeviceEvent { + event: event::DeviceEvent::ModifiersChanged(new_modifiers), + .. + } => { + modifiers = new_modifiers; + } _ => { *control_flow = ControlFlow::Wait; } @@ -440,7 +455,7 @@ fn build_user_interface<'a, A: Application>( application: &'a mut A, cache: Cache, renderer: &mut A::Renderer, - size: winit::dpi::LogicalSize, + size: winit::dpi::LogicalSize, debug: &mut Debug, ) -> UserInterface<'a, A::Message, A::Renderer> { debug.view_started(); @@ -459,12 +474,12 @@ fn build_user_interface<'a, A: Application>( user_interface } -fn to_physical(size: winit::dpi::LogicalSize, dpi: f64) -> (u16, u16) { - let physical_size = size.to_physical(dpi); +fn to_physical(size: winit::dpi::LogicalSize, dpi: f64) -> (u32, u32) { + let physical_size = size.to_physical::(dpi); ( - physical_size.width.round() as u16, - physical_size.height.round() as u16, + physical_size.width.round() as u32, + physical_size.height.round() as u32, ) } -- cgit From 1d71f78f906dc74aa3d724dd09cb6c6225686d76 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jan 2020 03:58:33 +0100 Subject: Keep `is_private_use_character` filter for now --- winit/src/application.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 31561689..045d5872 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -484,7 +484,6 @@ fn to_physical(size: winit::dpi::LogicalSize, dpi: f64) -> (u32, u32) { } // As defined in: http://www.unicode.org/faq/private_use.html -// TODO: Remove once https://github.com/rust-windowing/winit/pull/1254 lands fn is_private_use_character(c: char) -> bool { match c { '\u{E000}'..='\u{F8FF}' -- cgit From fbc9deb424b0bfbc1ae7c7ee89ba08fecd049b2a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jan 2020 04:22:27 +0100 Subject: Implement an opaque `Size` type It immutably ties physical and logical sizes to a specific scale factor. --- winit/src/application.rs | 55 ++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 045d5872..853cbb5e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -158,21 +158,20 @@ pub trait Application: Sized { window_builder.build(&event_loop).expect("Open window") }; - let mut scale_factor = window.scale_factor(); - let mut size = window.inner_size().to_logical::(scale_factor); + let mut size = Size::new(window.inner_size(), window.scale_factor()); let mut resized = false; let clipboard = Clipboard::new(&window); let mut renderer = Self::Renderer::new(renderer_settings); let mut target = { - let (width, height) = to_physical(size, scale_factor); + let physical_size = size.physical(); ::Target::new( &window, - width, - height, - scale_factor as f32, + physical_size.width, + physical_size.height, + size.scale_factor() as f32, &renderer, ) }; @@ -181,7 +180,7 @@ pub trait Application: Sized { &mut application, Cache::default(), &mut renderer, - size, + size.logical(), &mut debug, ); @@ -213,7 +212,7 @@ pub trait Application: Sized { &mut application, cache.take().unwrap(), &mut renderer, - size, + size.logical(), &mut debug, ); @@ -285,7 +284,7 @@ pub trait Application: Sized { &mut application, temp_cache, &mut renderer, - size, + size.logical(), &mut debug, ); @@ -305,12 +304,12 @@ pub trait Application: Sized { debug.render_started(); if resized { - let (width, height) = to_physical(size, scale_factor); + let physical_size = size.physical(); target.resize( - width, - height, - scale_factor as f32, + physical_size.width, + physical_size.height, + size.scale_factor() as f32, &renderer, ); @@ -338,11 +337,11 @@ pub trait Application: Sized { .. } => match window_event { WindowEvent::Resized(new_size) => { - size = new_size.to_logical(scale_factor); + size = Size::new(new_size, size.scale_factor()); events.push(Event::Window(window::Event::Resized { - width: size.width.round() as u32, - height: size.height.round() as u32, + width: size.logical().width.round() as u32, + height: size.logical().height.round() as u32, })); resized = true; @@ -351,7 +350,8 @@ pub trait Application: Sized { *control_flow = ControlFlow::Exit; } WindowEvent::CursorMoved { position, .. } => { - let position = position.to_logical::(scale_factor); + let position = + position.to_logical::(size.scale_factor()); events.push(Event::Mouse(mouse::Event::CursorMoved { x: position.x as f32, @@ -430,11 +430,8 @@ pub trait Application: Sized { WindowEvent::HoveredFileCancelled => { events.push(Event::Window(window::Event::FilesHoveredLeft)); } - WindowEvent::ScaleFactorChanged { - scale_factor: new_scale_factor, - .. - } => { - scale_factor = new_scale_factor; + WindowEvent::ScaleFactorChanged { scale_factor, .. } => { + size = Size::new(size.physical(), scale_factor); } _ => {} }, @@ -465,7 +462,10 @@ fn build_user_interface<'a, A: Application>( debug.layout_started(); let user_interface = UserInterface::build( view, - Size::new(size.width.round() as f32, size.height.round() as f32), + iced_native::Size::new( + size.width.round() as f32, + size.height.round() as f32, + ), cache, renderer, ); @@ -474,15 +474,6 @@ fn build_user_interface<'a, A: Application>( user_interface } -fn to_physical(size: winit::dpi::LogicalSize, dpi: f64) -> (u32, u32) { - let physical_size = size.to_physical::(dpi); - - ( - physical_size.width.round() as u32, - physical_size.height.round() as u32, - ) -} - // As defined in: http://www.unicode.org/faq/private_use.html fn is_private_use_character(c: char) -> bool { match c { -- cgit From 7d9378752ab3a0676c62ab269be9bf64e371a17d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 9 Jan 2020 04:54:32 +0100 Subject: Increase precision of `scale_factor` in `Windowed` --- winit/src/application.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'winit/src/application.rs') diff --git a/winit/src/application.rs b/winit/src/application.rs index 853cbb5e..3c0332ed 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -171,7 +171,7 @@ pub trait Application: Sized { &window, physical_size.width, physical_size.height, - size.scale_factor() as f32, + size.scale_factor(), &renderer, ) }; @@ -309,7 +309,7 @@ pub trait Application: Sized { target.resize( physical_size.width, physical_size.height, - size.scale_factor() as f32, + size.scale_factor(), &renderer, ); -- cgit