From 49dbf2c14658cb5f2aafdbb75d826d8ba8fedc31 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 9 Jun 2020 15:45:57 +0200 Subject: Request a redraw only on relevant events --- glutin/src/application.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index c777a13b..4f36114c 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -95,6 +95,10 @@ pub fn run( event_loop.run(move |event, _, control_flow| match event { event::Event::MainEventsCleared => { + if state.is_queue_empty() { + return; + } + let command = runtime.enter(|| { state.update( clipboard.as_ref().map(|c| c as _), -- cgit From 4c0286e8acdf0792a9680f6f8212a534a51e3da0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 12 Jun 2020 22:12:15 +0200 Subject: Add `background_color` to `Application` and `Sandbox` --- glutin/src/application.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 4f36114c..63d41573 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -47,6 +47,7 @@ pub fn run( let mut title = application.title(); let mut mode = application.mode(); + let mut background_color = application.background_color(); let context = { let builder = settings.window.into_builder( @@ -138,6 +139,9 @@ pub fn run( mode = new_mode; } + + // Update background color + background_color = program.background_color(); } context.window().request_redraw(); @@ -164,6 +168,7 @@ pub fn run( let new_mouse_interaction = compositor.draw( &mut renderer, &viewport, + background_color, state.primitive(), &debug.overlay(), ); -- cgit From c9696ca687446d78de374a828183de0a5e4bace3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 19 Jun 2020 19:17:05 +0200 Subject: Add `scale_factor` to `Application` and `Sandbox` --- glutin/src/application.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 63d41573..bcdd9e33 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -48,6 +48,7 @@ pub fn run( let mut title = application.title(); let mut mode = application.mode(); let mut background_color = application.background_color(); + let mut scale_factor = application.scale_factor(); let context = { let builder = settings.window.into_builder( @@ -75,7 +76,7 @@ pub fn run( let physical_size = context.window().inner_size(); let mut viewport = Viewport::with_physical_size( Size::new(physical_size.width, physical_size.height), - context.window().scale_factor(), + context.window().scale_factor() * scale_factor, ); let mut resized = false; @@ -142,6 +143,20 @@ pub fn run( // Update background color background_color = program.background_color(); + + // Update scale factor + let new_scale_factor = program.scale_factor(); + + if scale_factor != new_scale_factor { + let size = context.window().inner_size(); + + viewport = Viewport::with_physical_size( + Size::new(size.width, size.height), + context.window().scale_factor() * new_scale_factor, + ); + + scale_factor = new_scale_factor; + } } context.window().request_redraw(); @@ -195,6 +210,7 @@ pub fn run( application::handle_window_event( &window_event, context.window(), + scale_factor, control_flow, &mut modifiers, &mut viewport, -- cgit From bbdf558bd7eb3abbf69c922b34075360cd5f12c5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Jun 2020 06:12:06 +0200 Subject: Relayout when `Application::scale_factor` changes --- glutin/src/application.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index bcdd9e33..93877734 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -155,6 +155,19 @@ pub fn run( context.window().scale_factor() * new_scale_factor, ); + // We relayout the UI with the new logical size. + // The queue is empty, therefore this will never produce + // a `Command`. + // + // TODO: Properly queue `WindowResized` and `CursorMoved` + // events. + let _ = state.update( + clipboard.as_ref().map(|c| c as _), + viewport.logical_size(), + &mut renderer, + &mut debug, + ); + scale_factor = new_scale_factor; } } -- cgit From f30a666dc81fdc85d225dc83f1a33e32d5dccbd2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Jun 2020 06:44:34 +0200 Subject: Decouple `cursor_position` from `Cache` Instead, we ask explicitly for it in the different `update` and `draw` methods. This way, the runtime can derive the logical position of the cursor from the source of truth. --- glutin/src/application.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'glutin/src') diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 93877734..3be9b65f 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -70,6 +70,7 @@ pub fn run( }; let clipboard = Clipboard::new(&context.window()); + let mut cursor_position = glutin::dpi::PhysicalPosition::new(-1.0, -1.0); let mut mouse_interaction = mouse::Interaction::default(); let mut modifiers = glutin::event::ModifiersState::default(); @@ -90,6 +91,7 @@ pub fn run( let mut state = program::State::new( application, viewport.logical_size(), + conversion::cursor_position(cursor_position, viewport.scale_factor()), &mut renderer, &mut debug, ); @@ -103,8 +105,12 @@ pub fn run( let command = runtime.enter(|| { state.update( - clipboard.as_ref().map(|c| c as _), viewport.logical_size(), + conversion::cursor_position( + cursor_position, + viewport.scale_factor(), + ), + clipboard.as_ref().map(|c| c as _), &mut renderer, &mut debug, ) @@ -159,11 +165,14 @@ pub fn run( // The queue is empty, therefore this will never produce // a `Command`. // - // TODO: Properly queue `WindowResized` and `CursorMoved` - // events. + // TODO: Properly queue `WindowResized` let _ = state.update( - clipboard.as_ref().map(|c| c as _), viewport.logical_size(), + conversion::cursor_position( + cursor_position, + viewport.scale_factor(), + ), + clipboard.as_ref().map(|c| c as _), &mut renderer, &mut debug, ); @@ -225,6 +234,7 @@ pub fn run( context.window(), scale_factor, control_flow, + &mut cursor_position, &mut modifiers, &mut viewport, &mut resized, -- cgit