From 5c97ecbeeda250a6fac8f3d0e37ca8bd6dc2a0f0 Mon Sep 17 00:00:00 2001 From: Red Artist Date: Sun, 17 Dec 2023 20:35:44 +0530 Subject: [PATCH] upgraded egui, and release 0.6 --- Cargo.toml | 8 +-- crates/egui_render_glow/Cargo.toml | 2 +- crates/egui_render_three_d/Cargo.toml | 4 +- crates/egui_render_wgpu/Cargo.toml | 2 +- .../egui_window_glfw_passthrough/Cargo.toml | 2 +- .../egui_window_glfw_passthrough/src/lib.rs | 53 ++++++++++++++++++- 6 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dff388f..afbdfbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui_overlay" -version = "0.5.3" +version = "0.6.0" edition = "2021" license = "MIT" description = "Egui integration to easily create Desktop Overlays" @@ -9,18 +9,18 @@ repository = "https://github.com/coderedart/egui_overlay.git" [features] default = ["egui/default"] [dependencies] -egui_window_glfw_passthrough = { version = "0.5", path = "crates/egui_window_glfw_passthrough" } +egui_window_glfw_passthrough = { version = "0.6", path = "crates/egui_window_glfw_passthrough" } egui = { workspace = true } tracing = { workspace = true } raw-window-handle = { workspace = true } [target.'cfg(not(target_os = "macos"))'.dependencies] -egui_render_three_d = { version = "0.5", path = "crates/egui_render_three_d" } +egui_render_three_d = { version = "0.6", path = "crates/egui_render_three_d" } # because opengl doesn't work on mac :(( [target.'cfg(target_os = "macos")'.dependencies] -egui_render_wgpu = { version = "0.5", path = "crates/egui_render_wgpu" } +egui_render_wgpu = { version = "0.6", path = "crates/egui_render_wgpu" } [dev-dependencies] tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/crates/egui_render_glow/Cargo.toml b/crates/egui_render_glow/Cargo.toml index 3f5ff6b..47e498a 100644 --- a/crates/egui_render_glow/Cargo.toml +++ b/crates/egui_render_glow/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui_render_glow" -version = "0.5.2" +version = "0.6.0" edition = "2021" description = "egui rendering backend using glow" license = "MIT" diff --git a/crates/egui_render_three_d/Cargo.toml b/crates/egui_render_three_d/Cargo.toml index 3be41be..2a741be 100644 --- a/crates/egui_render_three_d/Cargo.toml +++ b/crates/egui_render_three_d/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "egui_render_three_d" -version = "0.5.2" +version = "0.6.0" edition = "2021" description = "egui rendering backend using three-d" license = "MIT" [dependencies] -egui_render_glow = { version = "0.5", path = "../egui_render_glow" } +egui_render_glow = { version = "0.6", path = "../egui_render_glow" } three-d = { version = "0.16", default-features = false } egui = { workspace = true } raw-window-handle = { workspace = true } diff --git a/crates/egui_render_wgpu/Cargo.toml b/crates/egui_render_wgpu/Cargo.toml index be55d4b..ddf21be 100644 --- a/crates/egui_render_wgpu/Cargo.toml +++ b/crates/egui_render_wgpu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui_render_wgpu" -version = "0.5.1" +version = "0.6.0" edition = "2021" description = "egui rendering backend using wgpu" license = "MIT" diff --git a/crates/egui_window_glfw_passthrough/Cargo.toml b/crates/egui_window_glfw_passthrough/Cargo.toml index 4360a7a..80cb8f2 100644 --- a/crates/egui_window_glfw_passthrough/Cargo.toml +++ b/crates/egui_window_glfw_passthrough/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "egui_window_glfw_passthrough" -version = "0.5.1" +version = "0.6.0" edition = "2021" description = "egui windowing backend using Glfw" license = "MIT" diff --git a/crates/egui_window_glfw_passthrough/src/lib.rs b/crates/egui_window_glfw_passthrough/src/lib.rs index 147087d..93e60e7 100644 --- a/crates/egui_window_glfw_passthrough/src/lib.rs +++ b/crates/egui_window_glfw_passthrough/src/lib.rs @@ -1,6 +1,7 @@ //! This crate uses `glfw-passthrough` crate as a window backend for egui. use egui::{Event, Key, PointerButton, Pos2, RawInput}; +use egui::{ViewportEvent, ViewportId, ViewportInfo}; pub use glfw; use glfw::Action; use glfw::ClientApiHint; @@ -57,6 +58,8 @@ pub struct GlfwBackend { /// in logical points pub cursor_pos: [f32; 2], pub cursor_inside_bounds: bool, + pub title: String, + pub focused: bool, } impl Drop for GlfwBackend { fn drop(&mut self) { @@ -201,6 +204,7 @@ impl GlfwBackend { let size_physical_pixels = [physical_width as u32, physical_height as u32]; let position = window.get_pos(); let window_position = [position.0, position.1]; + let focus = window.is_focused(); // set raw input screen rect details so that first frame // will have correct size even without any resize event let raw_input = RawInput { @@ -212,6 +216,19 @@ impl GlfwBackend { ] .into(), ])), + viewports: [( + ViewportId::ROOT, + ViewportInfo { + parent: None, + title: Some(window_title.clone()), + events: Default::default(), + native_pixels_per_point: Some(scale), + focused: Some(focus), + ..Default::default() + }, + )] + .into_iter() + .collect(), ..Default::default() }; tracing::info!( @@ -242,9 +259,11 @@ impl GlfwBackend { ], physical_pixels_per_virtual_unit: pixels_per_virtual_unit, window_position, + title: window_title, + focused: focus, } } - + /// returns raw input and scale. `scale` is only Some, if it changed (or if first frame). Otherwise it just returns None. pub fn take_raw_input(&mut self) -> RawInput { self.raw_input.take() } @@ -315,16 +334,27 @@ impl GlfwBackend { (size[1] * self.scale / self.physical_pixels_per_virtual_unit) as i32, ); } + pub fn set_title(&mut self, title: String) { + self.title = title; + self.window.set_title(&self.title); + } } impl GlfwBackend { #[allow(unused)] pub fn tick(&mut self) { self.frame_events.clear(); + + let time = self.glfw.get_time(); + self.raw_input.time = Some(time); + self.raw_input.focused = self.focused; + // whether we got a cursor event in this frame. // if false, and the window is passthrough, we will manually get cursor pos and push it // otherwise, we do nothing. let mut cursor_event = false; + let mut scale = None; + let mut close = false; for (_timestamp, event) in glfw::flush_messages(&self.events_receiver) { self.frame_events.push(event.clone()); // if let &glfw::WindowEvent::CursorPos(..) = &event { @@ -455,6 +485,7 @@ impl GlfwBackend { "content scale changed" ); self.scale = x; + scale = Some(x); self.window_size_logical = [ self.framebuffer_size_physical[0] as f32 / self.scale, self.framebuffer_size_physical[1] as f32 / self.scale, @@ -470,6 +501,7 @@ impl GlfwBackend { } glfw::WindowEvent::Close => { self.window.set_should_close(true); + close = true; None } glfw::WindowEvent::Pos(x, y) => { @@ -528,7 +560,11 @@ impl GlfwBackend { Some(Event::PointerGone) } } - _rest => None, + WindowEvent::Focus(f) => { + self.focused = f; + None + } + _ => None, } { self.raw_input.events.push(ev); } @@ -568,6 +604,19 @@ impl GlfwBackend { } } self.cursor_pos = logical_cursor_pos; + let title = self.title.clone(); + let vp = self + .raw_input + .viewports + .get_mut(&ViewportId::ROOT) + .expect("failed to get default viewport info"); + vp.events.clear(); + vp.focused = Some(self.focused); + vp.title = Some(title); + if let Some(scale) = scale { + vp.native_pixels_per_point = Some(scale); + } + vp.events.push(ViewportEvent::Close); } pub fn set_cursor(&mut self, cursor: egui::CursorIcon) { let cursor = egui_to_glfw_cursor(cursor);