diff options
author | 2019-12-16 21:38:56 +0100 | |
---|---|---|
committer | 2019-12-16 21:38:56 +0100 | |
commit | 0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36 (patch) | |
tree | 6b4c601bfa0ced1e003f597d7f485be7c108e12c /src | |
parent | 3702b109977a249247a0f1be40e57bec2cbaa4e3 (diff) | |
parent | 430ab6e44432d044f8444575053d97651f0f7d20 (diff) | |
download | iced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.tar.gz iced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.tar.bz2 iced-0f2e20f5e5b1f0658ab4e6cbe6fdda9ca97f2b36.zip |
Merge pull request #122 from hecrj/feature/event-subscriptions
Event subscriptions
Diffstat (limited to 'src')
-rw-r--r-- | src/application.rs | 20 | ||||
-rw-r--r-- | src/native.rs | 2 | ||||
-rw-r--r-- | src/sandbox.rs | 6 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/application.rs b/src/application.rs index a4d20e68..98e160ce 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,4 +1,4 @@ -use crate::{Command, Element, Settings}; +use crate::{Command, Element, Settings, Subscription}; /// An interactive cross-platform application. /// @@ -117,6 +117,20 @@ pub trait Application: Sized { /// [`Command`]: struct.Command.html fn update(&mut self, message: Self::Message) -> Command<Self::Message>; + /// Returns the event [`Subscription`] for the current state of the + /// application. + /// + /// A [`Subscription`] will be kept alive as long as you keep returning it, + /// and the __messages__ produced will be handled by + /// [`update`](#tymethod.update). + /// + /// By default, this method returns an empty [`Subscription`]. + /// + /// [`Subscription`]: struct.Subscription.html + fn subscription(&self) -> Subscription<Self::Message> { + Subscription::none() + } + /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. @@ -168,6 +182,10 @@ where self.0.update(message) } + fn subscription(&self) -> Subscription<Self::Message> { + self.0.subscription() + } + fn view(&mut self) -> Element<'_, Self::Message> { self.0.view() } diff --git a/src/native.rs b/src/native.rs index c6ddf25b..f06f1c99 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1,6 +1,6 @@ pub use iced_winit::{ Align, Background, Color, Command, Font, HorizontalAlignment, Length, - VerticalAlignment, + Subscription, VerticalAlignment, }; pub mod widget { diff --git a/src/sandbox.rs b/src/sandbox.rs index acf7f5e0..75020b16 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,4 +1,4 @@ -use crate::{Application, Command, Element, Settings}; +use crate::{Application, Command, Element, Settings, Subscription}; /// A sandboxed [`Application`]. /// @@ -149,6 +149,10 @@ where Command::none() } + fn subscription(&self) -> Subscription<T::Message> { + Subscription::none() + } + fn view(&mut self) -> Element<'_, T::Message> { T::view(self) } |