From c4b4207f4768c7e254ff0a6bf95c4d76ea08ce48 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Mar 2024 14:41:34 +0100 Subject: Support custom themes in `Program` API --- src/application/program.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/application/program.rs') diff --git a/src/application/program.rs b/src/application/program.rs index 24e00efe..d70f39cf 100644 --- a/src/application/program.rs +++ b/src/application/program.rs @@ -64,37 +64,38 @@ use std::borrow::Cow; /// ] /// } /// ``` -pub fn program( +pub fn program( title: impl Title, update: impl Update, - view: impl for<'a> self::View<'a, State, Message>, -) -> Program< - impl Definition, -> + view: impl for<'a> self::View<'a, State, Message, Theme>, +) -> Program> where State: Default + 'static, Message: Send + std::fmt::Debug, + Theme: Default + application::DefaultStyle, { use std::marker::PhantomData; - struct Application { + struct Application { update: Update, view: View, _state: PhantomData, _message: PhantomData, + _theme: PhantomData, } - impl Definition - for Application + impl Definition + for Application where State: Default, Message: Send + std::fmt::Debug, + Theme: Default + application::DefaultStyle, Update: self::Update, - View: for<'a> self::View<'a, State, Message>, + View: for<'a> self::View<'a, State, Message, Theme>, { type State = State; type Message = Message; - type Theme = crate::Theme; + type Theme = Theme; type Executor = executor::Default; fn build(&self) -> (Self::State, Command) { @@ -123,6 +124,7 @@ where view, _state: PhantomData, _message: PhantomData, + _theme: PhantomData, }, settings: Settings::default(), } @@ -793,18 +795,18 @@ where /// /// This trait allows the [`program`] builder to take any closure that /// returns any `Into>`. -pub trait View<'a, State, Message> { +pub trait View<'a, State, Message, Theme> { /// Produces the widget of the [`Program`]. - fn view(&self, state: &'a State) -> impl Into>; + fn view(&self, state: &'a State) -> impl Into>; } -impl<'a, T, State, Message, Widget> View<'a, State, Message> for T +impl<'a, T, State, Message, Theme, Widget> View<'a, State, Message, Theme> for T where T: Fn(&'a State) -> Widget, State: 'static, - Widget: Into>, + Widget: Into>, { - fn view(&self, state: &'a State) -> impl Into> { + fn view(&self, state: &'a State) -> impl Into> { self(state) } } -- cgit