diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 3dca6df06..283efecc7 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -91,7 +91,7 @@ fn main() -> anyhow::Result<()> { let invert_zoom = config.invert_zoom.unwrap_or(false); let watcher = model.load_and_watch(parameters)?; - run(Some(watcher), shape_processor, status, invert_zoom)?; + run(watcher, shape_processor, status, invert_zoom)?; Ok(()) } diff --git a/crates/fj-interop/src/status_report.rs b/crates/fj-interop/src/status_report.rs index 23f74b802..f5c645da2 100644 --- a/crates/fj-interop/src/status_report.rs +++ b/crates/fj-interop/src/status_report.rs @@ -3,6 +3,7 @@ use std::collections::VecDeque; /// Struct to store and update status messages +#[derive(Default)] pub struct StatusReport { status: VecDeque, } @@ -10,9 +11,7 @@ pub struct StatusReport { impl StatusReport { /// Create a new ``StatusReport`` instance with a blank status pub fn new() -> Self { - Self { - status: VecDeque::new(), - } + Self::default() } /// Update the status @@ -39,9 +38,3 @@ impl StatusReport { self.status.clear(); } } - -impl Default for StatusReport { - fn default() -> Self { - Self::new() - } -} diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 31194880f..000fc9b67 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -27,7 +27,7 @@ use crate::window::{self, Window}; /// Initializes a model viewer for a given model and enters its process loop. pub fn run( - watcher: Option, + watcher: Watcher, shape_processor: ShapeProcessor, mut status: StatusReport, invert_zoom: bool, @@ -49,50 +49,48 @@ pub fn run( event_loop.run(move |event, _, control_flow| { trace!("Handling event: {:?}", event); - if let Some(watcher) = &watcher { - match watcher.receive_shape(&mut status) { - Ok(shape) => { - if let Some(shape) = shape { - match shape_processor.process(&shape) { - Ok(shape) => { - viewer.handle_shape_update(shape); - } - Err(err) => { - // Can be cleaned up, once `Report` is stable: - // https://doc.rust-lang.org/std/error/struct.Report.html + match watcher.receive_shape(&mut status) { + Ok(shape) => { + if let Some(shape) = shape { + match shape_processor.process(&shape) { + Ok(shape) => { + viewer.handle_shape_update(shape); + } + Err(err) => { + // Can be cleaned up, once `Report` is stable: + // https://doc.rust-lang.org/std/error/struct.Report.html - println!("Shape processing error: {}", err); + println!("Shape processing error: {}", err); - let mut current_err = &err as &dyn error::Error; - while let Some(err) = current_err.source() { - println!(); - println!("Caused by:"); - println!(" {}", err); + let mut current_err = &err as &dyn error::Error; + while let Some(err) = current_err.source() { + println!(); + println!("Caused by:"); + println!(" {}", err); - current_err = err; - } + current_err = err; } } } } - Err(err) => { - // Can be cleaned up, once `Report` is stable: - // https://doc.rust-lang.org/std/error/struct.Report.html + } + Err(err) => { + // Can be cleaned up, once `Report` is stable: + // https://doc.rust-lang.org/std/error/struct.Report.html - println!("Error receiving updated shape: {}", err); + println!("Error receiving updated shape: {}", err); - let mut current_err = &err as &dyn error::Error; - while let Some(err) = current_err.source() { - println!(); - println!("Caused by:"); - println!(" {}", err); + let mut current_err = &err as &dyn error::Error; + while let Some(err) = current_err.source() { + println!(); + println!("Caused by:"); + println!(" {}", err); - current_err = err; - } - - *control_flow = ControlFlow::Exit; - return; + current_err = err; } + + *control_flow = ControlFlow::Exit; + return; } } @@ -171,6 +169,8 @@ pub fn run( window.window().request_redraw(); } Event::RedrawRequested(_) => { + // Only do a screen resize once per frame. This protects against + // spurious resize events that cause issues with the renderer. if let Some(size) = new_size.take() { viewer.handle_screen_resize(size); } @@ -200,8 +200,8 @@ pub fn run( }); } -fn input_event( - event: &Event<()>, +fn input_event( + event: &Event, window: &Window, held_mouse_button: &Option, previous_cursor: &mut Option, diff --git a/crates/fj-window/src/window.rs b/crates/fj-window/src/window.rs index db1c57a84..25d709d39 100644 --- a/crates/fj-window/src/window.rs +++ b/crates/fj-window/src/window.rs @@ -8,7 +8,7 @@ pub struct Window(winit::window::Window); impl Window { /// Returns a new window with the given `EventLoop`. - pub fn new(event_loop: &EventLoop<()>) -> Result { + pub fn new(event_loop: &EventLoop) -> Result { let window = WindowBuilder::new() .with_title("Fornjot") .with_maximized(true)