Skip to content

Commit

Permalink
Fix: Make sure RawInput::take clears all events, like it says it do…
Browse files Browse the repository at this point in the history
…es (emilk#5104)
  • Loading branch information
emilk authored and hacknus committed Oct 30, 2024
1 parent bbecc35 commit dd3c716
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dd3c716

Please sign in to comment.