diff options
author | 2022-09-28 19:52:00 +0200 | |
---|---|---|
committer | 2022-09-28 19:52:00 +0200 | |
commit | 97f385e093711c269df315b28f76e66e0220e22a (patch) | |
tree | 7e4201b6d19275b770f297c300ab95bff2d91829 | |
parent | 77800bcf6d268e5891ca62928b81b3e95515c904 (diff) | |
parent | c9b8dbdb7a15a7a797eec78d1a42783e0ea0f8d6 (diff) | |
download | iced-97f385e093711c269df315b28f76e66e0220e22a.tar.gz iced-97f385e093711c269df315b28f76e66e0220e22a.tar.bz2 iced-97f385e093711c269df315b28f76e66e0220e22a.zip |
Merge pull request #1230 from kaimast/feat/ignored_events
Pass ignored events to program
-rw-r--r-- | native/src/program/state.rs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/native/src/program/state.rs b/native/src/program/state.rs index 2ddde2c2..8ae1cacb 100644 --- a/native/src/program/state.rs +++ b/native/src/program/state.rs @@ -1,8 +1,9 @@ use crate::application; +use crate::event::{self, Event}; use crate::mouse; use crate::renderer; use crate::user_interface::{self, UserInterface}; -use crate::{Clipboard, Command, Debug, Event, Point, Program, Size}; +use crate::{Clipboard, Command, Debug, Point, Program, Size}; /// The execution state of a [`Program`]. It leverages caching, event /// processing, and rendering primitive storage. @@ -82,8 +83,9 @@ where /// Processes all the queued events and messages, rebuilding and redrawing /// the widgets of the linked [`Program`] if necessary. /// - /// Returns the [`Command`] obtained from [`Program`] after updating it, - /// only if an update was necessary. + /// Returns a list containing the instances of [`Event`] that were not + /// captured by any widget, and the [`Command`] obtained from [`Program`] + /// after updating it, only if an update was necessary. pub fn update( &mut self, bounds: Size, @@ -93,7 +95,7 @@ where style: &renderer::Style, clipboard: &mut dyn Clipboard, debug: &mut Debug, - ) -> Option<Command<P::Message>> { + ) -> (Vec<Event>, Option<Command<P::Message>>) { let mut user_interface = build_user_interface( &mut self.program, self.cache.take().unwrap(), @@ -105,7 +107,7 @@ where debug.event_processing_started(); let mut messages = Vec::new(); - let _ = user_interface.update( + let (_, event_statuses) = user_interface.update( &self.queued_events, cursor_position, renderer, @@ -113,11 +115,21 @@ where &mut messages, ); - messages.append(&mut self.queued_messages); + let uncaptured_events = self + .queued_events + .iter() + .zip(event_statuses) + .filter_map(|(event, status)| { + matches!(status, event::Status::Ignored).then_some(event) + }) + .cloned() + .collect(); + self.queued_events.clear(); + messages.append(&mut self.queued_messages); debug.event_processing_finished(); - if messages.is_empty() { + let command = if messages.is_empty() { debug.draw_started(); self.mouse_interaction = user_interface.draw(renderer, theme, style, cursor_position); @@ -158,7 +170,9 @@ where self.cache = Some(user_interface.into_cache()); Some(commands) - } + }; + + (uncaptured_events, command) } } |