From d6d5cf0294b1231f4909a782e90b491cc6838fae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 10 Nov 2020 02:32:57 +0100 Subject: Restore hotkeys in `pane_grid` example - Implement `subscription::events_with` - Remove `pane_grid::KeyPressEvent` - Return closest sibling in `pane_grid::State::close` --- native/src/subscription/events.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'native/src/subscription') diff --git a/native/src/subscription/events.rs b/native/src/subscription/events.rs index ceae467d..a1ae6051 100644 --- a/native/src/subscription/events.rs +++ b/native/src/subscription/events.rs @@ -2,17 +2,26 @@ use crate::{ subscription::{EventStream, Recipe}, Event, Hasher, }; +use iced_futures::futures::future; +use iced_futures::futures::StreamExt; use iced_futures::BoxStream; -pub struct Events; +pub struct Events { + pub(super) f: fn(Event) -> Option, +} -impl Recipe for Events { - type Output = Event; +impl Recipe for Events +where + Message: 'static + Send, +{ + type Output = Message; fn hash(&self, state: &mut Hasher) { use std::hash::Hash; - std::any::TypeId::of::().hash(state); + struct Marker; + std::any::TypeId::of::().hash(state); + self.f.hash(state); } fn stream( @@ -20,5 +29,7 @@ impl Recipe for Events { event_stream: EventStream, ) -> BoxStream { event_stream + .filter_map(move |event| future::ready((self.f)(event))) + .boxed() } } -- cgit