Merge branch 'master' into feature/test-recorder
This commit is contained in:
commit
a052ce58b0
69 changed files with 1555 additions and 833 deletions
|
|
@ -32,7 +32,7 @@ pub trait Program: Sized {
|
|||
type Message: Send + 'static;
|
||||
|
||||
/// The theme of the program.
|
||||
type Theme: Default + theme::Base;
|
||||
type Theme: theme::Base;
|
||||
|
||||
/// The renderer of the program.
|
||||
type Renderer: Renderer;
|
||||
|
|
@ -97,15 +97,19 @@ pub trait Program: Sized {
|
|||
Subscription::none()
|
||||
}
|
||||
|
||||
fn theme(&self, _state: &Self::State, _window: window::Id) -> Self::Theme {
|
||||
<Self::Theme as Default>::default()
|
||||
fn theme(
|
||||
&self,
|
||||
_state: &Self::State,
|
||||
_window: window::Id,
|
||||
) -> Option<Self::Theme> {
|
||||
None
|
||||
}
|
||||
|
||||
fn style(&self, _state: &Self::State, theme: &Self::Theme) -> theme::Style {
|
||||
theme::Base::base(theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, _state: &Self::State, _window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, _state: &Self::State, _window: window::Id) -> f32 {
|
||||
1.0
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +179,7 @@ pub fn with_title<P: Program>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
self.program.theme(state, window)
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +198,7 @@ pub fn with_title<P: Program>(
|
|||
self.program.style(state, theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -269,7 +273,7 @@ pub fn with_subscription<P: Program>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
self.program.theme(state, window)
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +285,7 @@ pub fn with_subscription<P: Program>(
|
|||
self.program.style(state, theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -295,7 +299,7 @@ pub fn with_subscription<P: Program>(
|
|||
/// Decorates a [`Program`] with the given theme function.
|
||||
pub fn with_theme<P: Program>(
|
||||
program: P,
|
||||
f: impl Fn(&P::State, window::Id) -> P::Theme,
|
||||
f: impl Fn(&P::State, window::Id) -> Option<P::Theme>,
|
||||
) -> impl Program<State = P::State, Message = P::Message, Theme = P::Theme> {
|
||||
struct WithTheme<P, F> {
|
||||
program: P,
|
||||
|
|
@ -304,7 +308,7 @@ pub fn with_theme<P: Program>(
|
|||
|
||||
impl<P: Program, F> Program for WithTheme<P, F>
|
||||
where
|
||||
F: Fn(&P::State, window::Id) -> P::Theme,
|
||||
F: Fn(&P::State, window::Id) -> Option<P::Theme>,
|
||||
{
|
||||
type State = P::State;
|
||||
type Message = P::Message;
|
||||
|
|
@ -316,7 +320,7 @@ pub fn with_theme<P: Program>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
(self.theme)(state, window)
|
||||
}
|
||||
|
||||
|
|
@ -371,7 +375,7 @@ pub fn with_theme<P: Program>(
|
|||
self.program.style(state, theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -454,11 +458,11 @@ pub fn with_style<P: Program>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
self.program.theme(state, window)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -469,7 +473,7 @@ pub fn with_style<P: Program>(
|
|||
/// Decorates a [`Program`] with the given scale factor function.
|
||||
pub fn with_scale_factor<P: Program>(
|
||||
program: P,
|
||||
f: impl Fn(&P::State, window::Id) -> f64,
|
||||
f: impl Fn(&P::State, window::Id) -> f32,
|
||||
) -> impl Program<State = P::State, Message = P::Message, Theme = P::Theme> {
|
||||
struct WithScaleFactor<P, F> {
|
||||
program: P,
|
||||
|
|
@ -478,7 +482,7 @@ pub fn with_scale_factor<P: Program>(
|
|||
|
||||
impl<P: Program, F> Program for WithScaleFactor<P, F>
|
||||
where
|
||||
F: Fn(&P::State, window::Id) -> f64,
|
||||
F: Fn(&P::State, window::Id) -> f32,
|
||||
{
|
||||
type State = P::State;
|
||||
type Message = P::Message;
|
||||
|
|
@ -533,7 +537,7 @@ pub fn with_scale_factor<P: Program>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
self.program.theme(state, window)
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +549,7 @@ pub fn with_scale_factor<P: Program>(
|
|||
self.program.style(state, theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
(self.scale_factor)(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -624,7 +628,7 @@ pub fn with_executor<P: Program, E: Executor>(
|
|||
&self,
|
||||
state: &Self::State,
|
||||
window: window::Id,
|
||||
) -> Self::Theme {
|
||||
) -> Option<Self::Theme> {
|
||||
self.program.theme(state, window)
|
||||
}
|
||||
|
||||
|
|
@ -636,7 +640,7 @@ pub fn with_executor<P: Program, E: Executor>(
|
|||
self.program.style(state, theme)
|
||||
}
|
||||
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f64 {
|
||||
fn scale_factor(&self, state: &Self::State, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(state, window)
|
||||
}
|
||||
}
|
||||
|
|
@ -697,7 +701,7 @@ impl<P: Program> Instance<P> {
|
|||
}
|
||||
|
||||
/// Returns the current theme of the [`Instance`].
|
||||
pub fn theme(&self, window: window::Id) -> P::Theme {
|
||||
pub fn theme(&self, window: window::Id) -> Option<P::Theme> {
|
||||
self.program.theme(&self.state, window)
|
||||
}
|
||||
|
||||
|
|
@ -707,7 +711,7 @@ impl<P: Program> Instance<P> {
|
|||
}
|
||||
|
||||
/// Returns the current scale factor of the [`Instance`].
|
||||
pub fn scale_factor(&self, window: window::Id) -> f64 {
|
||||
pub fn scale_factor(&self, window: window::Id) -> f32 {
|
||||
self.program.scale_factor(&self.state, window)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue