From 897a33c947a5c96ee44d7d5a0166993456f70373 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 14 Jan 2022 21:20:04 +0300 Subject: [PATCH 1/5] Call .drag_window() only after Left mouse btn clicked --- egui-winit/src/epi.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index ea4353bf92b..4ecca07276b 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -196,6 +196,7 @@ pub struct EpiIntegration { pub app: Box, /// When set, it is time to quit quit: bool, + can_drag_window: bool, } impl EpiIntegration { @@ -229,6 +230,7 @@ impl EpiIntegration { egui_winit: crate::State::new(window), app, quit: false, + can_drag_window: false, }; slf.setup(window); @@ -264,8 +266,18 @@ impl EpiIntegration { } pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) { - use winit::event::WindowEvent; + use winit::event::{ElementState, MouseButton, WindowEvent}; self.quit |= matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed); + + if let WindowEvent::MouseInput { + button: MouseButton::Left, + state: ElementState::Pressed, + .. + } = event + { + self.can_drag_window = true; + } + self.egui_winit.on_event(&self.egui_ctx, event); } @@ -289,7 +301,9 @@ impl EpiIntegration { self.egui_winit .handle_output(window, &self.egui_ctx, egui_output); - let app_output = self.frame.take_app_output(); + let mut app_output = self.frame.take_app_output(); + app_output.drag_window &= self.can_drag_window; + self.can_drag_window = false; self.quit |= app_output.quit; let tex_allocation_data = crate::epi::handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output); From 97aef1a44e7d1b9c004f98d82968dfec8785e61e Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 14 Jan 2022 21:26:02 +0300 Subject: [PATCH 2/5] Better check for can_drag_window --- egui-winit/src/epi.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index 4ecca07276b..49ccbe4a603 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -302,8 +302,11 @@ impl EpiIntegration { .handle_output(window, &self.egui_ctx, egui_output); let mut app_output = self.frame.take_app_output(); - app_output.drag_window &= self.can_drag_window; - self.can_drag_window = false; + if app_output.drag_window { + app_output.drag_window &= self.can_drag_window; + self.can_drag_window = false; + } + self.quit |= app_output.quit; let tex_allocation_data = crate::epi::handle_app_output(window, self.egui_ctx.pixels_per_point(), app_output); From 8a0136d53115e49c8025a380d2ecf82b2208f4e6 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Mon, 17 Jan 2022 19:08:03 +0300 Subject: [PATCH 3/5] Reset can_drag_window on every frame --- egui-winit/src/epi.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index 49ccbe4a603..b0f808355c3 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -302,10 +302,8 @@ impl EpiIntegration { .handle_output(window, &self.egui_ctx, egui_output); let mut app_output = self.frame.take_app_output(); - if app_output.drag_window { - app_output.drag_window &= self.can_drag_window; - self.can_drag_window = false; - } + app_output.drag_window &= self.can_drag_window; + self.can_drag_window = false; self.quit |= app_output.quit; let tex_allocation_data = From 76acae5d4990e284f037769fd0e672cafeb0dc90 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 26 Jan 2022 21:33:16 +0300 Subject: [PATCH 4/5] Add `drag_window` fix to CHANGELOG --- CHANGELOG.md | 2 ++ egui-winit/CHANGELOG.md | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69ad2f99ba4..494412e7966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,10 +38,12 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w ### Fixed 🐛 * Context menu now respects the theme ([#1043](https://github.com/emilk/egui/pull/1043)) * Plot `Orientation` was not public, although fields using this type were ([#1130](https://github.com/emilk/egui/pull/1130)) +* Fixed `enable_drag` for Windows ([#1108](https://github.com/emilk/egui/pull/1108)). ### Contributors 🙏 * [danielkeller](https://github.com/danielkeller): [#1050](https://github.com/emilk/egui/pull/1050). * [juancampa](https://github.com/juancampa): [#1147](https://github.com/emilk/egui/pull/1147). +* [AlexxxRu](https://github.com/alexxxru): [#1108](https://github.com/emilk/egui/pull/1108). ## 0.16.1 - 2021-12-31 - Add back `CtxRef::begin_frame,end_frame` diff --git a/egui-winit/CHANGELOG.md b/egui-winit/CHANGELOG.md index 258e6a85855..426fbc6a206 100644 --- a/egui-winit/CHANGELOG.md +++ b/egui-winit/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the `egui-winit` integration will be noted in this file. * Replaced `std::time::Instant` with `instant::Instant` for WebAssembly compatability ([#1023](https://github.com/emilk/egui/pull/1023)) * Shift-scroll will now result in horizontal scrolling on all platforms ([#1136](https://github.com/emilk/egui/pull/1136)). * Require knowledge about max texture side (e.g. `GL_MAX_TEXTURE_SIZE`)) ([#1154](https://github.com/emilk/egui/pull/1154)). +* Fixed `enable_drag` for Windows. Now called only once just after left click ([#1108](https://github.com/emilk/egui/pull/1108)). ## 0.16.0 - 2021-12-29 From a1e9e1e0b104fe9be7eb288944b8bb2fadf14974 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 26 Jan 2022 21:21:13 +0100 Subject: [PATCH 5/5] explain why in the code --- egui-winit/src/epi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index 6209ccfeca1..f9eeaece098 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -300,7 +300,7 @@ impl EpiIntegration { .handle_output(window, &self.egui_ctx, egui_output); let mut app_output = self.frame.take_app_output(); - app_output.drag_window &= self.can_drag_window; + app_output.drag_window &= self.can_drag_window; // Necessary on Windows; see https://github.com/emilk/egui/pull/1108 self.can_drag_window = false; if app_output.quit {