Skip to content

Commit

Permalink
Run render at redraw requested
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Jan 22, 2024
1 parent 469166a commit b1c1f36
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/glass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ impl Glass {
if !event_loop.exiting() {
self.app.input(&mut context, event_loop, &event);
}
let mut end_of_frame = false;
match event {
Event::WindowEvent {
window_id,
event: window_event,
..
} => {
let mut redraw = false;
if let Some(window) = context.windows.get_mut(&window_id) {
match window_event {
WindowEvent::Resized(physical_size) => {
Expand Down Expand Up @@ -104,27 +106,15 @@ impl Glass {
request_window_close = true;
remove_windows.push(window_id);
}
WindowEvent::RedrawRequested => {
redraw = true;
end_of_frame = true;
}
_ => (),
}
}
}
Event::AboutToWait => {
if !event_loop.exiting() {
self.app.update(&mut context);
// Close window(s)
if request_window_close || context.exit {
for window in remove_windows.iter() {
context.windows.remove(window);
}
remove_windows.clear();
request_window_close = false;
// Exit
if context.windows.is_empty() || context.exit {
event_loop.exit();
}
}
// Render
for (_, window) in context.windows.iter() {
if redraw {
if let Some(window) = context.windows.get(&window_id) {
match window.surface().get_current_texture() {
Ok(frame) => {
let mut encoder = context
Expand Down Expand Up @@ -158,10 +148,30 @@ impl Glass {
}
}
}
}
}
}
Event::AboutToWait => {
if !event_loop.exiting() {
self.app.update(&mut context);

// Redraw
for (_, window) in context.windows.iter() {
window.window().request_redraw();
}
// End of frame
self.app.end_of_frame(&mut context);

// Close window(s)
if request_window_close || context.exit {
for window in remove_windows.iter() {
context.windows.remove(window);
}
remove_windows.clear();
request_window_close = false;
// Exit
if context.windows.is_empty() || context.exit {
event_loop.exit();
}
}
}
}
Event::LoopExiting => {
Expand All @@ -170,6 +180,9 @@ impl Glass {
}
_ => {}
}
if end_of_frame {
self.app.end_of_frame(&mut context);
}
}) {
Err(e) => Err(GlassError::EventLoopError(e)),
Ok(a) => Ok(a),
Expand Down

0 comments on commit b1c1f36

Please sign in to comment.