Refactor to avoid use of deprecated method

This commit is contained in:
Hanno Braun 2024-05-06 14:31:39 +02:00
parent 157e7e92e7
commit 6ada107e28
2 changed files with 10 additions and 10 deletions

View File

@ -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<Model>,
invert_zoom: bool,
window: Window,
window: Option<Window>,
viewer: Option<Viewer>,
held_mouse_button: Option<MouseButton>,
new_size: Option<ScreenSize>,
@ -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();
}
}

View File

@ -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<T>(event_loop: &EventLoop<T>) -> Result<Self, WindowError> {
#[allow(deprecated)] // only for the transition to winit 0.30
pub fn new(event_loop: &ActiveEventLoop) -> Result<Self, WindowError> {
let window = event_loop.create_window(
winit::window::Window::default_attributes()
.with_title("Fornjot")