Use winit to obtain current theme::Mode
This commit is contained in:
parent
5c7ae8a3d6
commit
0111f514a1
25 changed files with 208 additions and 602 deletions
|
|
@ -7,7 +7,7 @@
|
|||
//!
|
||||
//! pub fn main() -> iced::Result {
|
||||
//! iced::application(u64::default, update, view)
|
||||
//! .theme(|_| Theme::Dark)
|
||||
//! .theme(Theme::Dark)
|
||||
//! .centered()
|
||||
//! .run()
|
||||
//! }
|
||||
|
|
@ -35,7 +35,7 @@ use crate::shell;
|
|||
use crate::theme;
|
||||
use crate::window;
|
||||
use crate::{
|
||||
Element, Executor, Font, Result, Settings, Size, Subscription, Task,
|
||||
Element, Executor, Font, Result, Settings, Size, Subscription, Task, Theme,
|
||||
};
|
||||
|
||||
use iced_debug as debug;
|
||||
|
|
@ -82,7 +82,7 @@ pub fn application<State, Message, Theme, Renderer>(
|
|||
where
|
||||
State: 'static,
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
{
|
||||
use std::marker::PhantomData;
|
||||
|
|
@ -101,7 +101,7 @@ where
|
|||
for Instance<State, Message, Theme, Renderer, Boot, Update, View>
|
||||
where
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
Boot: self::Boot<State, Message>,
|
||||
Update: self::Update<State, Message>,
|
||||
|
|
@ -355,13 +355,13 @@ impl<P: Program> Application<P> {
|
|||
/// Sets the theme logic of the [`Application`].
|
||||
pub fn theme(
|
||||
self,
|
||||
f: impl Fn(&P::State) -> P::Theme,
|
||||
f: impl ThemeFn<P::State, P::Theme>,
|
||||
) -> Application<
|
||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||
> {
|
||||
Application {
|
||||
raw: program::with_theme(self.raw, move |state, _window| {
|
||||
debug::hot(|| f(state))
|
||||
debug::hot(|| f.theme(state))
|
||||
}),
|
||||
settings: self.settings,
|
||||
window: self.window,
|
||||
|
|
@ -529,3 +529,25 @@ where
|
|||
self(state).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO
|
||||
pub trait ThemeFn<State, Theme> {
|
||||
/// TODO
|
||||
fn theme(&self, state: &State) -> Option<Theme>;
|
||||
}
|
||||
|
||||
impl<State> ThemeFn<State, Theme> for Theme {
|
||||
fn theme(&self, _state: &State) -> Option<Theme> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, T, State, Theme> ThemeFn<State, Theme> for F
|
||||
where
|
||||
F: Fn(&State) -> T,
|
||||
T: Into<Option<Theme>>,
|
||||
{
|
||||
fn theme(&self, state: &State) -> Option<Theme> {
|
||||
(self)(state).into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub fn timed<State, Message, Theme, Renderer>(
|
|||
where
|
||||
State: 'static,
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base + 'static,
|
||||
Theme: theme::Base + 'static,
|
||||
Renderer: program::Renderer + 'static,
|
||||
{
|
||||
use std::marker::PhantomData;
|
||||
|
|
@ -69,7 +69,7 @@ where
|
|||
>
|
||||
where
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base + 'static,
|
||||
Theme: theme::Base + 'static,
|
||||
Renderer: program::Renderer + 'static,
|
||||
Boot: self::Boot<State, Message>,
|
||||
Update: self::Update<State, Message>,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ use crate::program::{self, Program};
|
|||
use crate::shell;
|
||||
use crate::theme;
|
||||
use crate::window;
|
||||
use crate::{Element, Executor, Font, Result, Settings, Subscription, Task};
|
||||
use crate::{
|
||||
Element, Executor, Font, Result, Settings, Subscription, Task, Theme,
|
||||
};
|
||||
|
||||
use iced_debug as debug;
|
||||
|
||||
|
|
@ -28,7 +30,7 @@ pub fn daemon<State, Message, Theme, Renderer>(
|
|||
where
|
||||
State: 'static,
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
{
|
||||
use std::marker::PhantomData;
|
||||
|
|
@ -47,7 +49,7 @@ where
|
|||
for Instance<State, Message, Theme, Renderer, Boot, Update, View>
|
||||
where
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base,
|
||||
Theme: theme::Base,
|
||||
Renderer: program::Renderer,
|
||||
Boot: application::Boot<State, Message>,
|
||||
Update: application::Update<State, Message>,
|
||||
|
|
@ -202,13 +204,13 @@ impl<P: Program> Daemon<P> {
|
|||
/// Sets the theme logic of the [`Daemon`].
|
||||
pub fn theme(
|
||||
self,
|
||||
f: impl Fn(&P::State, window::Id) -> P::Theme,
|
||||
f: impl ThemeFn<P::State, P::Theme>,
|
||||
) -> Daemon<
|
||||
impl Program<State = P::State, Message = P::Message, Theme = P::Theme>,
|
||||
> {
|
||||
Daemon {
|
||||
raw: program::with_theme(self.raw, move |state, window| {
|
||||
debug::hot(|| f(state, window))
|
||||
debug::hot(|| f.theme(state, window))
|
||||
}),
|
||||
settings: self.settings,
|
||||
}
|
||||
|
|
@ -314,3 +316,25 @@ where
|
|||
self(state, window).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO
|
||||
pub trait ThemeFn<State, Theme> {
|
||||
/// TODO
|
||||
fn theme(&self, state: &State, window: window::Id) -> Option<Theme>;
|
||||
}
|
||||
|
||||
impl<State> ThemeFn<State, Theme> for Theme {
|
||||
fn theme(&self, _state: &State, _window: window::Id) -> Option<Theme> {
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, T, State, Theme> ThemeFn<State, Theme> for F
|
||||
where
|
||||
F: Fn(&State, window::Id) -> T,
|
||||
T: Into<Option<Theme>>,
|
||||
{
|
||||
fn theme(&self, state: &State, window: window::Id) -> Option<Theme> {
|
||||
(self)(state, window).into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -698,7 +698,7 @@ pub fn run<State, Message, Theme, Renderer>(
|
|||
where
|
||||
State: Default + 'static,
|
||||
Message: program::Message + 'static,
|
||||
Theme: Default + theme::Base + 'static,
|
||||
Theme: theme::Base + 'static,
|
||||
Renderer: program::Renderer + 'static,
|
||||
{
|
||||
application(State::default, update, view).run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue