From 9676115e49ea38aa034a3afd080c809d4f94b5e6 Mon Sep 17 00:00:00 2001 From: Konkitoman Date: Wed, 8 Nov 2023 08:15:08 +0200 Subject: [PATCH] Simplify and move CloseRequested --- crates/egui-winit/src/lib.rs | 4 +--- crates/egui/src/context.rs | 1 - crates/egui/src/data/input.rs | 15 +++++---------- crates/egui/src/input_state.rs | 1 - crates/egui/src/memory.rs | 9 ++++----- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index fa65cde58ce..eec06fbbb0d 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -450,9 +450,7 @@ impl State { // Things that may require repaint: WindowEvent::CloseRequested => { - self.egui_input - .events - .push(egui::Event::WindowEvent(egui::WindowEvent::CloseRequested)); + self.egui_input.viewport.close_requested = true; EventResponse { consumed: true, repaint: true, diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index cd7be136c4a..6bfad650829 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -226,7 +226,6 @@ impl ContextImpl { self.memory.begin_frame( self.input.get(&viewport_id).unwrap_or(&Default::default()), &new_raw_input, - viewport_id, ); let input = self diff --git a/crates/egui/src/data/input.rs b/crates/egui/src/data/input.rs index 979eee49613..11200075fc8 100644 --- a/crates/egui/src/data/input.rs +++ b/crates/egui/src/data/input.rs @@ -83,8 +83,8 @@ impl Default for RawInput { events: vec![], hovered_files: Default::default(), dropped_files: Default::default(), - focused: true, - viewport: ViewportInfo::default(), // integrations opt into global focus tracking + focused: true, // integrations opt into global focus tracking + viewport: ViewportInfo::default(), } } } @@ -152,6 +152,9 @@ pub struct ViewportInfo { /// Viewport outer position and size, drowable area + decorations /// unit = physical pixels pub outer_rect: Option, + + /// Viewport should close? + pub close_requested: bool, } impl ViewportInfo { @@ -331,14 +334,6 @@ pub enum Event { /// An assistive technology (e.g. screen reader) requested an action. #[cfg(feature = "accesskit")] AccessKitActionRequest(accesskit::ActionRequest), - - WindowEvent(WindowEvent), -} - -#[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -pub enum WindowEvent { - CloseRequested, } /// Mouse button (or similar for touch input) diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 17478d17e93..47b8544f2be 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -162,7 +162,6 @@ impl InputState { }; let screen_rect = new.screen_rect.unwrap_or(self.screen_rect); - self.create_touch_states_for_new_devices(&new.events); for touch_state in self.touch_states.values_mut() { touch_state.begin_frame(time, &new, self.pointer.interact_pos); diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 89b4a745109..e4ae15ff583 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -543,19 +543,18 @@ impl Memory { &mut self, prev_input: &crate::input_state::InputState, new_input: &crate::data::input::RawInput, - viewport_id: ViewportId, ) { crate::profile_function!(); - self.viewport_id = viewport_id; + self.viewport_id = new_input.viewport.id_pair.this; self.interactions - .entry(viewport_id) + .entry(self.viewport_id) .or_default() .begin_frame(prev_input, new_input); - self.areas.entry(viewport_id).or_default(); + self.areas.entry(self.viewport_id).or_default(); if !prev_input.pointer.any_down() { - self.window_interactions.remove(&viewport_id); + self.window_interactions.remove(&self.viewport_id); } }