Write documentation for iced_style
This commit is contained in:
parent
bec1f5bbe0
commit
4b3d0fb08d
18 changed files with 261 additions and 56 deletions
|
|
@ -1,13 +1,23 @@
|
||||||
|
//! Change the appearance of an application.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
|
/// A set of rules that dictate the style of an application.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Returns the [`Appearance`] of the application for the provided [`Style`].
|
||||||
|
///
|
||||||
|
/// [`Style`]: Self::Style
|
||||||
fn appearance(&self, style: &Self::Style) -> Appearance;
|
fn appearance(&self, style: &Self::Style) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The appearance of an application.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The background [`Color`] of the application.
|
||||||
pub background_color: Color,
|
pub background_color: Color,
|
||||||
|
|
||||||
|
/// The default text [`Color`] of the application.
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
//! Allow your users to perform actions by pressing a button.
|
//! Change the apperance of a button.
|
||||||
use iced_core::{Background, Color, Vector};
|
use iced_core::{Background, Color, Vector};
|
||||||
|
|
||||||
/// The appearance of a button.
|
/// The appearance of a button.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The amount of offset to apply to the shadow of the button.
|
||||||
pub shadow_offset: Vector,
|
pub shadow_offset: Vector,
|
||||||
|
/// The [`Background`] of the button.
|
||||||
pub background: Option<Background>,
|
pub background: Option<Background>,
|
||||||
|
/// The border radius of the button.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the button.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the button.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The text [`Color`] of the button.
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,10 +33,13 @@ impl std::default::Default for Appearance {
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a button.
|
/// A set of rules that dictate the style of a button.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Produces the active [`Appearance`] of a button.
|
||||||
fn active(&self, style: &Self::Style) -> Appearance;
|
fn active(&self, style: &Self::Style) -> Appearance;
|
||||||
|
|
||||||
|
/// Produces the hovered [`Appearance`] of a button.
|
||||||
fn hovered(&self, style: &Self::Style) -> Appearance {
|
fn hovered(&self, style: &Self::Style) -> Appearance {
|
||||||
let active = self.active(style);
|
let active = self.active(style);
|
||||||
|
|
||||||
|
|
@ -40,6 +49,7 @@ pub trait StyleSheet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Produces the pressed [`Appearance`] of a button.
|
||||||
fn pressed(&self, style: &Self::Style) -> Appearance {
|
fn pressed(&self, style: &Self::Style) -> Appearance {
|
||||||
Appearance {
|
Appearance {
|
||||||
shadow_offset: Vector::default(),
|
shadow_offset: Vector::default(),
|
||||||
|
|
@ -47,6 +57,7 @@ pub trait StyleSheet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Produces the disabled [`Appearance`] of a button.
|
||||||
fn disabled(&self, style: &Self::Style) -> Appearance {
|
fn disabled(&self, style: &Self::Style) -> Appearance {
|
||||||
let active = self.active(style);
|
let active = self.active(style);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,31 @@
|
||||||
//! Show toggle controls using checkboxes.
|
//! Change the appearance of a checkbox.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a checkbox.
|
/// The appearance of a checkbox.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The [`Background`] of the checkbox.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The checkmark [`Color`] of the checkbox.
|
||||||
pub checkmark_color: Color,
|
pub checkmark_color: Color,
|
||||||
|
/// The border radius of the checkbox.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the checkbox.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the checkbox.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The text [`Color`] of the checkbox.
|
||||||
pub text_color: Option<Color>,
|
pub text_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a checkbox.
|
/// A set of rules that dictate the style of a checkbox.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Produces the active [`Appearance`] of a checkbox.
|
||||||
fn active(&self, style: &Self::Style, is_checked: bool) -> Appearance;
|
fn active(&self, style: &Self::Style, is_checked: bool) -> Appearance;
|
||||||
|
|
||||||
|
/// Produces the hovered [`Appearance`] of a checkbox.
|
||||||
fn hovered(&self, style: &Self::Style, is_checked: bool) -> Appearance;
|
fn hovered(&self, style: &Self::Style, is_checked: bool) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
//! Decorate content and apply alignment.
|
//! Change the appearance of a container.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a container.
|
/// The appearance of a container.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The text [`Color`] of the container.
|
||||||
pub text_color: Option<Color>,
|
pub text_color: Option<Color>,
|
||||||
|
/// The [`Background`] of the container.
|
||||||
pub background: Option<Background>,
|
pub background: Option<Background>,
|
||||||
|
/// The border radius of the container.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the container.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the container.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,6 +30,7 @@ impl std::default::Default for Appearance {
|
||||||
|
|
||||||
/// A set of rules that dictate the [`Appearance`] of a container.
|
/// A set of rules that dictate the [`Appearance`] of a container.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// Produces the [`Appearance`] of a container.
|
/// Produces the [`Appearance`] of a container.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
clippy::new_without_default,
|
clippy::new_without_default,
|
||||||
clippy::useless_conversion
|
clippy::useless_conversion
|
||||||
)]
|
)]
|
||||||
|
#![deny(missing_docs, unused_results)]
|
||||||
#![forbid(unsafe_code, rust_2018_idioms)]
|
#![forbid(unsafe_code, rust_2018_idioms)]
|
||||||
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
|
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
|
||||||
pub use iced_core::{Background, Color};
|
pub use iced_core::{Background, Color};
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,30 @@
|
||||||
|
//! Change the appearance of menus.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a menu.
|
/// The appearance of a menu.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The text [`Color`] of the menu.
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
|
/// The [`Background`] of the menu.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The border width of the menu.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border radius of the menu.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border [`Color`] of the menu.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The text [`Color`] of a selected option in the menu.
|
||||||
pub selected_text_color: Color,
|
pub selected_text_color: Color,
|
||||||
|
/// The background [`Color`] of a selected option in the menu.
|
||||||
pub selected_background: Background,
|
pub selected_background: Background,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The style sheet of a menu.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default + Clone;
|
type Style: Default + Clone;
|
||||||
|
|
||||||
|
/// Produces the [`Appearance`] of a menu.
|
||||||
fn appearance(&self, style: &Self::Style) -> Appearance;
|
fn appearance(&self, style: &Self::Style) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
//! Let your users split regions of your application and organize layout
|
//! Change the appearance of a pane grid.
|
||||||
//! dynamically.
|
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a container.
|
/// A set of rules that dictate the style of a container.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// The [`Line`] to draw when a split is picked.
|
/// The [`Line`] to draw when a split is picked.
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,33 @@
|
||||||
|
//! Change the appearance of a pick list.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a pick list.
|
/// The appearance of a pick list.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The text [`Color`] of the pick list.
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
|
/// The placeholder [`Color`] of the pick list.
|
||||||
pub placeholder_color: Color,
|
pub placeholder_color: Color,
|
||||||
|
/// The [`Background`] of the pick list.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The border radius of the pick list.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the pick list.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border color of the pick list.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The size of the arrow icon of the pick list.
|
||||||
pub icon_size: f32,
|
pub icon_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a container.
|
/// A set of rules that dictate the style of a container.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default + Clone;
|
type Style: Default + Clone;
|
||||||
|
|
||||||
|
/// Produces the active [`Appearance`] of a pick list.
|
||||||
fn active(&self, style: &<Self as StyleSheet>::Style) -> Appearance;
|
fn active(&self, style: &<Self as StyleSheet>::Style) -> Appearance;
|
||||||
|
|
||||||
|
/// Produces the hovered [`Appearance`] of a pick list.
|
||||||
fn hovered(&self, style: &<Self as StyleSheet>::Style) -> Appearance;
|
fn hovered(&self, style: &<Self as StyleSheet>::Style) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
//! Provide progress feedback to your users.
|
//! Change the appearance of a progress bar.
|
||||||
use iced_core::Background;
|
use iced_core::Background;
|
||||||
|
|
||||||
/// The appearance of a progress bar.
|
/// The appearance of a progress bar.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The [`Background`] of the progress bar.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The [`Background`] of the bar of the progress bar.
|
||||||
pub bar: Background,
|
pub bar: Background,
|
||||||
|
/// The border radius of the progress bar.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a progress bar.
|
/// A set of rules that dictate the style of a progress bar.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Produces the [`Appearance`] of the progress bar.
|
||||||
fn appearance(&self, style: &Self::Style) -> Appearance;
|
fn appearance(&self, style: &Self::Style) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,29 @@
|
||||||
//! Create choices using radio buttons.
|
//! Change the appearance of radio buttons.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a radio button.
|
/// The appearance of a radio button.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The [`Background`] of the radio button.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The [`Color`] of the dot of the radio button.
|
||||||
pub dot_color: Color,
|
pub dot_color: Color,
|
||||||
|
/// The border width of the radio button.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the radio button.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The text [`Color`] of the radio button.
|
||||||
pub text_color: Option<Color>,
|
pub text_color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a radio button.
|
/// A set of rules that dictate the style of a radio button.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Produces the active [`Appearance`] of a radio button.
|
||||||
fn active(&self, style: &Self::Style, is_selected: bool) -> Appearance;
|
fn active(&self, style: &Self::Style, is_selected: bool) -> Appearance;
|
||||||
|
|
||||||
|
/// Produces the hovered [`Appearance`] of a radio button.
|
||||||
fn hovered(&self, style: &Self::Style, is_selected: bool) -> Appearance;
|
fn hovered(&self, style: &Self::Style, is_selected: bool) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
//! Display a horizontal or vertical rule for dividing content.
|
//! Change the appearance of a rule.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
/// The appearance of a rule.
|
/// The appearance of a rule.
|
||||||
|
|
@ -16,6 +16,7 @@ pub struct Appearance {
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a rule.
|
/// A set of rules that dictate the style of a rule.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// Produces the style of a rule.
|
/// Produces the style of a rule.
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,37 @@
|
||||||
//! Navigate an endless amount of content with a scrollbar.
|
//! Change the appearance of a scrollable.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a scrollable.
|
/// The appearance of a scrollable.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Scrollbar {
|
pub struct Scrollbar {
|
||||||
|
/// The [`Background`] of a scrollable.
|
||||||
pub background: Option<Background>,
|
pub background: Option<Background>,
|
||||||
|
/// The border radius of a scrollable.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of a scrollable.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of a scrollable.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
|
/// The appearance of the [`Scroller`] of a scrollable.
|
||||||
pub scroller: Scroller,
|
pub scroller: Scroller,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The appearance of the scroller of a scrollable.
|
/// The appearance of the scroller of a scrollable.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Scroller {
|
pub struct Scroller {
|
||||||
|
/// The [`Color`] of the scroller.
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
/// The border radius of the scroller.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the scroller.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the scroller.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a scrollable.
|
/// A set of rules that dictate the style of a scrollable.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// Produces the style of an active scrollbar.
|
/// Produces the style of an active scrollbar.
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,48 @@
|
||||||
//! Display an interactive selector of a single value from a range of values.
|
//! Change the apperance of a slider.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
/// The appearance of a slider.
|
/// The appearance of a slider.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The colors of the rail of the slider.
|
||||||
pub rail_colors: (Color, Color),
|
pub rail_colors: (Color, Color),
|
||||||
|
/// The appearance of the [`Handle`] of the slider.
|
||||||
pub handle: Handle,
|
pub handle: Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The appearance of the handle of a slider.
|
/// The appearance of the handle of a slider.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Handle {
|
pub struct Handle {
|
||||||
|
/// The shape of the handle.
|
||||||
pub shape: HandleShape,
|
pub shape: HandleShape,
|
||||||
|
/// The [`Color`] of the handle.
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
/// The border width of the handle.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the handle.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The shape of the handle of a slider.
|
/// The shape of the handle of a slider.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum HandleShape {
|
pub enum HandleShape {
|
||||||
Circle { radius: f32 },
|
/// A circular handle.
|
||||||
Rectangle { width: u16, border_radius: f32 },
|
Circle {
|
||||||
|
/// The radius of the circle.
|
||||||
|
radius: f32,
|
||||||
|
},
|
||||||
|
/// A rectangular shape.
|
||||||
|
Rectangle {
|
||||||
|
/// The width of the rectangle.
|
||||||
|
width: u16,
|
||||||
|
/// The border radius of the corners of the rectangle.
|
||||||
|
border_radius: f32,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a slider.
|
/// A set of rules that dictate the style of a slider.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// Produces the style of an active slider.
|
/// Produces the style of an active slider.
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
|
//! Change the appearance of text.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
|
/// The style sheet of some text.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default + Copy;
|
type Style: Default + Copy;
|
||||||
|
|
||||||
|
/// Produces the [`Appearance`] of some text.
|
||||||
fn appearance(&self, style: Self::Style) -> Appearance;
|
fn appearance(&self, style: Self::Style) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The apperance of some text.
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy, Default)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The [`Color`] of the text.
|
||||||
|
///
|
||||||
|
/// The default, `None`, means using the inherited color.
|
||||||
pub color: Option<Color>,
|
pub color: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
//! Display fields that can be filled with text.
|
//! Change the appearance of a text input.
|
||||||
use iced_core::{Background, Color};
|
use iced_core::{Background, Color};
|
||||||
|
|
||||||
/// The appearance of a text input.
|
/// The appearance of a text input.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The [`Background`] of the text input.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The border radius of the text input.
|
||||||
pub border_radius: f32,
|
pub border_radius: f32,
|
||||||
|
/// The border width of the text input.
|
||||||
pub border_width: f32,
|
pub border_width: f32,
|
||||||
|
/// The border [`Color`] of the text input.
|
||||||
pub border_color: Color,
|
pub border_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a text input.
|
/// A set of rules that dictate the style of a text input.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
/// Produces the style of an active text input.
|
/// Produces the style of an active text input.
|
||||||
|
|
@ -20,10 +25,13 @@ pub trait StyleSheet {
|
||||||
/// Produces the style of a focused text input.
|
/// Produces the style of a focused text input.
|
||||||
fn focused(&self, style: &Self::Style) -> Appearance;
|
fn focused(&self, style: &Self::Style) -> Appearance;
|
||||||
|
|
||||||
|
/// Produces the [`Color`] of the placeholder of a text input.
|
||||||
fn placeholder_color(&self, style: &Self::Style) -> Color;
|
fn placeholder_color(&self, style: &Self::Style) -> Color;
|
||||||
|
|
||||||
|
/// Produces the [`Color`] of the value of a text input.
|
||||||
fn value_color(&self, style: &Self::Style) -> Color;
|
fn value_color(&self, style: &Self::Style) -> Color;
|
||||||
|
|
||||||
|
/// Produces the [`Color`] of the selection of a text input.
|
||||||
fn selection_color(&self, style: &Self::Style) -> Color;
|
fn selection_color(&self, style: &Self::Style) -> Color;
|
||||||
|
|
||||||
/// Produces the style of an hovered text input.
|
/// Produces the style of an hovered text input.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! Use the built-in theme and styles.
|
||||||
pub mod palette;
|
pub mod palette;
|
||||||
|
|
||||||
use self::palette::Extended;
|
use self::palette::Extended;
|
||||||
|
|
@ -23,19 +24,25 @@ use iced_core::{Background, Color, Vector};
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
/// A built-in theme.
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub enum Theme {
|
pub enum Theme {
|
||||||
|
/// The built-in light variant.
|
||||||
#[default]
|
#[default]
|
||||||
Light,
|
Light,
|
||||||
|
/// The built-in dark variant.
|
||||||
Dark,
|
Dark,
|
||||||
|
/// A [`Theme`] that uses a [`Custom`] palette.
|
||||||
Custom(Box<Custom>),
|
Custom(Box<Custom>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Theme {
|
impl Theme {
|
||||||
|
/// Creates a new custom [`Theme`] from the given [`Palette`].
|
||||||
pub fn custom(palette: Palette) -> Self {
|
pub fn custom(palette: Palette) -> Self {
|
||||||
Self::Custom(Box::new(Custom::new(palette)))
|
Self::Custom(Box::new(Custom::new(palette)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`Palette`] of the [`Theme`].
|
||||||
pub fn palette(&self) -> Palette {
|
pub fn palette(&self) -> Palette {
|
||||||
match self {
|
match self {
|
||||||
Self::Light => Palette::LIGHT,
|
Self::Light => Palette::LIGHT,
|
||||||
|
|
@ -44,6 +51,7 @@ impl Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`palette::Extended`] of the [`Theme`].
|
||||||
pub fn extended_palette(&self) -> &palette::Extended {
|
pub fn extended_palette(&self) -> &palette::Extended {
|
||||||
match self {
|
match self {
|
||||||
Self::Light => &palette::EXTENDED_LIGHT,
|
Self::Light => &palette::EXTENDED_LIGHT,
|
||||||
|
|
@ -53,6 +61,7 @@ impl Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A [`Theme`] with a customized [`Palette`].
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Custom {
|
pub struct Custom {
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
|
|
@ -60,6 +69,7 @@ pub struct Custom {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Custom {
|
impl Custom {
|
||||||
|
/// Creates a [`Custom`] theme from the given [`Palette`].
|
||||||
pub fn new(palette: Palette) -> Self {
|
pub fn new(palette: Palette) -> Self {
|
||||||
Self {
|
Self {
|
||||||
palette,
|
palette,
|
||||||
|
|
@ -68,10 +78,13 @@ impl Custom {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The style of an application.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Application {
|
pub enum Application {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn application::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn application::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,17 +118,23 @@ impl From<fn(&Theme) -> application::Appearance> for Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a button.
|
||||||
* Button
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Button {
|
pub enum Button {
|
||||||
|
/// The primary style.
|
||||||
#[default]
|
#[default]
|
||||||
Primary,
|
Primary,
|
||||||
|
/// The secondary style.
|
||||||
Secondary,
|
Secondary,
|
||||||
|
/// The positive style.
|
||||||
Positive,
|
Positive,
|
||||||
|
/// The destructive style.
|
||||||
Destructive,
|
Destructive,
|
||||||
|
/// The text style.
|
||||||
|
///
|
||||||
|
/// Useful for links!
|
||||||
Text,
|
Text,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn button::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn button::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,16 +226,19 @@ impl button::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a checkbox.
|
||||||
* Checkbox
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Checkbox {
|
pub enum Checkbox {
|
||||||
|
/// The primary style.
|
||||||
#[default]
|
#[default]
|
||||||
Primary,
|
Primary,
|
||||||
|
/// The secondary style.
|
||||||
Secondary,
|
Secondary,
|
||||||
|
/// The success style.
|
||||||
Success,
|
Success,
|
||||||
|
/// The danger style.
|
||||||
Danger,
|
Danger,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn checkbox::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn checkbox::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -316,14 +338,15 @@ fn checkbox_appearance(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a container.
|
||||||
* Container
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Container {
|
pub enum Container {
|
||||||
|
/// No style.
|
||||||
#[default]
|
#[default]
|
||||||
Transparent,
|
Transparent,
|
||||||
|
/// A simple box.
|
||||||
Box,
|
Box,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn container::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn container::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -363,13 +386,13 @@ impl container::StyleSheet for fn(&Theme) -> container::Appearance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a slider.
|
||||||
* Slider
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Slider {
|
pub enum Slider {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn slider::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn slider::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,13 +467,13 @@ impl slider::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a menu.
|
||||||
* Menu
|
|
||||||
*/
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub enum Menu {
|
pub enum Menu {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Rc<dyn menu::StyleSheet<Style = Theme>>),
|
Custom(Rc<dyn menu::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,13 +509,13 @@ impl From<PickList> for Menu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a pick list.
|
||||||
* Pick List
|
|
||||||
*/
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub enum PickList {
|
pub enum PickList {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(
|
Custom(
|
||||||
Rc<dyn pick_list::StyleSheet<Style = Theme>>,
|
Rc<dyn pick_list::StyleSheet<Style = Theme>>,
|
||||||
Rc<dyn menu::StyleSheet<Style = Theme>>,
|
Rc<dyn menu::StyleSheet<Style = Theme>>,
|
||||||
|
|
@ -541,13 +564,13 @@ impl pick_list::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a radio button.
|
||||||
* Radio
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Radio {
|
pub enum Radio {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn radio::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn radio::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -596,13 +619,13 @@ impl radio::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a toggler.
|
||||||
* Toggler
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Toggler {
|
pub enum Toggler {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn toggler::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn toggler::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -663,13 +686,13 @@ impl toggler::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a pane grid.
|
||||||
* Pane Grid
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum PaneGrid {
|
pub enum PaneGrid {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn pane_grid::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn pane_grid::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -705,15 +728,17 @@ impl pane_grid::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a progress bar.
|
||||||
* Progress Bar
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum ProgressBar {
|
pub enum ProgressBar {
|
||||||
|
/// The primary style.
|
||||||
#[default]
|
#[default]
|
||||||
Primary,
|
Primary,
|
||||||
|
/// The success style.
|
||||||
Success,
|
Success,
|
||||||
|
/// The danger style.
|
||||||
Danger,
|
Danger,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -756,13 +781,13 @@ impl progress_bar::StyleSheet for fn(&Theme) -> progress_bar::Appearance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a rule.
|
||||||
* Rule
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Rule {
|
pub enum Rule {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn rule::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn rule::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -798,13 +823,13 @@ impl rule::StyleSheet for fn(&Theme) -> rule::Appearance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a scrollable.
|
||||||
* Scrollable
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum Scrollable {
|
pub enum Scrollable {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn scrollable::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn scrollable::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -863,13 +888,13 @@ impl scrollable::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of text.
|
||||||
* Text
|
|
||||||
*/
|
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
pub enum Text {
|
pub enum Text {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// Colored text.
|
||||||
Color(Color),
|
Color(Color),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -890,13 +915,13 @@ impl text::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// The style of a text input.
|
||||||
* Text Input
|
|
||||||
*/
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub enum TextInput {
|
pub enum TextInput {
|
||||||
|
/// The default style.
|
||||||
#[default]
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
|
/// A custom style.
|
||||||
Custom(Box<dyn text_input::StyleSheet<Style = Theme>>),
|
Custom(Box<dyn text_input::StyleSheet<Style = Theme>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,26 @@
|
||||||
|
//! Define the colors of a theme.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb};
|
use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb};
|
||||||
|
|
||||||
|
/// A color palette.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Palette {
|
pub struct Palette {
|
||||||
|
/// The background [`Color`] of the [`Palette`].
|
||||||
pub background: Color,
|
pub background: Color,
|
||||||
|
/// The text [`Color`] of the [`Palette`].
|
||||||
pub text: Color,
|
pub text: Color,
|
||||||
|
/// The primary [`Color`] of the [`Palette`].
|
||||||
pub primary: Color,
|
pub primary: Color,
|
||||||
|
/// The success [`Color`] of the [`Palette`].
|
||||||
pub success: Color,
|
pub success: Color,
|
||||||
|
/// The danger [`Color`] of the [`Palette`].
|
||||||
pub danger: Color,
|
pub danger: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Palette {
|
impl Palette {
|
||||||
|
/// The built-in light variant of a [`Palette`].
|
||||||
pub const LIGHT: Self = Self {
|
pub const LIGHT: Self = Self {
|
||||||
background: Color::WHITE,
|
background: Color::WHITE,
|
||||||
text: Color::BLACK,
|
text: Color::BLACK,
|
||||||
|
|
@ -33,6 +41,7 @@ impl Palette {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The built-in dark variant of a [`Palette`].
|
||||||
pub const DARK: Self = Self {
|
pub const DARK: Self = Self {
|
||||||
background: Color::from_rgb(
|
background: Color::from_rgb(
|
||||||
0x20 as f32 / 255.0,
|
0x20 as f32 / 255.0,
|
||||||
|
|
@ -58,21 +67,31 @@ impl Palette {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An extended set of colors generated from a [`Palette`].
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Extended {
|
pub struct Extended {
|
||||||
|
/// The set of background colors.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
|
/// The set of primary colors.
|
||||||
pub primary: Primary,
|
pub primary: Primary,
|
||||||
|
/// The set of secondary colors.
|
||||||
pub secondary: Secondary,
|
pub secondary: Secondary,
|
||||||
|
/// The set of success colors.
|
||||||
pub success: Success,
|
pub success: Success,
|
||||||
|
/// The set of danger colors.
|
||||||
pub danger: Danger,
|
pub danger: Danger,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The built-in light variant of an [`Extended`] palette.
|
||||||
pub static EXTENDED_LIGHT: Lazy<Extended> =
|
pub static EXTENDED_LIGHT: Lazy<Extended> =
|
||||||
Lazy::new(|| Extended::generate(Palette::LIGHT));
|
Lazy::new(|| Extended::generate(Palette::LIGHT));
|
||||||
|
|
||||||
|
/// The built-in dark variant of an [`Extended`] palette.
|
||||||
pub static EXTENDED_DARK: Lazy<Extended> =
|
pub static EXTENDED_DARK: Lazy<Extended> =
|
||||||
Lazy::new(|| Extended::generate(Palette::DARK));
|
Lazy::new(|| Extended::generate(Palette::DARK));
|
||||||
|
|
||||||
impl Extended {
|
impl Extended {
|
||||||
|
/// Generates an [`Extended`] palette from a simple [`Palette`].
|
||||||
pub fn generate(palette: Palette) -> Self {
|
pub fn generate(palette: Palette) -> Self {
|
||||||
Self {
|
Self {
|
||||||
background: Background::new(palette.background, palette.text),
|
background: Background::new(palette.background, palette.text),
|
||||||
|
|
@ -96,13 +115,22 @@ impl Extended {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A pair of background and text colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Pair {
|
pub struct Pair {
|
||||||
|
/// The background color.
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
|
||||||
|
/// The text color.
|
||||||
|
///
|
||||||
|
/// It's guaranteed to be readable on top of the background [`color`].
|
||||||
|
///
|
||||||
|
/// [`color`]: Self::color
|
||||||
pub text: Color,
|
pub text: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pair {
|
impl Pair {
|
||||||
|
/// Creates a new [`Pair`] from a background [`Color`] and some text [`Color`].
|
||||||
pub fn new(color: Color, text: Color) -> Self {
|
pub fn new(color: Color, text: Color) -> Self {
|
||||||
Self {
|
Self {
|
||||||
color,
|
color,
|
||||||
|
|
@ -111,14 +139,19 @@ impl Pair {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of background colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Background {
|
pub struct Background {
|
||||||
|
/// The base background color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// A weaker version of the base background color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
|
/// A stronger version of the base background color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Background {
|
impl Background {
|
||||||
|
/// Generates a set of [`Background`] colors from the base and text colors.
|
||||||
pub fn new(base: Color, text: Color) -> Self {
|
pub fn new(base: Color, text: Color) -> Self {
|
||||||
let weak = mix(base, text, 0.15);
|
let weak = mix(base, text, 0.15);
|
||||||
let strong = mix(base, text, 0.40);
|
let strong = mix(base, text, 0.40);
|
||||||
|
|
@ -131,14 +164,19 @@ impl Background {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of primary colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Primary {
|
pub struct Primary {
|
||||||
|
/// The base primary color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// A weaker version of the base primary color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
|
/// A stronger version of the base primary color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Primary {
|
impl Primary {
|
||||||
|
/// Generates a set of [`Primary`] colors from the base, background, and text colors.
|
||||||
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
||||||
let weak = mix(base, background, 0.4);
|
let weak = mix(base, background, 0.4);
|
||||||
let strong = deviate(base, 0.1);
|
let strong = deviate(base, 0.1);
|
||||||
|
|
@ -151,14 +189,19 @@ impl Primary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of secondary colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Secondary {
|
pub struct Secondary {
|
||||||
|
/// The base secondary color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// A weaker version of the base secondary color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
|
/// A stronger version of the base secondary color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Secondary {
|
impl Secondary {
|
||||||
|
/// Generates a set of [`Secondary`] colors from the base and text colors.
|
||||||
pub fn generate(base: Color, text: Color) -> Self {
|
pub fn generate(base: Color, text: Color) -> Self {
|
||||||
let base = mix(base, text, 0.2);
|
let base = mix(base, text, 0.2);
|
||||||
let weak = mix(base, text, 0.1);
|
let weak = mix(base, text, 0.1);
|
||||||
|
|
@ -172,14 +215,19 @@ impl Secondary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of success colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Success {
|
pub struct Success {
|
||||||
|
/// The base success color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// A weaker version of the base success color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
|
/// A stronger version of the base success color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Success {
|
impl Success {
|
||||||
|
/// Generates a set of [`Success`] colors from the base, background, and text colors.
|
||||||
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
||||||
let weak = mix(base, background, 0.4);
|
let weak = mix(base, background, 0.4);
|
||||||
let strong = deviate(base, 0.1);
|
let strong = deviate(base, 0.1);
|
||||||
|
|
@ -192,14 +240,19 @@ impl Success {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set of danger colors.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Danger {
|
pub struct Danger {
|
||||||
|
/// The base danger color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// A weaker version of the base danger color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
|
/// A stronger version of the base danger color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Danger {
|
impl Danger {
|
||||||
|
/// Generates a set of [`Danger`] colors from the base, background, and text colors.
|
||||||
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
pub fn generate(base: Color, background: Color, text: Color) -> Self {
|
||||||
let weak = mix(base, background, 0.4);
|
let weak = mix(base, background, 0.4);
|
||||||
let strong = deviate(base, 0.1);
|
let strong = deviate(base, 0.1);
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,31 @@
|
||||||
//! Show toggle controls using togglers.
|
//! Change the appearance of a toggler.
|
||||||
use iced_core::Color;
|
use iced_core::Color;
|
||||||
|
|
||||||
/// The appearance of a toggler.
|
/// The appearance of a toggler.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Appearance {
|
pub struct Appearance {
|
||||||
|
/// The background [`Color`] of the toggler.
|
||||||
pub background: Color,
|
pub background: Color,
|
||||||
|
/// The [`Color`] of the background border of the toggler.
|
||||||
pub background_border: Option<Color>,
|
pub background_border: Option<Color>,
|
||||||
|
/// The foreground [`Color`] of the toggler.
|
||||||
pub foreground: Color,
|
pub foreground: Color,
|
||||||
|
/// The [`Color`] of the foreground border of the toggler.
|
||||||
pub foreground_border: Option<Color>,
|
pub foreground_border: Option<Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of rules that dictate the style of a toggler.
|
/// A set of rules that dictate the style of a toggler.
|
||||||
pub trait StyleSheet {
|
pub trait StyleSheet {
|
||||||
|
/// The supported style of the [`StyleSheet`].
|
||||||
type Style: Default;
|
type Style: Default;
|
||||||
|
|
||||||
|
/// Returns the active [`Appearance`] of the toggler for the provided [`Style`].
|
||||||
|
///
|
||||||
|
/// [`Style`]: Self::Style
|
||||||
fn active(&self, style: &Self::Style, is_active: bool) -> Appearance;
|
fn active(&self, style: &Self::Style, is_active: bool) -> Appearance;
|
||||||
|
|
||||||
|
/// Returns the hovered [`Appearance`] of the toggler for the provided [`Style`].
|
||||||
|
///
|
||||||
|
/// [`Style`]: Self::Style
|
||||||
fn hovered(&self, style: &Self::Style, is_active: bool) -> Appearance;
|
fn hovered(&self, style: &Self::Style, is_active: bool) -> Appearance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue