Skip to content

Commit

Permalink
Merge pull request #1243 from hannobraun/window
Browse files Browse the repository at this point in the history
Always require watcher in `fj_window::run`
  • Loading branch information
hannobraun authored Oct 20, 2022
2 parents a7cbec7 + 541150a commit f57cd28
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 47 deletions.
2 changes: 1 addition & 1 deletion crates/fj-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
11 changes: 2 additions & 9 deletions crates/fj-interop/src/status_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
use std::collections::VecDeque;

/// Struct to store and update status messages
#[derive(Default)]
pub struct StatusReport {
status: VecDeque<String>,
}

impl StatusReport {
/// Create a new ``StatusReport`` instance with a blank status
pub fn new() -> Self {
Self {
status: VecDeque::new(),
}
Self::default()
}

/// Update the status
Expand All @@ -39,9 +38,3 @@ impl StatusReport {
self.status.clear();
}
}

impl Default for StatusReport {
fn default() -> Self {
Self::new()
}
}
72 changes: 36 additions & 36 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: Watcher,
shape_processor: ShapeProcessor,
mut status: StatusReport,
invert_zoom: bool,
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -200,8 +200,8 @@ pub fn run(
});
}

fn input_event(
event: &Event<()>,
fn input_event<T>(
event: &Event<T>,
window: &Window,
held_mouse_button: &Option<MouseButton>,
previous_cursor: &mut Option<NormalizedScreenPosition>,
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Error> {
pub fn new<T>(event_loop: &EventLoop<T>) -> Result<Self, Error> {
let window = WindowBuilder::new()
.with_title("Fornjot")
.with_maximized(true)
Expand Down

0 comments on commit f57cd28

Please sign in to comment.