Restore hotkeys in pane_grid example

- Implement `subscription::events_with`
- Remove `pane_grid::KeyPressEvent`
- Return closest sibling in `pane_grid::State::close`
This commit is contained in:
Héctor Ramón Jiménez 2020-11-10 02:32:57 +01:00
parent c53022e8df
commit d6d5cf0294
9 changed files with 88 additions and 45 deletions

View file

@ -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<Message> {
pub(super) f: fn(Event) -> Option<Message>,
}
impl Recipe<Hasher, Event> for Events {
type Output = Event;
impl<Message> Recipe<Hasher, Event> for Events<Message>
where
Message: 'static + Send,
{
type Output = Message;
fn hash(&self, state: &mut Hasher) {
use std::hash::Hash;
std::any::TypeId::of::<Self>().hash(state);
struct Marker;
std::any::TypeId::of::<Marker>().hash(state);
self.f.hash(state);
}
fn stream(
@ -20,5 +29,7 @@ impl Recipe<Hasher, Event> for Events {
event_stream: EventStream,
) -> BoxStream<Self::Output> {
event_stream
.filter_map(move |event| future::ready((self.f)(event)))
.boxed()
}
}