Allow pure widgets to borrow from Application data 🎉

This commit is contained in:
Héctor Ramón Jiménez 2022-02-11 22:07:21 +07:00
parent 43a7ad72ef
commit 01c5004959
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
11 changed files with 103 additions and 98 deletions

View file

@ -20,7 +20,8 @@
pub use iced_pure::{Element as _, *};
/// A generic, pure [`Widget`].
pub type Element<Message> = iced_pure::Element<Message, crate::Renderer>;
pub type Element<'a, Message> =
iced_pure::Element<'a, Message, crate::Renderer>;
mod application;
mod sandbox;

View file

@ -66,7 +66,7 @@ pub trait Application: Sized {
/// Returns the widgets to display in the [`Application`].
///
/// These widgets can produce __messages__ based on user interaction.
fn view(&self) -> pure::Element<Self::Message>;
fn view(&self) -> pure::Element<'_, Self::Message>;
/// Returns the current [`Application`] mode.
///
@ -126,7 +126,7 @@ pub trait Application: Sized {
struct Instance<A: Application> {
application: A,
state: pure::State<A::Message, crate::Renderer>,
state: pure::State,
}
impl<A> crate::Application for Instance<A>

View file

@ -32,7 +32,7 @@ pub trait Sandbox {
/// Returns the widgets to display in the [`Sandbox`].
///
/// These widgets can produce __messages__ based on user interaction.
fn view(&self) -> pure::Element<Self::Message>;
fn view(&self) -> pure::Element<'_, Self::Message>;
/// Returns the background color of the [`Sandbox`].
///
@ -101,7 +101,7 @@ where
Subscription::none()
}
fn view(&self) -> pure::Element<T::Message> {
fn view(&self) -> pure::Element<'_, T::Message> {
T::view(self)
}