Skip to content

Commit

Permalink
Update winit-0.29 and egui-0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Mar 15, 2024
1 parent 43721bf commit f73e9d7
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 357 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ base64 = "0.21"
bitflags = "2"
bytemuck = { version = "1", features = ["derive"] }
choir = "0.7"
egui = "0.23"
glam = { version = "0.24", features = ["mint"] }
egui = "0.26"
glam = { version = "0.25", features = ["mint"] }
gltf = { version = "1.1", default-features = false }
log = "0.4"
mint = "0.5"
Expand Down Expand Up @@ -55,20 +55,20 @@ log = { workspace = true }
mint = { workspace = true, features = ["serde"] }
num_cpus = "1"
profiling = { workspace = true }
rapier3d = { version = "0.17", features = ["debug-render"] }
rapier3d = { version = "0.18", features = ["debug-render"] }
serde = { version = "1", features = ["serde_derive"] }
slab = "0.4"
strum = { workspace = true }
winit = "0.28"
winit = { version = "0.29", features = ["rwh_05"] }

[dev-dependencies]
blade-macros = { version = "0.2", path = "blade-macros" }
bytemuck = { workspace = true }
choir = { workspace = true }
egui = { workspace = true }
egui-gizmo = "0.12"
egui_plot = "0.23"
egui-winit = "0.23"
egui-gizmo = "0.16"
egui_plot = "0.26"
egui-winit = "0.26"
env_logger = "0.10"
del-msh = "=0.1.25" # not following semver :(
glam = { workspace = true }
Expand Down
94 changes: 47 additions & 47 deletions examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn main() {
#[cfg(not(target_arch = "wasm32"))]
env_logger::init();

let event_loop = winit::event_loop::EventLoop::new();
let event_loop = winit::event_loop::EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new()
.with_title("blade-bunnymark")
.build(&event_loop)
Expand Down Expand Up @@ -315,56 +315,56 @@ fn main() {
}
let mut frame_count = 0;

event_loop.run(move |event, _, control_flow| {
let _ = &window; // force ownership by the closure
*control_flow = winit::event_loop::ControlFlow::Poll;
match event {
winit::event::Event::RedrawEventsCleared => {
window.request_redraw();
}
winit::event::Event::WindowEvent { event, .. } => match event {
#[cfg(not(target_arch = "wasm32"))]
winit::event::WindowEvent::KeyboardInput {
input:
winit::event::KeyboardInput {
virtual_keycode: Some(key_code),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key_code {
winit::event::VirtualKeyCode::Escape => {
*control_flow = winit::event_loop::ControlFlow::Exit;
event_loop
.run(|event, target| {
target.set_control_flow(winit::event_loop::ControlFlow::Poll);
match event {
winit::event::Event::AboutToWait => {
window.request_redraw();
}
winit::event::Event::WindowEvent { event, .. } => match event {
#[cfg(not(target_arch = "wasm32"))]
winit::event::WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
physical_key: winit::keyboard::PhysicalKey::Code(key_code),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key_code {
winit::keyboard::KeyCode::Escape => {
target.exit();
}
winit::keyboard::KeyCode::Space => {
example.increase();
}
_ => {}
},
winit::event::WindowEvent::CloseRequested => {
target.exit();
}
winit::event::VirtualKeyCode::Space => {
example.increase();
winit::event::WindowEvent::RedrawRequested => {
frame_count += 1;
#[cfg(not(target_arch = "wasm32"))]
if frame_count == 100 {
let accum_time = last_snapshot.elapsed().as_secs_f32();
println!(
"Avg frame time {}ms",
accum_time * 1000.0 / frame_count as f32
);
last_snapshot = std::time::Instant::now();
frame_count = 0;
}
example.step(0.01);
example.render();
}
_ => {}
},
winit::event::WindowEvent::CloseRequested => {
*control_flow = winit::event_loop::ControlFlow::Exit;
}
_ => {}
},
winit::event::Event::RedrawRequested(_) => {
frame_count += 1;
#[cfg(not(target_arch = "wasm32"))]
if frame_count == 100 {
let accum_time = last_snapshot.elapsed().as_secs_f32();
println!(
"Avg frame time {}ms",
accum_time * 1000.0 / frame_count as f32
);
last_snapshot = std::time::Instant::now();
frame_count = 0;
}
example.step(0.01);
example.render();
}
winit::event::Event::LoopDestroyed => {
example.deinit();
}
_ => {}
}
})
})
.unwrap();

example.deinit();
}
150 changes: 78 additions & 72 deletions examples/particle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,93 +115,99 @@ impl Example {
fn main() {
env_logger::init();

let event_loop = winit::event_loop::EventLoop::new();
let event_loop = winit::event_loop::EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new()
.with_title("blade-particle")
.build(&event_loop)
.unwrap();

let egui_ctx = egui::Context::default();
let mut egui_winit = egui_winit::State::new(&event_loop);
let viewport_id = egui_ctx.viewport_id();
let mut egui_winit = egui_winit::State::new(egui_ctx, viewport_id, &window, None, None);

let mut example = Example::new(&window);

event_loop.run(move |event, _, control_flow| {
*control_flow = winit::event_loop::ControlFlow::Poll;
match event {
winit::event::Event::RedrawEventsCleared => {
window.request_redraw();
}
winit::event::Event::WindowEvent { event, .. } => {
let response = egui_winit.on_event(&egui_ctx, &event);
if response.consumed {
return;
}
if response.repaint {
event_loop
.run(|event, target| {
target.set_control_flow(winit::event_loop::ControlFlow::Poll);
match event {
winit::event::Event::AboutToWait => {
window.request_redraw();
}
winit::event::Event::WindowEvent { event, .. } => {
let response = egui_winit.on_window_event(&window, &event);
if response.consumed {
return;
}
if response.repaint {
window.request_redraw();
}

match event {
winit::event::WindowEvent::KeyboardInput {
input:
winit::event::KeyboardInput {
virtual_keycode: Some(key_code),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key_code {
winit::event::VirtualKeyCode::Escape => {
*control_flow = winit::event_loop::ControlFlow::Exit;
match event {
winit::event::WindowEvent::KeyboardInput {
event:
winit::event::KeyEvent {
physical_key: winit::keyboard::PhysicalKey::Code(key_code),
state: winit::event::ElementState::Pressed,
..
},
..
} => match key_code {
winit::keyboard::KeyCode::Escape => {
target.exit();
}
_ => {}
},
winit::event::WindowEvent::CloseRequested => {
target.exit();
}
winit::event::WindowEvent::RedrawRequested => {
let raw_input = egui_winit.take_egui_input(&window);
let egui_output = egui_winit.egui_ctx().run(raw_input, |egui_ctx| {
egui::SidePanel::left("my_side_panel").show(egui_ctx, |ui| {
ui.heading("Particle System");
example.particle_system.add_gui(ui);
if ui.button("Quit").clicked() {
target.exit();
}
});
});

egui_winit.handle_platform_output(&window, egui_output.platform_output);
let repaint_delay =
egui_output.viewport_output[&viewport_id].repaint_delay;

let pixels_per_point =
egui_winit::pixels_per_point(egui_winit.egui_ctx(), &window);
let primitives = egui_winit
.egui_ctx()
.tessellate(egui_output.shapes, pixels_per_point);

let control_flow = if let Some(repaint_after_instant) =
std::time::Instant::now().checked_add(repaint_delay)
{
winit::event_loop::ControlFlow::WaitUntil(repaint_after_instant)
} else {
winit::event_loop::ControlFlow::Wait
};
target.set_control_flow(control_flow);

//Note: this will probably look different with proper support for resizing
let window_size = window.inner_size();
let screen_desc = blade_egui::ScreenDescriptor {
physical_size: (window_size.width, window_size.height),
scale_factor: pixels_per_point,
};

example.render(&primitives, &egui_output.textures_delta, &screen_desc);
}
_ => {}
},
winit::event::WindowEvent::CloseRequested => {
*control_flow = winit::event_loop::ControlFlow::Exit;
}
_ => {}
}
_ => {}
}
winit::event::Event::RedrawRequested(_) => {
let mut quit = false;
let raw_input = egui_winit.take_egui_input(&window);
let egui_output = egui_ctx.run(raw_input, |egui_ctx| {
egui::SidePanel::left("my_side_panel").show(egui_ctx, |ui| {
ui.heading("Particle System");
example.particle_system.add_gui(ui);
if ui.button("Quit").clicked() {
quit = true;
}
});
});

egui_winit.handle_platform_output(&window, &egui_ctx, egui_output.platform_output);

let primitives = egui_ctx.tessellate(egui_output.shapes);

*control_flow = if quit {
winit::event_loop::ControlFlow::Exit
} else if let Some(repaint_after_instant) =
std::time::Instant::now().checked_add(egui_output.repaint_after)
{
winit::event_loop::ControlFlow::WaitUntil(repaint_after_instant)
} else {
winit::event_loop::ControlFlow::Wait
};

//Note: this will probably look different with proper support for resizing
let window_size = window.inner_size();
let screen_desc = blade_egui::ScreenDescriptor {
physical_size: (window_size.width, window_size.height),
scale_factor: egui_ctx.pixels_per_point(),
};

example.render(&primitives, &egui_output.textures_delta, &screen_desc);
}
winit::event::Event::LoopDestroyed => {
example.destroy();
}
_ => {}
}
})
})
.unwrap();

example.destroy();
}
Loading

0 comments on commit f73e9d7

Please sign in to comment.