From 12214b24e84f37782a02f2a60e241a69cfc4db73 Mon Sep 17 00:00:00 2001 From: Swoorup Joshi Date: Sat, 6 Jul 2024 06:24:49 +1000 Subject: [PATCH] Upgrade egui to 0.28 (#290) --- Cargo.toml | 2 +- examples/ui.rs | 2 +- src/systems.rs | 39 ++++++++++++++------------------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f09043688..fb26439d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ required-features = ["render"] [dependencies] bevy = { version = "0.13", default-features = false, features = ["bevy_asset"] } -egui = { version = "0.27", default-features = false, features = ["bytemuck"] } +egui = { version = "0.28", default-features = false, features = ["bytemuck"] } webbrowser = { version = "0.8.2", optional = true } [target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies] diff --git a/examples/ui.rs b/examples/ui.rs index 80844b287..d8c76c5da 100644 --- a/examples/ui.rs +++ b/examples/ui.rs @@ -234,7 +234,7 @@ impl Default for Painting { impl Painting { pub fn ui_control(&mut self, ui: &mut egui::Ui) -> egui::Response { ui.horizontal(|ui| { - egui::stroke_ui(ui, &mut self.stroke, "Stroke"); + ui.add(&mut self.stroke); ui.separator(); if ui.button("Clear Painting").clicked() { self.lines.clear(); diff --git a/src/systems.rs b/src/systems.rs index c98e10819..5ca126230 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -211,32 +211,21 @@ pub fn process_input_system( continue; }; - let mut delta = egui::vec2(event.x, event.y); - if let MouseScrollUnit::Line = event.unit { - // https://github.com/emilk/egui/blob/a689b623a669d54ea85708a8c748eb07e23754b0/egui-winit/src/lib.rs#L449 - delta *= 50.0; - } + let delta = egui::vec2(event.x, event.y); - if ctrl || mac_cmd { - // Treat as zoom instead. - let factor = (delta.y / 200.0).exp(); - window_context - .egui_input - .events - .push(egui::Event::Zoom(factor)); - } else if shift { - // Treat as horizontal scrolling. - // Note: Mac already fires horizontal scroll events when shift is down. - window_context - .egui_input - .events - .push(egui::Event::Scroll(egui::vec2(delta.x + delta.y, 0.0))); - } else { - window_context - .egui_input - .events - .push(egui::Event::Scroll(delta)); - } + let unit = match event.unit { + MouseScrollUnit::Line => egui::MouseWheelUnit::Line, + MouseScrollUnit::Pixel => egui::MouseWheelUnit::Point, + }; + + window_context + .egui_input + .events + .push(egui::Event::MouseWheel { + unit, + delta, + modifiers, + }); } if !command && !win || !*context_params.is_macos && ctrl && alt {