summaryrefslogtreecommitdiffstats
path: root/native/src/subscription.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-11-10 22:57:19 +0100
committerLibravatar GitHub <noreply@github.com>2020-11-10 22:57:19 +0100
commit2f5a3dacd933a52931a1bb169138d52402413956 (patch)
tree65995b4304543ea6a6400af3c8e11eae630dd22b /native/src/subscription.rs
parentd0402d072d3f4e128c55fc0a6184c5f7c712bb20 (diff)
parent86fa12229e7117306b8297a09aa22c99802600c8 (diff)
downloadiced-2f5a3dacd933a52931a1bb169138d52402413956.tar.gz
iced-2f5a3dacd933a52931a1bb169138d52402413956.tar.bz2
iced-2f5a3dacd933a52931a1bb169138d52402413956.zip
Merge pull request #608 from hecrj/remove-pane-grid-focus
Improve flexibility of `PaneGrid`
Diffstat (limited to 'native/src/subscription.rs')
-rw-r--r--native/src/subscription.rs22
1 files changed, 21 insertions, 1 deletions
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<Event> {
- 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<Message>(
+ f: fn(Event) -> Option<Message>,
+) -> Subscription<Message>
+where
+ Message: 'static + Send,
+{
+ Subscription::from_recipe(Events { f })
}