Skip to content

Commit 0f54f68

Browse files
committed
chore: formatting and minor fixes
1 parent b6ccc8c commit 0f54f68

File tree

2 files changed

+44
-47
lines changed

2 files changed

+44
-47
lines changed

src/app.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
use wgpu::InstanceFlags;
2-
use winit::keyboard::PhysicalKey::Code;
3-
use winit::{
4-
event::*,
5-
event_loop::{ControlFlow, EventLoop},
6-
keyboard::KeyCode,
7-
window::{Window, WindowBuilder},
8-
};
9-
101
use crate::{heat_equation::HeatEquation, renderer::Renderer};
2+
use winit::window::Window;
113

124
pub struct App {
135
surface: wgpu::Surface,

src/main.rs

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use heat_wgpu::app::App;
2-
use winit::{event_loop::EventLoop, window::WindowBuilder, event::{Event, WindowEvent}, keyboard::{KeyCode, PhysicalKey::Code}};
3-
4-
2+
use winit::{
3+
event::{Event, WindowEvent},
4+
event_loop::EventLoop,
5+
keyboard::{KeyCode, PhysicalKey::Code},
6+
window::WindowBuilder,
7+
};
58

69
fn main() {
710
env_logger::init();
@@ -11,45 +14,47 @@ fn main() {
1114
.expect("Window builder creation failed");
1215
let mut app = pollster::block_on(App::new(&window));
1316

14-
event_loop.run(move |event, event_loop_window_target| {
15-
match event {
16-
Event::WindowEvent {
17-
ref event,
18-
window_id,
19-
} if window_id == window.id() => {
20-
match &event {
21-
WindowEvent::Resized(physical_size) => app.resize(*physical_size),
22-
WindowEvent::ScaleFactorChanged { .. } => {
23-
app.resize(window.inner_size());
24-
}
25-
WindowEvent::CloseRequested => event_loop_window_target.exit(),
26-
WindowEvent::KeyboardInput { event, .. } => {
27-
if event.state.is_pressed()
28-
&& matches!(event.physical_key, Code(KeyCode::Escape))
29-
{
30-
event_loop_window_target.exit();
17+
event_loop
18+
.run(move |event, event_loop_window_target| {
19+
match event {
20+
Event::WindowEvent {
21+
ref event,
22+
window_id,
23+
} if window_id == window.id() => {
24+
match &event {
25+
WindowEvent::Resized(physical_size) => app.resize(*physical_size),
26+
WindowEvent::ScaleFactorChanged { .. } => {
27+
app.resize(window.inner_size());
3128
}
32-
}
33-
WindowEvent::RedrawRequested => {
34-
app.update();
29+
WindowEvent::CloseRequested => event_loop_window_target.exit(),
30+
WindowEvent::KeyboardInput { event, .. } => {
31+
if event.state.is_pressed()
32+
&& matches!(event.physical_key, Code(KeyCode::Escape))
33+
{
34+
event_loop_window_target.exit();
35+
}
36+
}
37+
WindowEvent::RedrawRequested => {
38+
app.update();
3539

36-
match app.render(&window) {
37-
Ok(_) => {}
38-
// Recreate the swap_chain if lost
39-
Err(wgpu::SurfaceError::Lost) => app.reacquire_size(),
40-
// The system is out of memory, we should probably quit
41-
Err(wgpu::SurfaceError::OutOfMemory) => event_loop_window_target.exit(),
42-
// All other errors (Outdated, Timeout) should be resolved by the next frame
43-
Err(e) => eprintln!("Unhandled error: {:?}", e),
40+
match app.render(&window) {
41+
Ok(_) => {}
42+
// Recreate the swap_chain if lost
43+
Err(wgpu::SurfaceError::Lost) => app.reacquire_size(),
44+
// The system is out of memory, we should probably quit
45+
Err(wgpu::SurfaceError::OutOfMemory) => {
46+
event_loop_window_target.exit()
47+
}
48+
// All other errors (Outdated, Timeout) should be resolved by the next frame
49+
Err(e) => eprintln!("Unhandled error: {:?}", e),
50+
}
4451
}
52+
_ => {}
4553
}
46-
_ => {}
4754
}
55+
Event::AboutToWait => window.request_redraw(),
56+
_ => {}
4857
}
49-
Event::AboutToWait => {
50-
window.request_redraw()
51-
}
52-
_ => {}
53-
}
54-
}).unwrap();
58+
})
59+
.unwrap();
5560
}

0 commit comments

Comments
 (0)