Merge pull request #1230 from kaimast/feat/ignored_events

Pass ignored events to program
This commit is contained in:
Héctor Ramón 2022-09-28 19:52:00 +02:00 committed by GitHub
commit 97f385e093
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,9 @@
use crate::application; use crate::application;
use crate::event::{self, Event};
use crate::mouse; use crate::mouse;
use crate::renderer; use crate::renderer;
use crate::user_interface::{self, UserInterface}; 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 /// The execution state of a [`Program`]. It leverages caching, event
/// processing, and rendering primitive storage. /// processing, and rendering primitive storage.
@ -82,8 +83,9 @@ where
/// Processes all the queued events and messages, rebuilding and redrawing /// Processes all the queued events and messages, rebuilding and redrawing
/// the widgets of the linked [`Program`] if necessary. /// the widgets of the linked [`Program`] if necessary.
/// ///
/// Returns the [`Command`] obtained from [`Program`] after updating it, /// Returns a list containing the instances of [`Event`] that were not
/// only if an update was necessary. /// captured by any widget, and the [`Command`] obtained from [`Program`]
/// after updating it, only if an update was necessary.
pub fn update( pub fn update(
&mut self, &mut self,
bounds: Size, bounds: Size,
@ -93,7 +95,7 @@ where
style: &renderer::Style, style: &renderer::Style,
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
debug: &mut Debug, debug: &mut Debug,
) -> Option<Command<P::Message>> { ) -> (Vec<Event>, Option<Command<P::Message>>) {
let mut user_interface = build_user_interface( let mut user_interface = build_user_interface(
&mut self.program, &mut self.program,
self.cache.take().unwrap(), self.cache.take().unwrap(),
@ -105,7 +107,7 @@ where
debug.event_processing_started(); debug.event_processing_started();
let mut messages = Vec::new(); let mut messages = Vec::new();
let _ = user_interface.update( let (_, event_statuses) = user_interface.update(
&self.queued_events, &self.queued_events,
cursor_position, cursor_position,
renderer, renderer,
@ -113,11 +115,21 @@ where
&mut messages, &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(); self.queued_events.clear();
messages.append(&mut self.queued_messages);
debug.event_processing_finished(); debug.event_processing_finished();
if messages.is_empty() { let command = if messages.is_empty() {
debug.draw_started(); debug.draw_started();
self.mouse_interaction = self.mouse_interaction =
user_interface.draw(renderer, theme, style, cursor_position); user_interface.draw(renderer, theme, style, cursor_position);
@ -158,7 +170,9 @@ where
self.cache = Some(user_interface.into_cache()); self.cache = Some(user_interface.into_cache());
Some(commands) Some(commands)
} };
(uncaptured_events, command)
} }
} }