Let a Theme control the background color of an application

... and remove `Application::background_color`
This commit is contained in:
Héctor Ramón Jiménez 2022-05-25 05:01:18 +02:00
parent 2cfb307f8c
commit 03eda9b162
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
9 changed files with 33 additions and 79 deletions

View file

@ -1,5 +1,6 @@
use crate::theme;
use crate::window;
use crate::{Color, Command, Element, Executor, Settings, Subscription};
use crate::{Command, Element, Executor, Settings, Subscription};
/// An interactive cross-platform application.
///
@ -101,7 +102,7 @@ pub trait Application: Sized {
type Message: std::fmt::Debug + Send;
/// The theme of your [`Application`].
type Theme: Default;
type Theme: Default + theme::Definition;
/// The data needed to initialize your [`Application`].
type Flags;
@ -167,13 +168,6 @@ pub trait Application: Sized {
window::Mode::Windowed
}
/// Returns the background color of the [`Application`].
///
/// By default, it returns [`Color::WHITE`].
fn background_color(&self) -> Color {
Color::WHITE
}
/// Returns the scale factor of the [`Application`].
///
/// It can be used to dynamically control the size of the UI at runtime
@ -277,10 +271,6 @@ where
self.0.subscription()
}
fn background_color(&self) -> Color {
self.0.background_color()
}
fn scale_factor(&self) -> f64 {
self.0.scale_factor()
}

View file

@ -1,6 +1,7 @@
use crate::pure::{self, Pure};
use crate::theme;
use crate::window;
use crate::{Color, Command, Executor, Settings, Subscription};
use crate::{Command, Executor, Settings, Subscription};
/// A pure version of [`Application`].
///
@ -22,7 +23,7 @@ pub trait Application: Sized {
type Message: std::fmt::Debug + Send;
/// The theme of your [`Application`].
type Theme: Default;
type Theme: Default + theme::Definition;
/// The data needed to initialize your [`Application`].
type Flags;
@ -88,13 +89,6 @@ pub trait Application: Sized {
window::Mode::Windowed
}
/// Returns the background color of the [`Application`].
///
/// By default, it returns [`Color::WHITE`].
fn background_color(&self) -> Color {
Color::WHITE
}
/// Returns the scale factor of the [`Application`].
///
/// It can be used to dynamically control the size of the UI at runtime
@ -185,10 +179,6 @@ where
A::mode(&self.application)
}
fn background_color(&self) -> Color {
A::background_color(&self.application)
}
fn scale_factor(&self) -> f64 {
A::scale_factor(&self.application)
}

View file

@ -1,5 +1,5 @@
use crate::pure;
use crate::{Color, Command, Error, Settings, Subscription, Theme};
use crate::{Command, Error, Settings, Subscription, Theme};
/// A pure version of [`Sandbox`].
///
@ -44,13 +44,6 @@ pub trait Sandbox {
Theme::default()
}
/// Returns the background color of the [`Sandbox`].
///
/// By default, it returns [`Color::WHITE`].
fn background_color(&self) -> Color {
Color::WHITE
}
/// Returns the scale factor of the [`Sandbox`].
///
/// It can be used to dynamically control the size of the UI at runtime
@ -120,10 +113,6 @@ where
Subscription::none()
}
fn background_color(&self) -> Color {
T::background_color(self)
}
fn scale_factor(&self) -> f64 {
T::scale_factor(self)
}

View file

@ -1,5 +1,5 @@
use crate::{
Application, Color, Command, Element, Error, Settings, Subscription, Theme,
Application, Command, Element, Error, Settings, Subscription, Theme,
};
/// A sandboxed [`Application`].
@ -121,13 +121,6 @@ pub trait Sandbox {
Theme::default()
}
/// Returns the background color of the [`Sandbox`].
///
/// By default, it returns [`Color::WHITE`].
fn background_color(&self) -> Color {
Color::WHITE
}
/// Returns the scale factor of the [`Sandbox`].
///
/// It can be used to dynamically control the size of the UI at runtime
@ -197,10 +190,6 @@ where
Subscription::none()
}
fn background_color(&self) -> Color {
T::background_color(self)
}
fn scale_factor(&self) -> f64 {
T::scale_factor(self)
}