Leverage DefaultStyle traits instead of Default
This commit is contained in:
parent
44f002f64a
commit
833538ee7f
30 changed files with 393 additions and 437 deletions
|
|
@ -3,7 +3,7 @@ use crate::{Command, Element, Executor, Settings, Subscription};
|
||||||
|
|
||||||
use crate::shell::application;
|
use crate::shell::application;
|
||||||
|
|
||||||
pub use application::{default, Appearance, Style};
|
pub use application::{default, Appearance, DefaultStyle};
|
||||||
|
|
||||||
/// An interactive cross-platform application.
|
/// An interactive cross-platform application.
|
||||||
///
|
///
|
||||||
|
|
@ -95,7 +95,7 @@ pub use application::{default, Appearance, Style};
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Application: Sized
|
pub trait Application: Sized
|
||||||
where
|
where
|
||||||
Style<Self::Theme>: Default,
|
Self::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
/// The [`Executor`] that will run commands and subscriptions.
|
/// The [`Executor`] that will run commands and subscriptions.
|
||||||
///
|
///
|
||||||
|
|
@ -153,11 +153,9 @@ where
|
||||||
Self::Theme::default()
|
Self::Theme::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current `Style` of the [`Theme`].
|
/// Returns the current [`Appearance`] of the [`Application`].
|
||||||
///
|
|
||||||
/// [`Theme`]: Self::Theme
|
|
||||||
fn style(&self, theme: &Self::Theme) -> Appearance {
|
fn style(&self, theme: &Self::Theme) -> Appearance {
|
||||||
Style::default().resolve(theme)
|
theme.default_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event [`Subscription`] for the current state of the
|
/// Returns the event [`Subscription`] for the current state of the
|
||||||
|
|
@ -221,12 +219,12 @@ where
|
||||||
struct Instance<A>(A)
|
struct Instance<A>(A)
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
application::Style<A::Theme>: Default;
|
A::Theme: DefaultStyle;
|
||||||
|
|
||||||
impl<A> crate::runtime::Program for Instance<A>
|
impl<A> crate::runtime::Program for Instance<A>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
application::Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
type Message = A::Message;
|
type Message = A::Message;
|
||||||
type Theme = A::Theme;
|
type Theme = A::Theme;
|
||||||
|
|
@ -244,7 +242,7 @@ where
|
||||||
impl<A> application::Application for Instance<A>
|
impl<A> application::Application for Instance<A>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
application::Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
type Flags = A::Flags;
|
type Flags = A::Flags;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::window;
|
use crate::window;
|
||||||
use crate::{Command, Element, Executor, Settings, Subscription};
|
use crate::{Command, Element, Executor, Settings, Subscription};
|
||||||
|
|
||||||
pub use crate::application::{default, Appearance, Style};
|
pub use crate::application::{Appearance, DefaultStyle};
|
||||||
|
|
||||||
/// An interactive cross-platform multi-window application.
|
/// An interactive cross-platform multi-window application.
|
||||||
///
|
///
|
||||||
|
|
@ -67,7 +67,7 @@ pub use crate::application::{default, Appearance, Style};
|
||||||
/// [`Sandbox`]: crate::Sandbox
|
/// [`Sandbox`]: crate::Sandbox
|
||||||
pub trait Application: Sized
|
pub trait Application: Sized
|
||||||
where
|
where
|
||||||
Style<Self::Theme>: Default,
|
Self::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
/// The [`Executor`] that will run commands and subscriptions.
|
/// The [`Executor`] that will run commands and subscriptions.
|
||||||
///
|
///
|
||||||
|
|
@ -133,7 +133,7 @@ where
|
||||||
///
|
///
|
||||||
/// [`Theme`]: Self::Theme
|
/// [`Theme`]: Self::Theme
|
||||||
fn style(&self, theme: &Self::Theme) -> Appearance {
|
fn style(&self, theme: &Self::Theme) -> Appearance {
|
||||||
Style::default().resolve(theme)
|
Self::Theme::default_style(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event [`Subscription`] for the current state of the
|
/// Returns the event [`Subscription`] for the current state of the
|
||||||
|
|
@ -198,12 +198,12 @@ where
|
||||||
struct Instance<A>(A)
|
struct Instance<A>(A)
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
Style<A::Theme>: Default;
|
A::Theme: DefaultStyle;
|
||||||
|
|
||||||
impl<A> crate::runtime::multi_window::Program for Instance<A>
|
impl<A> crate::runtime::multi_window::Program for Instance<A>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
type Message = A::Message;
|
type Message = A::Message;
|
||||||
type Theme = A::Theme;
|
type Theme = A::Theme;
|
||||||
|
|
@ -224,7 +224,7 @@ where
|
||||||
impl<A> crate::shell::multi_window::Application for Instance<A>
|
impl<A> crate::shell::multi_window::Application for Instance<A>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
type Flags = A::Flags;
|
type Flags = A::Flags;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,9 @@ pub trait Sandbox {
|
||||||
|
|
||||||
/// Returns the current [`application::Appearance`].
|
/// Returns the current [`application::Appearance`].
|
||||||
fn style(&self, theme: &Theme) -> application::Appearance {
|
fn style(&self, theme: &Theme) -> application::Appearance {
|
||||||
crate::shell::application::default(theme)
|
use application::DefaultStyle;
|
||||||
|
|
||||||
|
theme.default_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the scale factor of the [`Sandbox`].
|
/// Returns the scale factor of the [`Sandbox`].
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ where
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
let content = content.into();
|
let content = content.into();
|
||||||
let size = content.as_widget().size_hint();
|
let size = content.as_widget().size_hint();
|
||||||
|
|
@ -80,7 +80,7 @@ where
|
||||||
height: size.height.fluid(),
|
height: size.height.fluid(),
|
||||||
padding: Padding::new(5.0),
|
padding: Padding::new(5.0),
|
||||||
clip: false,
|
clip: false,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ where
|
||||||
|
|
||||||
/// Sets the style variant of this [`Button`].
|
/// Sets the style variant of this [`Button`].
|
||||||
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,7 +301,7 @@ where
|
||||||
Status::Active
|
Status::Active
|
||||||
};
|
};
|
||||||
|
|
||||||
let styling = (self.style.0)(theme, status);
|
let styling = (self.style)(theme, status);
|
||||||
|
|
||||||
if styling.background.is_some()
|
if styling.background.is_some()
|
||||||
|| styling.border.width > 0.0
|
|| styling.border.width > 0.0
|
||||||
|
|
@ -424,26 +424,23 @@ impl std::default::Default for Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Button`].
|
/// The style of a [`Button`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Button`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Button`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
primary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(primary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ where
|
||||||
/// * a boolean describing whether the [`Checkbox`] is checked or not
|
/// * a boolean describing whether the [`Checkbox`] is checked or not
|
||||||
pub fn new(label: impl Into<String>, is_checked: bool) -> Self
|
pub fn new(label: impl Into<String>, is_checked: bool) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Checkbox {
|
Checkbox {
|
||||||
is_checked,
|
is_checked,
|
||||||
|
|
@ -91,7 +91,7 @@ where
|
||||||
line_height: text::LineHeight::default(),
|
line_height: text::LineHeight::default(),
|
||||||
shaping: text::Shaping::Basic,
|
shaping: text::Shaping::Basic,
|
||||||
},
|
},
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ where
|
||||||
|
|
||||||
/// Sets the style of the [`Checkbox`].
|
/// Sets the style of the [`Checkbox`].
|
||||||
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +301,7 @@ where
|
||||||
Status::Active { is_checked }
|
Status::Active { is_checked }
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
{
|
{
|
||||||
let layout = children.next().unwrap();
|
let layout = children.next().unwrap();
|
||||||
|
|
@ -424,26 +424,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Checkbox`].
|
/// The style of a [`Checkbox`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Checkbox`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Checkbox`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
primary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(primary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,9 @@ where
|
||||||
on_selected: impl Fn(T) -> Message + 'static,
|
on_selected: impl Fn(T) -> Message + 'static,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
let style = Style::<Theme>::default();
|
let style = Theme::default_style();
|
||||||
|
|
||||||
let text_input = TextInput::with_style(
|
let text_input = TextInput::with_style(
|
||||||
placeholder,
|
placeholder,
|
||||||
|
|
@ -762,7 +762,7 @@ where
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The appearance of a [`ComboBox`].
|
/// The style of a [`ComboBox`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Style<Theme> {
|
pub struct Style<Theme> {
|
||||||
/// The style of the [`TextInput`] of the [`ComboBox`].
|
/// The style of the [`TextInput`] of the [`ComboBox`].
|
||||||
|
|
@ -772,6 +772,14 @@ pub struct Style<Theme> {
|
||||||
menu: menu::Style<Theme>,
|
menu: menu::Style<Theme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Style<Theme> {
|
||||||
|
/// The default style of a [`ComboBox`].
|
||||||
|
pub const DEFAULT: Self = Self {
|
||||||
|
text_input: text_input::default,
|
||||||
|
menu: menu::Style::<Theme>::DEFAULT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
impl<Theme> Clone for Style<Theme> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
|
|
@ -780,16 +788,14 @@ impl<Theme> Clone for Style<Theme> {
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl<Theme> Copy for Style<Theme> {}
|
||||||
|
|
||||||
impl Default for Style<Theme> {
|
/// The default style of a [`ComboBox`].
|
||||||
fn default() -> Self {
|
pub trait DefaultStyle: Sized {
|
||||||
default()
|
/// Returns the default style of a [`ComboBox`].
|
||||||
}
|
fn default_style() -> Style<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default style of a [`ComboBox`].
|
impl DefaultStyle for Theme {
|
||||||
pub fn default() -> Style<Theme> {
|
fn default_style() -> Style<Self> {
|
||||||
Style {
|
Style::<Self>::DEFAULT
|
||||||
text_input: text_input::default,
|
|
||||||
menu: menu::Style::default(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ where
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::with_style(content, Style::default().0)
|
Self::with_style(content, Theme::default_style())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a [`Container`] with the given content and style.
|
/// Creates a [`Container`] with the given content and style.
|
||||||
|
|
@ -71,7 +71,7 @@ where
|
||||||
vertical_alignment: alignment::Vertical::Top,
|
vertical_alignment: alignment::Vertical::Top,
|
||||||
clip: false,
|
clip: false,
|
||||||
content,
|
content,
|
||||||
style: Style(style),
|
style,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,7 +137,7 @@ where
|
||||||
|
|
||||||
/// Sets the style of the [`Container`].
|
/// Sets the style of the [`Container`].
|
||||||
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ where
|
||||||
Status::Idle
|
Status::Idle
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = (self.style.0)(theme, status);
|
let style = (self.style)(theme, status);
|
||||||
|
|
||||||
if let Some(clipped_viewport) = bounds.intersection(viewport) {
|
if let Some(clipped_viewport) = bounds.intersection(viewport) {
|
||||||
draw_background(renderer, &style, bounds);
|
draw_background(renderer, &style, bounds);
|
||||||
|
|
@ -546,40 +546,23 @@ pub enum Status {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Container`].
|
/// The style of a [`Container`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Style<Theme> {
|
/// The default style of a [`Container`].
|
||||||
/// Resolves the [`Style`] with the given `Theme` and [`Status`] to
|
pub trait DefaultStyle {
|
||||||
/// produce an [`Appearance`].
|
/// Returns the default style of a [`Container`].
|
||||||
pub fn resolve(self, theme: &Theme, status: Status) -> Appearance {
|
fn default_style() -> Style<Self>;
|
||||||
(self.0)(theme, status)
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
transparent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
impl DefaultStyle for Appearance {
|
||||||
fn clone(&self) -> Self {
|
fn default_style() -> Style<Self> {
|
||||||
*self
|
|appearance, _status| *appearance
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
|
||||||
|
|
||||||
impl Default for Style<Theme> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Style(transparent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Style<Appearance> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Style(|appearance, _status| *appearance)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ pub fn container<'a, Message, Theme, Renderer>(
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Container<'a, Message, Theme, Renderer>
|
) -> Container<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: container::DefaultStyle,
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
container::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Container::new(content)
|
Container::new(content)
|
||||||
}
|
}
|
||||||
|
|
@ -104,8 +104,8 @@ pub fn scrollable<'a, Message, Theme, Renderer>(
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Scrollable<'a, Message, Theme, Renderer>
|
) -> Scrollable<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: scrollable::DefaultStyle,
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
scrollable::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Scrollable::new(content)
|
Scrollable::new(content)
|
||||||
}
|
}
|
||||||
|
|
@ -117,8 +117,8 @@ pub fn button<'a, Message, Theme, Renderer>(
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Button<'a, Message, Theme, Renderer>
|
) -> Button<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: button::DefaultStyle,
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
button::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Button::new(content)
|
Button::new(content)
|
||||||
}
|
}
|
||||||
|
|
@ -134,8 +134,8 @@ pub fn tooltip<'a, Message, Theme, Renderer>(
|
||||||
position: tooltip::Position,
|
position: tooltip::Position,
|
||||||
) -> crate::Tooltip<'a, Message, Theme, Renderer>
|
) -> crate::Tooltip<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: container::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
container::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Tooltip::new(content, tooltip, position)
|
Tooltip::new(content, tooltip, position)
|
||||||
}
|
}
|
||||||
|
|
@ -160,8 +160,8 @@ pub fn checkbox<'a, Message, Theme, Renderer>(
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
) -> Checkbox<'a, Message, Theme, Renderer>
|
) -> Checkbox<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: checkbox::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
checkbox::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Checkbox::new(label, is_checked)
|
Checkbox::new(label, is_checked)
|
||||||
}
|
}
|
||||||
|
|
@ -177,9 +177,9 @@ pub fn radio<Message, Theme, Renderer, V>(
|
||||||
) -> Radio<Message, Theme, Renderer>
|
) -> Radio<Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
|
Theme: radio::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
V: Copy + Eq,
|
V: Copy + Eq,
|
||||||
radio::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Radio::new(label, value, selected, on_click)
|
Radio::new(label, value, selected, on_click)
|
||||||
}
|
}
|
||||||
|
|
@ -193,8 +193,8 @@ pub fn toggler<'a, Message, Theme, Renderer>(
|
||||||
f: impl Fn(bool) -> Message + 'a,
|
f: impl Fn(bool) -> Message + 'a,
|
||||||
) -> Toggler<'a, Message, Theme, Renderer>
|
) -> Toggler<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
|
Theme: toggler::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
toggler::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
Toggler::new(label, is_checked, f)
|
Toggler::new(label, is_checked, f)
|
||||||
}
|
}
|
||||||
|
|
@ -208,8 +208,8 @@ pub fn text_input<'a, Message, Theme, Renderer>(
|
||||||
) -> TextInput<'a, Message, Theme, Renderer>
|
) -> TextInput<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
|
Theme: text_input::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
text_input::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
TextInput::new(placeholder, value)
|
TextInput::new(placeholder, value)
|
||||||
}
|
}
|
||||||
|
|
@ -222,8 +222,8 @@ pub fn text_editor<Message, Theme, Renderer>(
|
||||||
) -> TextEditor<'_, core::text::highlighter::PlainText, Message, Theme, Renderer>
|
) -> TextEditor<'_, core::text::highlighter::PlainText, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
|
Theme: text_editor::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
text_editor::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
TextEditor::new(content)
|
TextEditor::new(content)
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +239,7 @@ pub fn slider<'a, T, Message, Theme>(
|
||||||
where
|
where
|
||||||
T: Copy + From<u8> + std::cmp::PartialOrd,
|
T: Copy + From<u8> + std::cmp::PartialOrd,
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
slider::Style<Theme>: Default,
|
Theme: slider::DefaultStyle,
|
||||||
{
|
{
|
||||||
Slider::new(range, value, on_change)
|
Slider::new(range, value, on_change)
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +255,7 @@ pub fn vertical_slider<'a, T, Message, Theme>(
|
||||||
where
|
where
|
||||||
T: Copy + From<u8> + std::cmp::PartialOrd,
|
T: Copy + From<u8> + std::cmp::PartialOrd,
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
vertical_slider::Style<Theme>: Default,
|
Theme: vertical_slider::DefaultStyle,
|
||||||
{
|
{
|
||||||
VerticalSlider::new(range, value, on_change)
|
VerticalSlider::new(range, value, on_change)
|
||||||
}
|
}
|
||||||
|
|
@ -273,8 +273,8 @@ where
|
||||||
L: Borrow<[T]> + 'a,
|
L: Borrow<[T]> + 'a,
|
||||||
V: Borrow<T> + 'a,
|
V: Borrow<T> + 'a,
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
|
Theme: pick_list::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
pick_list::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
PickList::new(options, selected, on_selected)
|
PickList::new(options, selected, on_selected)
|
||||||
}
|
}
|
||||||
|
|
@ -290,8 +290,8 @@ pub fn combo_box<'a, T, Message, Theme, Renderer>(
|
||||||
) -> ComboBox<'a, T, Message, Theme, Renderer>
|
) -> ComboBox<'a, T, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
T: std::fmt::Display + Clone,
|
T: std::fmt::Display + Clone,
|
||||||
|
Theme: combo_box::DefaultStyle,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
combo_box::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
ComboBox::new(state, placeholder, selection, on_selected)
|
ComboBox::new(state, placeholder, selection, on_selected)
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +317,7 @@ pub fn vertical_space() -> Space {
|
||||||
/// [`Rule`]: crate::Rule
|
/// [`Rule`]: crate::Rule
|
||||||
pub fn horizontal_rule<Theme>(height: impl Into<Pixels>) -> Rule<Theme>
|
pub fn horizontal_rule<Theme>(height: impl Into<Pixels>) -> Rule<Theme>
|
||||||
where
|
where
|
||||||
rule::Style<Theme>: Default,
|
Theme: rule::DefaultStyle,
|
||||||
{
|
{
|
||||||
Rule::horizontal(height)
|
Rule::horizontal(height)
|
||||||
}
|
}
|
||||||
|
|
@ -327,7 +327,7 @@ where
|
||||||
/// [`Rule`]: crate::Rule
|
/// [`Rule`]: crate::Rule
|
||||||
pub fn vertical_rule<Theme>(width: impl Into<Pixels>) -> Rule<Theme>
|
pub fn vertical_rule<Theme>(width: impl Into<Pixels>) -> Rule<Theme>
|
||||||
where
|
where
|
||||||
rule::Style<Theme>: Default,
|
Theme: rule::DefaultStyle,
|
||||||
{
|
{
|
||||||
Rule::vertical(width)
|
Rule::vertical(width)
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +344,7 @@ pub fn progress_bar<Theme>(
|
||||||
value: f32,
|
value: f32,
|
||||||
) -> ProgressBar<Theme>
|
) -> ProgressBar<Theme>
|
||||||
where
|
where
|
||||||
progress_bar::Style<Theme>: Default,
|
Theme: progress_bar::DefaultStyle,
|
||||||
{
|
{
|
||||||
ProgressBar::new(range, value)
|
ProgressBar::new(range, value)
|
||||||
}
|
}
|
||||||
|
|
@ -364,7 +364,7 @@ pub fn image<Handle>(handle: impl Into<Handle>) -> crate::Image<Handle> {
|
||||||
#[cfg(feature = "svg")]
|
#[cfg(feature = "svg")]
|
||||||
pub fn svg<Theme>(handle: impl Into<core::svg::Handle>) -> crate::Svg<Theme>
|
pub fn svg<Theme>(handle: impl Into<core::svg::Handle>) -> crate::Svg<Theme>
|
||||||
where
|
where
|
||||||
crate::svg::Style<Theme>: Default,
|
Theme: crate::svg::DefaultStyle,
|
||||||
{
|
{
|
||||||
crate::Svg::new(handle)
|
crate::Svg::new(handle)
|
||||||
}
|
}
|
||||||
|
|
@ -390,7 +390,7 @@ where
|
||||||
#[cfg(feature = "qr_code")]
|
#[cfg(feature = "qr_code")]
|
||||||
pub fn qr_code<Theme>(data: &crate::qr_code::Data) -> crate::QRCode<'_, Theme>
|
pub fn qr_code<Theme>(data: &crate::qr_code::Data) -> crate::QRCode<'_, Theme>
|
||||||
where
|
where
|
||||||
crate::qr_code::Style<Theme>: Default,
|
Theme: crate::qr_code::DefaultStyle,
|
||||||
{
|
{
|
||||||
crate::QRCode::new(data)
|
crate::QRCode::new(data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ where
|
||||||
on_option_hovered: Option<&'a dyn Fn(T) -> Message>,
|
on_option_hovered: Option<&'a dyn Fn(T) -> Message>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::with_style(
|
Self::with_style(
|
||||||
state,
|
state,
|
||||||
|
|
@ -66,7 +66,7 @@ where
|
||||||
hovered_option,
|
hovered_option,
|
||||||
on_selected,
|
on_selected,
|
||||||
on_option_hovered,
|
on_option_hovered,
|
||||||
Style::default(),
|
Theme::default_style(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ where
|
||||||
text_line_height,
|
text_line_height,
|
||||||
text_shaping,
|
text_shaping,
|
||||||
padding,
|
padding,
|
||||||
style: style.menu,
|
style: style.list,
|
||||||
},
|
},
|
||||||
scrollable::Direction::default(),
|
scrollable::Direction::default(),
|
||||||
style.scrollable,
|
style.scrollable,
|
||||||
|
|
@ -327,7 +327,7 @@ where
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
let appearance = (self.style.menu)(theme);
|
let appearance = (self.style.list)(theme);
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -598,15 +598,23 @@ pub struct Appearance {
|
||||||
pub selected_background: Background,
|
pub selected_background: Background,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The definiton of the default style of a [`Menu`].
|
/// The style of the different parts of a [`Menu`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Style<Theme> {
|
pub struct Style<Theme> {
|
||||||
/// The style of the [`Menu`].
|
/// The style of the list of the [`Menu`].
|
||||||
menu: fn(&Theme) -> Appearance,
|
list: fn(&Theme) -> Appearance,
|
||||||
/// The style of the [`Scrollable`] of the [`Menu`].
|
/// The style of the [`Scrollable`] of the [`Menu`].
|
||||||
scrollable: fn(&Theme, scrollable::Status) -> scrollable::Appearance,
|
scrollable: fn(&Theme, scrollable::Status) -> scrollable::Appearance,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Style<Theme> {
|
||||||
|
/// The default style of a [`Menu`] with the built-in [`Theme`].
|
||||||
|
pub const DEFAULT: Self = Self {
|
||||||
|
list: default,
|
||||||
|
scrollable: scrollable::default,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
impl<Theme> Clone for Style<Theme> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
|
|
@ -615,16 +623,19 @@ impl<Theme> Clone for Style<Theme> {
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl<Theme> Copy for Style<Theme> {}
|
||||||
|
|
||||||
impl Default for Style<Theme> {
|
/// The default style of a [`Menu`].
|
||||||
fn default() -> Self {
|
pub trait DefaultStyle: Sized {
|
||||||
Self {
|
/// Returns the default style of a [`Menu`].
|
||||||
menu: default,
|
fn default_style() -> Style<Self>;
|
||||||
scrollable: scrollable::default,
|
}
|
||||||
}
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
Style::<Theme>::DEFAULT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default style of a [`Menu`].
|
/// The default style of the list of a [`Menu`].
|
||||||
pub fn default(theme: &Theme) -> Appearance {
|
pub fn default(theme: &Theme) -> Appearance {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ where
|
||||||
view: impl Fn(Pane, &'a T, bool) -> Content<'a, Message, Theme, Renderer>,
|
view: impl Fn(Pane, &'a T, bool) -> Content<'a, Message, Theme, Renderer>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
let contents = if let Some((pane, pane_state)) =
|
let contents = if let Some((pane, pane_state)) =
|
||||||
state.maximized.and_then(|pane| {
|
state.maximized.and_then(|pane| {
|
||||||
|
|
@ -158,7 +158,7 @@ where
|
||||||
on_click: None,
|
on_click: None,
|
||||||
on_drag: None,
|
on_drag: None,
|
||||||
on_resize: None,
|
on_resize: None,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +219,7 @@ where
|
||||||
|
|
||||||
/// Sets the style of the [`PaneGrid`].
|
/// Sets the style of the [`PaneGrid`].
|
||||||
pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -677,7 +677,7 @@ where
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme);
|
let appearance = (self.style)(theme);
|
||||||
|
|
||||||
for ((id, (content, tree)), pane_layout) in
|
for ((id, (content, tree)), pane_layout) in
|
||||||
contents.zip(layout.children())
|
contents.zip(layout.children())
|
||||||
|
|
@ -1146,26 +1146,23 @@ pub struct Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`PaneGrid`].
|
/// The style of a [`PaneGrid`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`PaneGrid`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`PaneGrid`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@ where
|
||||||
/// Creates a new [`Content`] with the provided body.
|
/// Creates a new [`Content`] with the provided body.
|
||||||
pub fn new(body: impl Into<Element<'a, Message, Theme, Renderer>>) -> Self
|
pub fn new(body: impl Into<Element<'a, Message, Theme, Renderer>>) -> Self
|
||||||
where
|
where
|
||||||
container::Style<Theme>: Default,
|
Theme: container::DefaultStyle,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
title_bar: None,
|
title_bar: None,
|
||||||
body: body.into(),
|
body: body.into(),
|
||||||
style: container::Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ where
|
||||||
container::Status::Idle
|
container::Status::Idle
|
||||||
};
|
};
|
||||||
|
|
||||||
self.style.resolve(theme, status)
|
(self.style)(theme, status)
|
||||||
};
|
};
|
||||||
|
|
||||||
container::draw_background(renderer, &style, bounds);
|
container::draw_background(renderer, &style, bounds);
|
||||||
|
|
@ -403,8 +403,8 @@ impl<'a, T, Message, Theme, Renderer> From<T>
|
||||||
for Content<'a, Message, Theme, Renderer>
|
for Content<'a, Message, Theme, Renderer>
|
||||||
where
|
where
|
||||||
T: Into<Element<'a, Message, Theme, Renderer>>,
|
T: Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
|
Theme: container::DefaultStyle,
|
||||||
Renderer: crate::core::Renderer,
|
Renderer: crate::core::Renderer,
|
||||||
container::Style<Theme>: Default,
|
|
||||||
{
|
{
|
||||||
fn from(element: T) -> Self {
|
fn from(element: T) -> Self {
|
||||||
Self::new(element)
|
Self::new(element)
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,14 @@ where
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
container::Style<Theme>: Default,
|
Theme: container::DefaultStyle,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
controls: None,
|
controls: None,
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
always_show_controls: false,
|
always_show_controls: false,
|
||||||
style: container::Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,7 +138,7 @@ where
|
||||||
container::Status::Idle
|
container::Status::Idle
|
||||||
};
|
};
|
||||||
|
|
||||||
self.style.resolve(theme, status)
|
(self.style)(theme, status)
|
||||||
};
|
};
|
||||||
|
|
||||||
let inherited_style = renderer::Style {
|
let inherited_style = renderer::Style {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ where
|
||||||
on_select: impl Fn(T) -> Message + 'a,
|
on_select: impl Fn(T) -> Message + 'a,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
on_select: Box::new(on_select),
|
on_select: Box::new(on_select),
|
||||||
|
|
@ -85,7 +85,7 @@ where
|
||||||
text_shaping: text::Shaping::Basic,
|
text_shaping: text::Shaping::Basic,
|
||||||
font: None,
|
font: None,
|
||||||
handle: Handle::default(),
|
handle: Handle::default(),
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ where
|
||||||
Status::Active
|
Status::Active
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.pick_list)(theme, status);
|
let appearance = (self.style.field)(theme, status);
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -737,16 +737,24 @@ pub struct Appearance {
|
||||||
pub border: Border,
|
pub border: Border,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The different styles of a [`PickList`].
|
/// The styles of the different parts of a [`PickList`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct Style<Theme> {
|
pub struct Style<Theme> {
|
||||||
/// The style of the [`PickList`] itself.
|
/// The style of the [`PickList`] itself.
|
||||||
pub pick_list: fn(&Theme, Status) -> Appearance,
|
pub field: fn(&Theme, Status) -> Appearance,
|
||||||
|
|
||||||
/// The style of the [`Menu`] of the pick list.
|
/// The style of the [`Menu`] of the pick list.
|
||||||
pub menu: menu::Style<Theme>,
|
pub menu: menu::Style<Theme>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Style<Theme> {
|
||||||
|
/// The default style of a [`PickList`] with the built-in [`Theme`].
|
||||||
|
pub const DEFAULT: Self = Self {
|
||||||
|
field: default,
|
||||||
|
menu: menu::Style::<Theme>::DEFAULT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
impl<Theme> Clone for Style<Theme> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
*self
|
*self
|
||||||
|
|
@ -755,16 +763,19 @@ impl<Theme> Clone for Style<Theme> {
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl<Theme> Copy for Style<Theme> {}
|
||||||
|
|
||||||
impl Default for Style<Theme> {
|
/// The default style of a [`PickList`].
|
||||||
fn default() -> Self {
|
pub trait DefaultStyle: Sized {
|
||||||
Self {
|
/// Returns the default style of a [`PickList`].
|
||||||
pick_list: default,
|
fn default_style() -> Style<Self>;
|
||||||
menu: menu::Style::default(),
|
}
|
||||||
}
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
Style::<Self>::DEFAULT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default style of a [`PickList`].
|
/// The default style of the field of a [`PickList`].
|
||||||
pub fn default(theme: &Theme, status: Status) -> Appearance {
|
pub fn default(theme: &Theme, status: Status) -> Appearance {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,14 @@ impl<Theme> ProgressBar<Theme> {
|
||||||
/// * the current value of the [`ProgressBar`]
|
/// * the current value of the [`ProgressBar`]
|
||||||
pub fn new(range: RangeInclusive<f32>, value: f32) -> Self
|
pub fn new(range: RangeInclusive<f32>, value: f32) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
ProgressBar {
|
ProgressBar {
|
||||||
value: value.clamp(*range.start(), *range.end()),
|
value: value.clamp(*range.start(), *range.end()),
|
||||||
range,
|
range,
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: None,
|
height: None,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ where
|
||||||
/ (range_end - range_start)
|
/ (range_end - range_start)
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme);
|
let appearance = (self.style)(theme);
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -169,26 +169,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`ProgressBar`].
|
/// The style of a [`ProgressBar`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`ProgressBar`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`ProgressBar`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
primary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(primary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ impl<'a, Theme> QRCode<'a, Theme> {
|
||||||
/// Creates a new [`QRCode`] with the provided [`Data`].
|
/// Creates a new [`QRCode`] with the provided [`Data`].
|
||||||
pub fn new(data: &'a Data) -> Self
|
pub fn new(data: &'a Data) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
data,
|
data,
|
||||||
cell_size: DEFAULT_CELL_SIZE,
|
cell_size: DEFAULT_CELL_SIZE,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ impl<'a, Message, Theme> Widget<Message, Theme, Renderer>
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let side_length = self.data.width + 2 * QUIET_ZONE;
|
let side_length = self.data.width + 2 * QUIET_ZONE;
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme);
|
let appearance = (self.style)(theme);
|
||||||
let mut last_appearance = state.last_appearance.borrow_mut();
|
let mut last_appearance = state.last_appearance.borrow_mut();
|
||||||
|
|
||||||
if Some(appearance) != *last_appearance {
|
if Some(appearance) != *last_appearance {
|
||||||
|
|
@ -336,26 +336,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`QRCode`].
|
/// The style of a [`QRCode`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`QRCode`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`QRCode`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ where
|
||||||
f: F,
|
f: F,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
V: Eq + Copy,
|
V: Eq + Copy,
|
||||||
F: FnOnce(V) -> Message,
|
F: FnOnce(V) -> Message,
|
||||||
{
|
{
|
||||||
|
|
@ -125,7 +125,7 @@ where
|
||||||
text_line_height: text::LineHeight::default(),
|
text_line_height: text::LineHeight::default(),
|
||||||
text_shaping: text::Shaping::Basic,
|
text_shaping: text::Shaping::Basic,
|
||||||
font: None,
|
font: None,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,7 +176,7 @@ where
|
||||||
|
|
||||||
/// Sets the style of the [`Radio`] button.
|
/// Sets the style of the [`Radio`] button.
|
||||||
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +297,7 @@ where
|
||||||
Status::Active { is_selected }
|
Status::Active { is_selected }
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
{
|
{
|
||||||
let layout = children.next().unwrap();
|
let layout = children.next().unwrap();
|
||||||
|
|
@ -398,26 +398,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Radio`] button.
|
/// The style of a [`Radio`] button.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Radio`] button.
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Radio`] button.
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,32 +21,32 @@ impl<Theme> Rule<Theme> {
|
||||||
/// Creates a horizontal [`Rule`] with the given height.
|
/// Creates a horizontal [`Rule`] with the given height.
|
||||||
pub fn horizontal(height: impl Into<Pixels>) -> Self
|
pub fn horizontal(height: impl Into<Pixels>) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Fixed(height.into().0),
|
height: Length::Fixed(height.into().0),
|
||||||
is_horizontal: true,
|
is_horizontal: true,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a vertical [`Rule`] with the given width.
|
/// Creates a vertical [`Rule`] with the given width.
|
||||||
pub fn vertical(width: impl Into<Pixels>) -> Self
|
pub fn vertical(width: impl Into<Pixels>) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Rule {
|
Rule {
|
||||||
width: Length::Fixed(width.into().0),
|
width: Length::Fixed(width.into().0),
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
is_horizontal: false,
|
is_horizontal: false,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the style of the [`Rule`].
|
/// Sets the style of the [`Rule`].
|
||||||
pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,7 +82,7 @@ where
|
||||||
_viewport: &Rectangle,
|
_viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let appearance = (self.style.0)(theme);
|
let appearance = (self.style)(theme);
|
||||||
|
|
||||||
let bounds = if self.is_horizontal {
|
let bounds = if self.is_horizontal {
|
||||||
let line_y = (bounds.y + (bounds.height / 2.0)
|
let line_y = (bounds.y + (bounds.height / 2.0)
|
||||||
|
|
@ -216,26 +216,23 @@ impl FillMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Rule`].
|
/// The style of a [`Rule`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Rule`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Rule`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ where
|
||||||
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
content: impl Into<Element<'a, Message, Theme, Renderer>>,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::with_direction(content, Direction::default())
|
Self::with_direction(content, Direction::default())
|
||||||
}
|
}
|
||||||
|
|
@ -59,9 +59,13 @@ where
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::with_direction_and_style(content, direction, Style::default().0)
|
Self::with_direction_and_style(
|
||||||
|
content,
|
||||||
|
direction,
|
||||||
|
Theme::default_style(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`Scrollable`] with the given [`Direction`] and style.
|
/// Creates a new [`Scrollable`] with the given [`Direction`] and style.
|
||||||
|
|
@ -407,7 +411,7 @@ where
|
||||||
Status::Active
|
Status::Active
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
container::draw_background(
|
container::draw_background(
|
||||||
renderer,
|
renderer,
|
||||||
|
|
@ -1662,26 +1666,23 @@ pub struct Scroller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Scrollable`].
|
/// The style of a [`Scrollable`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Scrollable`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Scrollable`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ where
|
||||||
/// `Message`.
|
/// `Message`.
|
||||||
pub fn new<F>(range: RangeInclusive<T>, value: T, on_change: F) -> Self
|
pub fn new<F>(range: RangeInclusive<T>, value: T, on_change: F) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
F: 'a + Fn(T) -> Message,
|
F: 'a + Fn(T) -> Message,
|
||||||
{
|
{
|
||||||
let value = if value >= *range.start() {
|
let value = if value >= *range.start() {
|
||||||
|
|
@ -95,7 +95,7 @@ where
|
||||||
on_release: None,
|
on_release: None,
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Self::DEFAULT_HEIGHT,
|
height: Self::DEFAULT_HEIGHT,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,7 +346,7 @@ where
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let is_mouse_over = cursor.is_over(bounds);
|
let is_mouse_over = cursor.is_over(bounds);
|
||||||
|
|
||||||
let style = (self.style.0)(
|
let style = (self.style)(
|
||||||
theme,
|
theme,
|
||||||
if state.is_dragging {
|
if state.is_dragging {
|
||||||
Status::Dragged
|
Status::Dragged
|
||||||
|
|
@ -547,26 +547,23 @@ pub enum HandleShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Slider`].
|
/// The style of a [`Slider`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(pub(crate) fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Slider`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Slider`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ impl<Theme> Svg<Theme> {
|
||||||
/// Creates a new [`Svg`] from the given [`Handle`].
|
/// Creates a new [`Svg`] from the given [`Handle`].
|
||||||
pub fn new(handle: impl Into<Handle>) -> Self
|
pub fn new(handle: impl Into<Handle>) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Svg {
|
Svg {
|
||||||
handle: handle.into(),
|
handle: handle.into(),
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
content_fit: ContentFit::Contain,
|
content_fit: ContentFit::Contain,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl<Theme> Svg<Theme> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn from_path(path: impl Into<PathBuf>) -> Self
|
pub fn from_path(path: impl Into<PathBuf>) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::new(Handle::from_path(path))
|
Self::new(Handle::from_path(path))
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ impl<Theme> Svg<Theme> {
|
||||||
/// Sets the style variant of this [`Svg`].
|
/// Sets the style variant of this [`Svg`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
pub fn style(mut self, style: fn(&Theme, Status) -> Appearance) -> Self {
|
||||||
self.style = Style(style);
|
self.style = style;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ where
|
||||||
Status::Idle
|
Status::Idle
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
renderer.draw(
|
renderer.draw(
|
||||||
self.handle.clone(),
|
self.handle.clone(),
|
||||||
|
|
@ -214,25 +214,22 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of an [`Svg`].
|
/// The style of an [`Svg`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of an [`Svg`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of an [`Svg`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
|_theme, _status| Appearance::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(|_, _| Appearance::default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ where
|
||||||
/// Creates new [`TextEditor`] with the given [`Content`].
|
/// Creates new [`TextEditor`] with the given [`Content`].
|
||||||
pub fn new(content: &'a Content<Renderer>) -> Self
|
pub fn new(content: &'a Content<Renderer>) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
content,
|
content,
|
||||||
|
|
@ -68,7 +68,7 @@ where
|
||||||
width: Length::Fill,
|
width: Length::Fill,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
padding: Padding::new(5.0),
|
padding: Padding::new(5.0),
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
on_edit: None,
|
on_edit: None,
|
||||||
highlighter_settings: (),
|
highlighter_settings: (),
|
||||||
highlighter_format: |_highlight, _theme| {
|
highlighter_format: |_highlight, _theme| {
|
||||||
|
|
@ -505,7 +505,7 @@ where
|
||||||
Status::Active
|
Status::Active
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -809,26 +809,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`TextEditor`].
|
/// The style of a [`TextEditor`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`TextEditor`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`TextEditor`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,9 @@ where
|
||||||
/// its current value.
|
/// its current value.
|
||||||
pub fn new(placeholder: &str, value: &str) -> Self
|
pub fn new(placeholder: &str, value: &str) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
Self::with_style(placeholder, value, Style::default().0)
|
Self::with_style(placeholder, value, Theme::default_style())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`TextInput`] with the given placeholder,
|
/// Creates a new [`TextInput`] with the given placeholder,
|
||||||
|
|
@ -342,7 +342,7 @@ where
|
||||||
Status::Active
|
Status::Active
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::Quad {
|
renderer::Quad {
|
||||||
|
|
@ -1412,26 +1412,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`TextInput`].
|
/// The style of a [`TextInput`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`TextInput`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`TextInput`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ where
|
||||||
f: F,
|
f: F,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
F: 'a + Fn(bool) -> Message,
|
F: 'a + Fn(bool) -> Message,
|
||||||
{
|
{
|
||||||
Toggler {
|
Toggler {
|
||||||
|
|
@ -87,7 +87,7 @@ where
|
||||||
text_shaping: text::Shaping::Basic,
|
text_shaping: text::Shaping::Basic,
|
||||||
spacing: Self::DEFAULT_SIZE / 2.0,
|
spacing: Self::DEFAULT_SIZE / 2.0,
|
||||||
font: None,
|
font: None,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,7 +299,7 @@ where
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let appearance = (self.style.0)(theme, status);
|
let appearance = (self.style)(theme, status);
|
||||||
|
|
||||||
let border_radius = bounds.height / BORDER_RADIUS_RATIO;
|
let border_radius = bounds.height / BORDER_RADIUS_RATIO;
|
||||||
let space = SPACE_RATIO * bounds.height;
|
let space = SPACE_RATIO * bounds.height;
|
||||||
|
|
@ -398,26 +398,23 @@ pub struct Appearance {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of a [`Toggler`].
|
/// The style of a [`Toggler`].
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub type Style<Theme> = fn(&Theme, Status) -> Appearance;
|
||||||
pub struct Style<Theme>(fn(&Theme, Status) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
/// The default style of a [`Toggler`].
|
||||||
fn clone(&self) -> Self {
|
pub trait DefaultStyle {
|
||||||
*self
|
/// Returns the default style of a [`Toggler`].
|
||||||
|
fn default_style() -> Style<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
|
default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
impl DefaultStyle for Appearance {
|
||||||
|
fn default_style() -> Style<Self> {
|
||||||
impl Default for Style<Theme> {
|
|appearance, _status| *appearance
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme, Status) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme, Status) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ where
|
||||||
position: Position,
|
position: Position,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
container::Style<Theme>: Default,
|
Theme: container::DefaultStyle,
|
||||||
{
|
{
|
||||||
Tooltip {
|
Tooltip {
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
|
|
@ -56,7 +56,7 @@ where
|
||||||
gap: 0.0,
|
gap: 0.0,
|
||||||
padding: Self::DEFAULT_PADDING,
|
padding: Self::DEFAULT_PADDING,
|
||||||
snap_within_viewport: true,
|
snap_within_viewport: true,
|
||||||
style: container::Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -424,7 +424,7 @@ where
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: mouse::Cursor,
|
cursor_position: mouse::Cursor,
|
||||||
) {
|
) {
|
||||||
let style = self.style.resolve(theme, container::Status::Idle);
|
let style = (self.style)(theme, container::Status::Idle);
|
||||||
|
|
||||||
container::draw_background(renderer, &style, layout.bounds());
|
container::draw_background(renderer, &style, layout.bounds());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
pub use crate::slider::{
|
pub use crate::slider::{
|
||||||
default, Appearance, Handle, HandleShape, Status, Style,
|
default, Appearance, DefaultStyle, Handle, HandleShape, Status, Style,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::core;
|
use crate::core;
|
||||||
|
|
@ -72,7 +72,7 @@ where
|
||||||
/// `Message`.
|
/// `Message`.
|
||||||
pub fn new<F>(range: RangeInclusive<T>, value: T, on_change: F) -> Self
|
pub fn new<F>(range: RangeInclusive<T>, value: T, on_change: F) -> Self
|
||||||
where
|
where
|
||||||
Style<Theme>: Default,
|
Theme: DefaultStyle,
|
||||||
F: 'a + Fn(T) -> Message,
|
F: 'a + Fn(T) -> Message,
|
||||||
{
|
{
|
||||||
let value = if value >= *range.start() {
|
let value = if value >= *range.start() {
|
||||||
|
|
@ -97,7 +97,7 @@ where
|
||||||
on_release: None,
|
on_release: None,
|
||||||
width: Self::DEFAULT_WIDTH,
|
width: Self::DEFAULT_WIDTH,
|
||||||
height: Length::Fill,
|
height: Length::Fill,
|
||||||
style: Style::default(),
|
style: Theme::default_style(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +351,7 @@ where
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
let is_mouse_over = cursor.is_over(bounds);
|
let is_mouse_over = cursor.is_over(bounds);
|
||||||
|
|
||||||
let style = (self.style.0)(
|
let style = (self.style)(
|
||||||
theme,
|
theme,
|
||||||
if state.is_dragging {
|
if state.is_dragging {
|
||||||
Status::Dragged
|
Status::Dragged
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ use std::sync::Arc;
|
||||||
/// can be toggled by pressing `F12`.
|
/// can be toggled by pressing `F12`.
|
||||||
pub trait Application: Program
|
pub trait Application: Program
|
||||||
where
|
where
|
||||||
Style<Self::Theme>: Default,
|
Self::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
/// The data needed to initialize your [`Application`].
|
/// The data needed to initialize your [`Application`].
|
||||||
type Flags;
|
type Flags;
|
||||||
|
|
@ -64,7 +64,7 @@ where
|
||||||
|
|
||||||
/// Returns the `Style` variation of the `Theme`.
|
/// Returns the `Style` variation of the `Theme`.
|
||||||
fn style(&self, theme: &Self::Theme) -> Appearance {
|
fn style(&self, theme: &Self::Theme) -> Appearance {
|
||||||
Style::default().resolve(theme)
|
theme.default_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event `Subscription` for the current state of the
|
/// Returns the event `Subscription` for the current state of the
|
||||||
|
|
@ -104,39 +104,19 @@ pub struct Appearance {
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The style of an [`Application`].
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
pub struct Style<Theme>(pub fn(&Theme) -> Appearance);
|
|
||||||
|
|
||||||
impl<Theme> Style<Theme> {
|
|
||||||
/// Resolves the [`Style`] with the given `Theme` to produce
|
|
||||||
/// an [`Appearance`].
|
|
||||||
pub fn resolve(self, theme: &Theme) -> Appearance {
|
|
||||||
(self.0)(theme)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> Clone for Style<Theme> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
*self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Theme> Copy for Style<Theme> {}
|
|
||||||
|
|
||||||
impl<Theme> From<fn(&Theme) -> Appearance> for Style<Theme> {
|
|
||||||
fn from(f: fn(&Theme) -> Appearance) -> Self {
|
|
||||||
Style(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Style<Theme> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Style(default)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The default style of an [`Application`].
|
/// The default style of an [`Application`].
|
||||||
|
pub trait DefaultStyle {
|
||||||
|
/// Returns the default style of an [`Application`].
|
||||||
|
fn default_style(&self) -> Appearance;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultStyle for Theme {
|
||||||
|
fn default_style(&self) -> Appearance {
|
||||||
|
default(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The default [`Appearance`] of an [`Application`] with the built-in [`Theme`].
|
||||||
pub fn default(theme: &Theme) -> Appearance {
|
pub fn default(theme: &Theme) -> Appearance {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
|
|
@ -156,7 +136,7 @@ where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use futures::task;
|
use futures::task;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
@ -340,7 +320,7 @@ async fn run_instance<A, E, C>(
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use winit::event;
|
use winit::event;
|
||||||
|
|
@ -663,7 +643,7 @@ pub fn build_user_interface<'a, A: Application>(
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
|
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
|
||||||
where
|
where
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
debug.view_started();
|
debug.view_started();
|
||||||
let view = application.view();
|
let view = application.view();
|
||||||
|
|
@ -694,7 +674,7 @@ pub fn update<A: Application, C, E: Executor>(
|
||||||
window: &winit::window::Window,
|
window: &winit::window::Window,
|
||||||
) where
|
) where
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
for message in messages.drain(..) {
|
for message in messages.drain(..) {
|
||||||
debug.log_message(&message);
|
debug.log_message(&message);
|
||||||
|
|
@ -745,7 +725,7 @@ pub fn run_command<A, C, E>(
|
||||||
A: Application,
|
A: Application,
|
||||||
E: Executor,
|
E: Executor,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use crate::runtime::command;
|
use crate::runtime::command;
|
||||||
use crate::runtime::system;
|
use crate::runtime::system;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use winit::window::Window;
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct State<A: Application>
|
pub struct State<A: Application>
|
||||||
where
|
where
|
||||||
application::Style<A::Theme>: Default,
|
A::Theme: application::DefaultStyle,
|
||||||
{
|
{
|
||||||
title: String,
|
title: String,
|
||||||
scale_factor: f64,
|
scale_factor: f64,
|
||||||
|
|
@ -29,7 +29,7 @@ where
|
||||||
|
|
||||||
impl<A: Application> State<A>
|
impl<A: Application> State<A>
|
||||||
where
|
where
|
||||||
application::Style<A::Theme>: Default,
|
A::Theme: application::DefaultStyle,
|
||||||
{
|
{
|
||||||
/// Creates a new [`State`] for the provided [`Application`] and window.
|
/// Creates a new [`State`] for the provided [`Application`] and window.
|
||||||
pub fn new(application: &A, window: &Window) -> Self {
|
pub fn new(application: &A, window: &Window) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use crate::runtime::user_interface::{self, UserInterface};
|
||||||
use crate::runtime::Debug;
|
use crate::runtime::Debug;
|
||||||
use crate::{Clipboard, Error, Proxy, Settings};
|
use crate::{Clipboard, Error, Proxy, Settings};
|
||||||
|
|
||||||
pub use crate::application::{default, Appearance, Style};
|
pub use crate::application::{default, Appearance, DefaultStyle};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::mem::ManuallyDrop;
|
use std::mem::ManuallyDrop;
|
||||||
|
|
@ -42,7 +42,7 @@ use std::time::Instant;
|
||||||
/// can be toggled by pressing `F12`.
|
/// can be toggled by pressing `F12`.
|
||||||
pub trait Application: Program
|
pub trait Application: Program
|
||||||
where
|
where
|
||||||
Style<Self::Theme>: Default,
|
Self::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
/// The data needed to initialize your [`Application`].
|
/// The data needed to initialize your [`Application`].
|
||||||
type Flags;
|
type Flags;
|
||||||
|
|
@ -68,7 +68,7 @@ where
|
||||||
|
|
||||||
/// Returns the `Style` variation of the `Theme`.
|
/// Returns the `Style` variation of the `Theme`.
|
||||||
fn style(&self, theme: &Self::Theme) -> Appearance {
|
fn style(&self, theme: &Self::Theme) -> Appearance {
|
||||||
Style::default().resolve(theme)
|
theme.default_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the event `Subscription` for the current state of the
|
/// Returns the event `Subscription` for the current state of the
|
||||||
|
|
@ -109,7 +109,7 @@ where
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use winit::event_loop::EventLoopBuilder;
|
use winit::event_loop::EventLoopBuilder;
|
||||||
|
|
||||||
|
|
@ -350,7 +350,7 @@ async fn run_instance<A, E, C>(
|
||||||
A: Application + 'static,
|
A: Application + 'static,
|
||||||
E: Executor + 'static,
|
E: Executor + 'static,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use winit::event;
|
use winit::event;
|
||||||
use winit::event_loop::ControlFlow;
|
use winit::event_loop::ControlFlow;
|
||||||
|
|
@ -820,7 +820,7 @@ fn build_user_interface<'a, A: Application>(
|
||||||
id: window::Id,
|
id: window::Id,
|
||||||
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
|
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
|
||||||
where
|
where
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
debug.view_started();
|
debug.view_started();
|
||||||
let view = application.view(id);
|
let view = application.view(id);
|
||||||
|
|
@ -848,7 +848,7 @@ fn update<A: Application, C, E: Executor>(
|
||||||
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
|
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
|
||||||
) where
|
) where
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
for message in messages.drain(..) {
|
for message in messages.drain(..) {
|
||||||
debug.log_message(&message);
|
debug.log_message(&message);
|
||||||
|
|
@ -891,7 +891,7 @@ fn run_command<A, C, E>(
|
||||||
A: Application,
|
A: Application,
|
||||||
E: Executor,
|
E: Executor,
|
||||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
use crate::runtime::clipboard;
|
use crate::runtime::clipboard;
|
||||||
use crate::runtime::system;
|
use crate::runtime::system;
|
||||||
|
|
@ -1218,7 +1218,7 @@ pub fn build_user_interfaces<'a, A: Application, C: Compositor>(
|
||||||
) -> HashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
|
) -> HashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
|
||||||
where
|
where
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
cached_user_interfaces
|
cached_user_interfaces
|
||||||
.drain()
|
.drain()
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use winit::window::Window;
|
||||||
/// The state of a multi-windowed [`Application`].
|
/// The state of a multi-windowed [`Application`].
|
||||||
pub struct State<A: Application>
|
pub struct State<A: Application>
|
||||||
where
|
where
|
||||||
multi_window::Style<A::Theme>: Default,
|
A::Theme: multi_window::DefaultStyle,
|
||||||
{
|
{
|
||||||
title: String,
|
title: String,
|
||||||
scale_factor: f64,
|
scale_factor: f64,
|
||||||
|
|
@ -25,7 +25,7 @@ where
|
||||||
|
|
||||||
impl<A: Application> Debug for State<A>
|
impl<A: Application> Debug for State<A>
|
||||||
where
|
where
|
||||||
multi_window::Style<A::Theme>: Default,
|
A::Theme: multi_window::DefaultStyle,
|
||||||
{
|
{
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("multi_window::State")
|
f.debug_struct("multi_window::State")
|
||||||
|
|
@ -41,7 +41,7 @@ where
|
||||||
|
|
||||||
impl<A: Application> State<A>
|
impl<A: Application> State<A>
|
||||||
where
|
where
|
||||||
multi_window::Style<A::Theme>: Default,
|
A::Theme: multi_window::DefaultStyle,
|
||||||
{
|
{
|
||||||
/// Creates a new [`State`] for the provided [`Application`]'s `window`.
|
/// Creates a new [`State`] for the provided [`Application`]'s `window`.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::core::mouse;
|
||||||
use crate::core::window::Id;
|
use crate::core::window::Id;
|
||||||
use crate::core::{Point, Size};
|
use crate::core::{Point, Size};
|
||||||
use crate::graphics::Compositor;
|
use crate::graphics::Compositor;
|
||||||
use crate::multi_window::{Application, State, Style};
|
use crate::multi_window::{Application, DefaultStyle, State};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -12,7 +12,7 @@ use winit::monitor::MonitorHandle;
|
||||||
pub struct WindowManager<A: Application, C: Compositor>
|
pub struct WindowManager<A: Application, C: Compositor>
|
||||||
where
|
where
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
aliases: BTreeMap<winit::window::WindowId, Id>,
|
aliases: BTreeMap<winit::window::WindowId, Id>,
|
||||||
entries: BTreeMap<Id, Window<A, C>>,
|
entries: BTreeMap<Id, Window<A, C>>,
|
||||||
|
|
@ -22,7 +22,7 @@ impl<A, C> WindowManager<A, C>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -108,7 +108,7 @@ impl<A, C> Default for WindowManager<A, C>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|
@ -120,7 +120,7 @@ pub struct Window<A, C>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
pub raw: Arc<winit::window::Window>,
|
pub raw: Arc<winit::window::Window>,
|
||||||
pub state: State<A>,
|
pub state: State<A>,
|
||||||
|
|
@ -135,7 +135,7 @@ impl<A, C> Window<A, C>
|
||||||
where
|
where
|
||||||
A: Application,
|
A: Application,
|
||||||
C: Compositor<Renderer = A::Renderer>,
|
C: Compositor<Renderer = A::Renderer>,
|
||||||
Style<A::Theme>: Default,
|
A::Theme: DefaultStyle,
|
||||||
{
|
{
|
||||||
pub fn position(&self) -> Option<Point> {
|
pub fn position(&self) -> Option<Point> {
|
||||||
self.raw
|
self.raw
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue