From dd3c716e5ffc87771e22c2568a89d7d4279e389f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 13 Sep 2024 11:26:50 +0200 Subject: [PATCH] Fix: Make sure `RawInput::take` clears all events, like it says it does (#5104) --- crates/egui/src/data/input.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/data/input.rs b/crates/egui/src/data/input.rs index c1b175dd843..3601fcae46e 100644 --- a/crates/egui/src/data/input.rs +++ b/crates/egui/src/data/input.rs @@ -116,10 +116,14 @@ impl RawInput { pub fn take(&mut self) -> Self { Self { viewport_id: self.viewport_id, - viewports: self.viewports.clone(), + viewports: self + .viewports + .iter_mut() + .map(|(id, info)| (*id, info.take())) + .collect(), screen_rect: self.screen_rect.take(), max_texture_side: self.max_texture_side.take(), - time: self.time.take(), + time: self.time, predicted_dt: self.predicted_dt, modifiers: self.modifiers, events: std::mem::take(&mut self.events), @@ -247,6 +251,23 @@ impl ViewportInfo { .any(|&event| event == ViewportEvent::Close) } + /// Helper: move [`Self::events`], clone the other fields. + pub fn take(&mut self) -> Self { + Self { + parent: self.parent, + title: self.title.clone(), + events: std::mem::take(&mut self.events), + native_pixels_per_point: self.native_pixels_per_point, + monitor_size: self.monitor_size, + inner_rect: self.inner_rect, + outer_rect: self.outer_rect, + minimized: self.minimized, + maximized: self.maximized, + fullscreen: self.fullscreen, + focused: self.focused, + } + } + pub fn ui(&self, ui: &mut crate::Ui) { let Self { parent,