Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always require watcher in fj_window::run #1243

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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