From f73e9d732602be68c3bdfce33389fe50b5ba69a7 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 12 Mar 2024 21:26:14 -0700 Subject: [PATCH] Update winit-0.29 and egui-0.26 --- Cargo.toml | 14 +- examples/bunnymark/main.rs | 94 ++++----- examples/particle/main.rs | 150 +++++++------- examples/ray-query/main.rs | 67 ++++--- examples/scene/main.rs | 402 +++++++++++++++++++------------------ 5 files changed, 370 insertions(+), 357 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7fc5cb10..3757bbc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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 } diff --git a/examples/bunnymark/main.rs b/examples/bunnymark/main.rs index 4f9e77a0..1a66022d 100644 --- a/examples/bunnymark/main.rs +++ b/examples/bunnymark/main.rs @@ -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) @@ -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(); } diff --git a/examples/particle/main.rs b/examples/particle/main.rs index 242a2ae3..45e95beb 100644 --- a/examples/particle/main.rs +++ b/examples/particle/main.rs @@ -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(); } diff --git a/examples/ray-query/main.rs b/examples/ray-query/main.rs index 4e7eabef..b99f22f2 100644 --- a/examples/ray-query/main.rs +++ b/examples/ray-query/main.rs @@ -323,48 +323,49 @@ 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-ray-query") .build(&event_loop) .unwrap(); - let mut example = Some(Example::new(&window)); + 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, .. } => 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; + 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 { + 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::RedrawRequested => { + target.set_control_flow(winit::event_loop::ControlFlow::Wait); + example.render(); + } + winit::event::WindowEvent::CloseRequested => { + target.exit(); } _ => {} }, - winit::event::WindowEvent::CloseRequested => { - *control_flow = winit::event_loop::ControlFlow::Exit; - } _ => {} - }, - winit::event::Event::RedrawRequested(_) => { - *control_flow = winit::event_loop::ControlFlow::Wait; - example.as_mut().unwrap().render(); - } - winit::event::Event::LoopDestroyed => { - example.take().unwrap().delete(); } - _ => {} - } - }) + }) + .unwrap(); + + example.delete(); } diff --git a/examples/scene/main.rs b/examples/scene/main.rs index 734a0dc1..5123f4b0 100644 --- a/examples/scene/main.rs +++ b/examples/scene/main.rs @@ -545,9 +545,9 @@ impl Example { .snapping(true); if let Some(response) = gizmo.interact(ui) { let t1 = TransformComponents { - scale: response.scale, - rotation: response.rotation, - translation: response.translation, + scale: response.scale.into(), + rotation: response.rotation.into(), + translation: response.translation.into(), } .to_blade(); if object.transform != t1 { @@ -1023,16 +1023,16 @@ impl Example { fn main() { env_logger::init(); - //let _ = profiling::tracy_client::Client::start(); - 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-scene") .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 args = std::env::args(); let path_to_scene = args @@ -1050,216 +1050,222 @@ fn main() { let mut last_event = time::Instant::now(); let mut last_mouse_pos = [0i32; 2]; - event_loop.run(move |event, _, control_flow| { - example.choir.check_panic(); - *control_flow = winit::event_loop::ControlFlow::Poll; - let delta = last_event.elapsed().as_secs_f32(); - last_event = time::Instant::now(); - let move_speed = example.fly_speed * delta; - let rotate_speed = 0.01f32; - let rotate_speed_z = 1000.0 * delta; - - 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| { + example.choir.check_panic(); + target.set_control_flow(winit::event_loop::ControlFlow::Poll); + + let delta = last_event.elapsed().as_secs_f32(); + last_event = time::Instant::now(); + let move_speed = example.fly_speed * delta; + let rotate_speed = 0.01f32; + let rotate_speed_z = 1000.0 * delta; + + 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.repaint { + window.request_redraw(); + } + if response.consumed { + return; + } - 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::keyboard::KeyCode::KeyW => { + example.move_camera_by(glam::Vec3::new(0.0, 0.0, -move_speed)); + } + winit::keyboard::KeyCode::KeyS => { + example.move_camera_by(glam::Vec3::new(0.0, 0.0, move_speed)); + } + winit::keyboard::KeyCode::KeyA => { + example.move_camera_by(glam::Vec3::new(-move_speed, 0.0, 0.0)); + } + winit::keyboard::KeyCode::KeyD => { + example.move_camera_by(glam::Vec3::new(move_speed, 0.0, 0.0)); + } + winit::keyboard::KeyCode::KeyZ => { + example.move_camera_by(glam::Vec3::new(0.0, -move_speed, 0.0)); + } + winit::keyboard::KeyCode::KeyX => { + example.move_camera_by(glam::Vec3::new(0.0, move_speed, 0.0)); + } + winit::keyboard::KeyCode::KeyQ => { + let rot = example.rotate_camera_z_by(rotate_speed_z); + if let Some(ref mut drag) = drag_start { + drag.rotation *= rot; + } + } + winit::keyboard::KeyCode::KeyE => { + let rot = example.rotate_camera_z_by(-rotate_speed_z); + if let Some(ref mut drag) = drag_start { + drag.rotation *= rot; + } + } + _ => {} + }, + winit::event::WindowEvent::CloseRequested => { + target.exit(); } - winit::event::VirtualKeyCode::W => { - example.move_camera_by(glam::Vec3::new(0.0, 0.0, -move_speed)); + winit::event::WindowEvent::MouseInput { + state, + button: winit::event::MouseButton::Left, + .. + } => { + drag_start = match state { + winit::event::ElementState::Pressed => Some(Drag { + _screen_pos: last_mouse_pos.into(), + rotation: example.camera.rot.into(), + }), + winit::event::ElementState::Released => None, + }; } - winit::event::VirtualKeyCode::S => { - example.move_camera_by(glam::Vec3::new(0.0, 0.0, move_speed)); + winit::event::WindowEvent::MouseInput { + state: winit::event::ElementState::Pressed, + button: winit::event::MouseButton::Right, + .. + } => { + example.is_point_selected = true; + example.need_picked_selection_frames = 3; } - winit::event::VirtualKeyCode::A => { - example.move_camera_by(glam::Vec3::new(-move_speed, 0.0, 0.0)); + winit::event::WindowEvent::MouseInput { + state: winit::event::ElementState::Released, + button: winit::event::MouseButton::Right, + .. + } => { + example.is_point_selected = false; } - winit::event::VirtualKeyCode::D => { - example.move_camera_by(glam::Vec3::new(move_speed, 0.0, 0.0)); + winit::event::WindowEvent::CursorMoved { position, .. } => { + if let Some(_) = drag_start { + let prev = glam::Quat::from(example.camera.rot); + let rotation = glam::Quat::from_euler( + glam::EulerRot::ZYX, + 0.0, + (last_mouse_pos[0] as f32 - position.x as f32) * rotate_speed, + (last_mouse_pos[1] as f32 - position.y as f32) * rotate_speed, + ); + example.camera.rot = (prev * rotation).into(); + example.debug.mouse_pos = None; + } + last_mouse_pos = [position.x as i32, position.y as i32]; } - winit::event::VirtualKeyCode::Z => { - example.move_camera_by(glam::Vec3::new(0.0, -move_speed, 0.0)); + winit::event::WindowEvent::HoveredFile(_) => { + example.is_file_hovered = true; + example + .debug + .draw_flags + .set(blade_render::DebugDrawFlags::SPACE, true); } - winit::event::VirtualKeyCode::X => { - example.move_camera_by(glam::Vec3::new(0.0, move_speed, 0.0)); + winit::event::WindowEvent::HoveredFileCancelled => { + example.is_file_hovered = false; + example + .debug + .draw_flags + .set(blade_render::DebugDrawFlags::SPACE, false); } - winit::event::VirtualKeyCode::Q => { - let rot = example.rotate_camera_z_by(rotate_speed_z); - if let Some(ref mut drag) = drag_start { - drag.rotation *= rot; + winit::event::WindowEvent::DroppedFile(ref file_path) => { + example.is_file_hovered = false; + example + .debug + .draw_flags + .set(blade_render::DebugDrawFlags::SPACE, false); + if !example.add_object(file_path) { + log::warn!( + "Unable to drop {}, loading in progress", + file_path.display() + ); } } - winit::event::VirtualKeyCode::E => { - let rot = example.rotate_camera_z_by(-rotate_speed_z); - if let Some(ref mut drag) = drag_start { - drag.rotation *= rot; + 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| { + let frame = { + let mut frame = egui::Frame::side_top_panel(&egui_ctx.style()); + let mut fill = frame.fill.to_array(); + for f in fill.iter_mut() { + *f = (*f as u32 * 7 / 8) as u8; + } + frame.fill = egui::Color32::from_rgba_premultiplied( + fill[0], fill[1], fill[2], fill[3], + ); + frame + }; + egui::SidePanel::right("view") + .frame(frame) + .show(egui_ctx, |ui| { + example.populate_view(ui); + }); + egui::SidePanel::left("content").frame(frame).show( + egui_ctx, + |ui| { + example.populate_content(ui); + ui.separator(); + if ui.button("Quit").clicked() { + target.exit(); + } + }, + ); + }); + + //HACK: https://github.com/urholaukkarinen/egui-gizmo/issues/29 + if example.have_objects_changed + && egui_winit.egui_ctx().wants_pointer_input() + { + drag_start = None; } - } - _ => {} - }, - winit::event::WindowEvent::CloseRequested => { - *control_flow = winit::event_loop::ControlFlow::Exit; - } - winit::event::WindowEvent::MouseInput { - state, - button: winit::event::MouseButton::Left, - .. - } => { - drag_start = match state { - winit::event::ElementState::Pressed => Some(Drag { - _screen_pos: last_mouse_pos.into(), - rotation: example.camera.rot.into(), - }), - winit::event::ElementState::Released => None, - }; - } - winit::event::WindowEvent::MouseInput { - state: winit::event::ElementState::Pressed, - button: winit::event::MouseButton::Right, - .. - } => { - example.is_point_selected = true; - example.need_picked_selection_frames = 3; - } - winit::event::WindowEvent::MouseInput { - state: winit::event::ElementState::Released, - button: winit::event::MouseButton::Right, - .. - } => { - example.is_point_selected = false; - } - winit::event::WindowEvent::CursorMoved { position, .. } => { - if let Some(_) = drag_start { - let prev = glam::Quat::from(example.camera.rot); - let rotation = glam::Quat::from_euler( - glam::EulerRot::ZYX, - 0.0, - (last_mouse_pos[0] as f32 - position.x as f32) * rotate_speed, - (last_mouse_pos[1] as f32 - position.y as f32) * rotate_speed, - ); - example.camera.rot = (prev * rotation).into(); - example.debug.mouse_pos = None; - } - last_mouse_pos = [position.x as i32, position.y as i32]; - } - winit::event::WindowEvent::HoveredFile(_) => { - example.is_file_hovered = true; - example - .debug - .draw_flags - .set(blade_render::DebugDrawFlags::SPACE, true); - } - winit::event::WindowEvent::HoveredFileCancelled => { - example.is_file_hovered = false; - example - .debug - .draw_flags - .set(blade_render::DebugDrawFlags::SPACE, false); - } - winit::event::WindowEvent::DroppedFile(ref file_path) => { - example.is_file_hovered = false; - example - .debug - .draw_flags - .set(blade_render::DebugDrawFlags::SPACE, false); - if !example.add_object(file_path) { - log::warn!( - "Unable to drop {}, loading in progress", - file_path.display() + + egui_winit.handle_platform_output(&window, egui_output.platform_output); + let repaint_delay = + egui_output.viewport_output[&viewport_id].repaint_delay; + let primitives = egui_winit + .egui_ctx() + .tessellate(egui_output.shapes, egui_output.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); + + example.render( + &primitives, + &egui_output.textures_delta, + window.inner_size(), + window.scale_factor() as f32, ); + profiling::finish_frame!(); } + _ => {} } - _ => {} - } - if example.is_point_selected || example.is_file_hovered { - //TODO: unfortunately winit doesn't update cursor position during a drag - // https://github.com/rust-windowing/winit/issues/1550 - example.debug.mouse_pos = Some(last_mouse_pos); + if example.is_point_selected || example.is_file_hovered { + //TODO: unfortunately winit doesn't update cursor position during a drag + // https://github.com/rust-windowing/winit/issues/1550 + example.debug.mouse_pos = Some(last_mouse_pos); + } } + _ => {} } - 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| { - let frame = { - let mut frame = egui::Frame::side_top_panel(&egui_ctx.style()); - let mut fill = frame.fill.to_array(); - for f in fill.iter_mut() { - *f = (*f as u32 * 7 / 8) as u8; - } - frame.fill = egui::Color32::from_rgba_premultiplied( - fill[0], fill[1], fill[2], fill[3], - ); - frame - }; - egui::SidePanel::right("view") - .frame(frame) - .show(egui_ctx, |ui| { - example.populate_view(ui); - }); - egui::SidePanel::left("content") - .frame(frame) - .show(egui_ctx, |ui| { - example.populate_content(ui); - ui.separator(); - if ui.button("Quit").clicked() { - quit = true; - } - }); - }); - - //HACK: https://github.com/urholaukkarinen/egui-gizmo/issues/29 - if example.have_objects_changed && egui_ctx.wants_pointer_input() { - drag_start = None; - } - - 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 - }; + }) + .unwrap(); - example.render( - &primitives, - &egui_output.textures_delta, - window.inner_size(), - egui_ctx.pixels_per_point(), - ); - profiling::finish_frame!(); - } - winit::event::Event::LoopDestroyed => { - example.destroy(); - } - _ => {} - } - }) + example.destroy(); }