Skip to content

Commit

Permalink
Update winit & other libs
Browse files Browse the repository at this point in the history
  • Loading branch information
hakolao committed Jan 11, 2024
1 parent 8d6740d commit 0167617
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 112 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ trace = ["wgpu/trace"]

[dependencies]
indexmap = "2.1"
pollster = "0.3.0"
pollster = "0.3"
image = "0.24"
bytemuck = { version = "1.13.1", features = ["derive"] }
bytemuck = { version = "1.14", features = ["derive"] }
wgpu = { version = "0.18", default_features = true, features = ["naga"] }
naga = "0.14"
winit = "0.28"
glam = "0.24.0"
winit = { version = "0.29", features = ["rwh_05"] }
glam = "0.25"
path-clean = "1.0.1"
notify = "6.1"
flume = "0.11"
log = "0.4"

# Optional Egui
egui = { version = "0.24", optional = true }
egui-wgpu = { version = "0.24", optional = true }
egui-winit = { version = "0.24", optional = true }
egui_extras = { version = "0.24", optional = true }
egui_demo_lib = { version = "0.24", optional = true }
egui = { version = "0.25", optional = true }
egui-wgpu = { version = "0.25", optional = true }
egui-winit = { version = "0.25", optional = true }
egui_extras = { version = "0.25", optional = true }
egui_demo_lib = { version = "0.25", optional = true }

[dev-dependencies]
egui_demo_lib = { version = "0.24" }
winit_input_helper = "0.14"
egui_demo_lib = { version = "0.25" }
winit_input_helper = "0.15"
rapier2d = { version = "0.17.2", features = ["default", "debug-render"] }

[profile.dev]
Expand Down
28 changes: 17 additions & 11 deletions examples/egui_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ fn initialize_gui_app(
context: &mut GlassContext,
event_loop: &EventLoopWindowTarget<()>,
) {
let ctx = egui::Context::default();
let pixels_per_point = context.primary_render_window().window().scale_factor() as f32;
let egui_winit = egui_winit::State::new(
ctx.clone(),
ViewportId::ROOT,
event_loop,
Some(pixels_per_point),
Expand All @@ -72,28 +74,32 @@ fn initialize_gui_app(
1,
);
app.gui = Some(GuiState {
egui_ctx: egui::Context::default(),
egui_ctx: ctx,
egui_winit,
renderer,
repaint: false,
ui_app: egui_demo_lib::DemoWindows::default(),
});
}

fn update_egui_with_winit_event(app: &mut GuiApp, _context: &mut GlassContext, event: &Event<()>) {
fn update_egui_with_winit_event(app: &mut GuiApp, context: &mut GlassContext, event: &Event<()>) {
match event {
Event::WindowEvent {
event, ..
window_id,
event,
..
} => {
let gui = app.gui();
let EventResponse {
consumed,
repaint,
} = gui.egui_winit.on_window_event(&gui.egui_ctx, event);
gui.repaint = repaint;
// Skip input if event was consumed by egui
if consumed {
return;
if let Some(window) = context.render_window(*window_id) {
let EventResponse {
consumed,
repaint,
} = gui.egui_winit.on_window_event(window.window(), event);
gui.repaint = repaint;
// Skip input if event was consumed by egui
if consumed {
return;
}
}
}
_ => {}
Expand Down
19 changes: 10 additions & 9 deletions examples/fluid_sim/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use glass::{
wgpu::{BlendState, ColorTargetState, ColorWrites, Extent3d, TextureFormat, TextureUsages},
window::GlassWindow,
winit::{
event::{Event, VirtualKeyCode},
event::Event,
event_loop::{EventLoop, EventLoopWindowTarget},
},
GlassApp, GlassContext, RenderData,
};
use wgpu::StoreOp;
use winit::keyboard::KeyCode;
use winit_input_helper::WinitInputHelper;

use crate::{
Expand Down Expand Up @@ -77,7 +78,7 @@ impl GlassApp for FluidSimApp {
&mut self,
_context: &mut GlassContext,
_event_loop: &EventLoopWindowTarget<()>,
event: &Event<'_, ()>,
event: &Event<()>,
) {
self.input.update(event);
}
Expand All @@ -87,7 +88,7 @@ impl GlassApp for FluidSimApp {
.primary_render_window()
.window()
.set_title(&format!("FPS: {:.3}", self.timer.avg_fps()));
let scroll_diff = self.input.scroll_diff();
let (_, scroll_diff) = self.input.scroll_diff();
if scroll_diff > 0.0 {
self.camera.set_scale(self.camera.scale() / 1.05);
} else if scroll_diff < 0.0 {
Expand All @@ -97,22 +98,22 @@ impl GlassApp for FluidSimApp {
self.resize(context);
}
// Read inputs state
if self.input.key_pressed(VirtualKeyCode::Space) {
if self.input.key_pressed(KeyCode::Space) {
self.fluid_scene.toggle_pause();
}
if self.input.key_pressed(VirtualKeyCode::R) {
if self.input.key_pressed(KeyCode::KeyR) {
self.fluid_scene.reset();
}
if self.input.key_pressed(VirtualKeyCode::G) {
if self.input.key_pressed(KeyCode::KeyG) {
self.fluid_scene.toggle_grid();
}
if self.input.key_pressed(VirtualKeyCode::P) {
if self.input.key_pressed(KeyCode::KeyP) {
self.fluid_scene.toggle_particles();
}
if self.input.key_pressed(VirtualKeyCode::F) {
if self.input.key_pressed(KeyCode::KeyF) {
self.fluid_scene.toggle_gravity();
}
if let Some((x, y)) = self.input.mouse() {
if let Some((x, y)) = self.input.cursor() {
let screen_size = context.primary_render_window().surface_size();
let scale_factor = context.primary_render_window().window().scale_factor() as f32;
let pos = cursor_to_world(
Expand Down
2 changes: 2 additions & 0 deletions examples/fluid_sim/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl Timer {
self.time.elapsed().as_nanos() as f64 * 1.0e-6
}

#[allow(unused)]
pub fn time_since_last_update_sec(&self) -> f64 {
self.end() / 1000.0
}
Expand Down Expand Up @@ -60,6 +61,7 @@ impl Timer {
self.delta
}

#[allow(unused)]
pub fn dt_sec(&self) -> f64 {
self.delta / 1000.0
}
Expand Down
33 changes: 17 additions & 16 deletions examples/multiple_windows/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use glass::{
};
use wgpu::{Color, StoreOp};
use winit::{
event::{DeviceEvent, ElementState, Event, VirtualKeyCode},
event::{DeviceEvent, ElementState, Event},
event_loop::{EventLoop, EventLoopWindowTarget},
keyboard::{KeyCode, PhysicalKey},
window::WindowId,
};

Expand Down Expand Up @@ -55,21 +56,21 @@ impl GlassApp for MultiWindowApp {
..
} = event
{
if let Some(key) = input.virtual_keycode {
if key == VirtualKeyCode::Space && input.state == ElementState::Pressed {
// Create window
self.window_ids.push(
context
.create_window(event_loop, WindowConfig {
width: WIDTH,
height: HEIGHT,
exit_on_esc: true,
..WindowConfig::default()
})
.unwrap(),
);
println!("Window ids: {:#?}", self.window_ids);
}
if input.physical_key == PhysicalKey::Code(KeyCode::Space)
&& input.state == ElementState::Pressed
{
// Create window
self.window_ids.push(
context
.create_window(event_loop, WindowConfig {
width: WIDTH,
height: HEIGHT,
exit_on_esc: true,
..WindowConfig::default()
})
.unwrap(),
);
println!("Window ids: {:#?}", self.window_ids);
}
}
}
Expand Down
Loading

0 comments on commit 0167617

Please sign in to comment.