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.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'native/src/subscription.rs') diff --git a/native/src/subscription.rs b/native/src/subscription.rs index 0d002c6c..18750abf 100644 --- a/native/src/subscription.rs +++ b/native/src/subscription.rs @@ -43,5 +43,25 @@ use events::Events; /// [`Subscription`]: type.Subscription.html /// [`Event`]: ../enum.Event.html pub fn events() -> Subscription { - Subscription::from_recipe(Events) + Subscription::from_recipe(Events { f: Some }) +} + +/// Returns a [`Subscription`] that filters all the runtime events with the +/// provided function, producing messages accordingly. +/// +/// This subscription will call the provided function for every [`Event`] +/// handled by the runtime. If the function: +/// +/// - Returns `None`, the [`Event`] will be discarded. +/// - Returns `Some` message, the `Message` will be produced. +/// +/// [`Subscription`]: type.Subscription.html +/// [`Event`]: ../enum.Event.html +pub fn events_with( + f: fn(Event) -> Option, +) -> Subscription +where + Message: 'static + Send, +{ + Subscription::from_recipe(Events { f }) } -- cgit