From 6ada107e2835ae3f0d93fde9072b8199029d471b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 6 May 2024 14:31:39 +0200 Subject: [PATCH] Refactor to avoid use of deprecated method --- crates/fj-window/src/display.rs | 15 ++++++++------- crates/fj-window/src/window.rs | 5 ++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/fj-window/src/display.rs b/crates/fj-window/src/display.rs index 331e3b059..1334a57fb 100644 --- a/crates/fj-window/src/display.rs +++ b/crates/fj-window/src/display.rs @@ -21,12 +21,11 @@ use crate::window::{self, Window}; /// Display the provided mesh in a window that processes input pub fn display(model: Model, invert_zoom: bool) -> Result<(), Error> { let event_loop = EventLoop::new()?; - let window = Window::new(&event_loop)?; let mut display_state = DisplayState { model: Some(model), invert_zoom, - window, + window: None, viewer: None, held_mouse_button: None, new_size: None, @@ -57,7 +56,7 @@ pub enum Error { struct DisplayState { model: Option, invert_zoom: bool, - window: Window, + window: Option, viewer: Option, held_mouse_button: Option, new_size: Option, @@ -65,8 +64,10 @@ struct DisplayState { } impl ApplicationHandler for DisplayState { - fn resumed(&mut self, _: &ActiveEventLoop) { - let window = &self.window; + fn resumed(&mut self, event_loop: &ActiveEventLoop) { + let window = self + .window + .get_or_insert_with(|| Window::new(event_loop).unwrap()); let viewer = self .viewer @@ -83,7 +84,7 @@ impl ApplicationHandler for DisplayState { _: WindowId, event: WindowEvent, ) { - let window = &self.window; + let Some(window) = &self.window else { return }; let Some(viewer) = &mut self.viewer else { return; }; @@ -159,7 +160,7 @@ impl ApplicationHandler for DisplayState { } fn about_to_wait(&mut self, _: &ActiveEventLoop) { - let window = &self.window; + let Some(window) = &self.window else { return }; window.window().request_redraw(); } } diff --git a/crates/fj-window/src/window.rs b/crates/fj-window/src/window.rs index a8580104a..ba7986b4b 100644 --- a/crates/fj-window/src/window.rs +++ b/crates/fj-window/src/window.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use fj_viewer::{Screen, ScreenSize}; -use winit::event_loop::EventLoop; +use winit::event_loop::ActiveEventLoop; /// A window that can be used with `fj-viewer` pub struct Window { @@ -10,8 +10,7 @@ pub struct Window { impl Window { /// Create an instance of `Window` from the given `EventLoop` - pub fn new(event_loop: &EventLoop) -> Result { - #[allow(deprecated)] // only for the transition to winit 0.30 + pub fn new(event_loop: &ActiveEventLoop) -> Result { let window = event_loop.create_window( winit::window::Window::default_attributes() .with_title("Fornjot")