From d575f4541126e2ab25908fe55c6805f16716b2a5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 5 Dec 2019 06:10:13 +0100 Subject: Draft first version of event subscriptions :tada: --- src/application.rs | 11 ++++++++++- src/native.rs | 4 ++-- src/sandbox.rs | 6 +++++- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index a4d20e68..95113344 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,11 @@ pub trait Application: Sized { /// [`Command`]: struct.Command.html fn update(&mut self, message: Self::Message) -> Command; + /// TODO + fn subscriptions(&self) -> Subscription { + Subscription::none() + } + /// Returns the widgets to display in the [`Application`]. /// /// These widgets can produce __messages__ based on user interaction. @@ -168,6 +173,10 @@ where self.0.update(message) } + fn subscriptions(&self) -> Subscription { + self.0.subscriptions() + } + fn view(&mut self) -> Element<'_, Self::Message> { self.0.view() } diff --git a/src/native.rs b/src/native.rs index 3537dd52..e3733955 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, Align, Background, Color, Command, Font, HorizontalAlignment, + Length, Subscription, VerticalAlignment, }; pub mod widget { diff --git a/src/sandbox.rs b/src/sandbox.rs index acf7f5e0..248aa152 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 subscriptions(&self) -> Subscription { + Subscription::none() + } + fn view(&mut self) -> Element<'_, T::Message> { T::view(self) } -- cgit From 98160406f714728afe718f305bf9d12be1676b2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 8 Dec 2019 08:21:26 +0100 Subject: Allow listening to runtime events in subscriptions --- src/native.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/native.rs b/src/native.rs index e3733955..e517b05d 100644 --- a/src/native.rs +++ b/src/native.rs @@ -1,6 +1,6 @@ pub use iced_winit::{ - subscription, Align, Background, Color, Command, Font, HorizontalAlignment, - Length, Subscription, VerticalAlignment, + Align, Background, Color, Command, Font, HorizontalAlignment, Length, + Subscription, VerticalAlignment, }; pub mod widget { -- cgit From d6c3da21f7fe7a79bcfbc2a180dc111e42300a04 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 Dec 2019 05:56:46 +0100 Subject: Write docs for subscriptions and reorganize a bit --- src/application.rs | 17 +++++++++++++---- src/sandbox.rs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 95113344..98e160ce 100644 --- a/src/application.rs +++ b/src/application.rs @@ -117,8 +117,17 @@ pub trait Application: Sized { /// [`Command`]: struct.Command.html fn update(&mut self, message: Self::Message) -> Command; - /// TODO - fn subscriptions(&self) -> Subscription { + /// 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 { Subscription::none() } @@ -173,8 +182,8 @@ where self.0.update(message) } - fn subscriptions(&self) -> Subscription { - self.0.subscriptions() + fn subscription(&self) -> Subscription { + self.0.subscription() } fn view(&mut self) -> Element<'_, Self::Message> { diff --git a/src/sandbox.rs b/src/sandbox.rs index 248aa152..75020b16 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -149,7 +149,7 @@ where Command::none() } - fn subscriptions(&self) -> Subscription { + fn subscription(&self) -> Subscription { Subscription::none() } -- cgit