Merge pull request #122 from hecrj/feature/event-subscriptions
Event subscriptions
This commit is contained in:
commit
0f2e20f5e5
20 changed files with 726 additions and 39 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
pub use iced_winit::{
|
||||
Align, Background, Color, Command, Font, HorizontalAlignment, Length,
|
||||
VerticalAlignment,
|
||||
Subscription, VerticalAlignment,
|
||||
};
|
||||
|
||||
pub mod widget {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue