Write documentation for iced_style

This commit is contained in:
Héctor Ramón Jiménez 2022-11-10 01:10:28 +01:00
parent bec1f5bbe0
commit 4b3d0fb08d
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
18 changed files with 261 additions and 56 deletions

View file

@ -1,13 +1,23 @@
//! Change the appearance of an application.
use iced_core::Color;
/// A set of rules that dictate the style of an application.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Returns the [`Appearance`] of the application for the provided [`Style`].
///
/// [`Style`]: Self::Style
fn appearance(&self, style: &Self::Style) -> Appearance;
}
/// The appearance of an application.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Appearance {
/// The background [`Color`] of the application.
pub background_color: Color,
/// The default text [`Color`] of the application.
pub text_color: Color,
}

View file

@ -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};
/// The appearance of a button.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The amount of offset to apply to the shadow of the button.
pub shadow_offset: Vector,
/// The [`Background`] of the button.
pub background: Option<Background>,
/// The border radius of the button.
pub border_radius: f32,
/// The border width of the button.
pub border_width: f32,
/// The border [`Color`] of the button.
pub border_color: Color,
/// The text [`Color`] of the button.
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.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the active [`Appearance`] of a button.
fn active(&self, style: &Self::Style) -> Appearance;
/// Produces the hovered [`Appearance`] of a button.
fn hovered(&self, style: &Self::Style) -> Appearance {
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 {
Appearance {
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 {
let active = self.active(style);

View file

@ -1,22 +1,31 @@
//! Show toggle controls using checkboxes.
//! Change the appearance of a checkbox.
use iced_core::{Background, Color};
/// The appearance of a checkbox.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the checkbox.
pub background: Background,
/// The checkmark [`Color`] of the checkbox.
pub checkmark_color: Color,
/// The border radius of the checkbox.
pub border_radius: f32,
/// The border width of the checkbox.
pub border_width: f32,
/// The border [`Color`] of the checkbox.
pub border_color: Color,
/// The text [`Color`] of the checkbox.
pub text_color: Option<Color>,
}
/// A set of rules that dictate the style of a checkbox.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the active [`Appearance`] of a checkbox.
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;
}

View file

@ -1,13 +1,18 @@
//! Decorate content and apply alignment.
//! Change the appearance of a container.
use iced_core::{Background, Color};
/// The appearance of a container.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the container.
pub text_color: Option<Color>,
/// The [`Background`] of the container.
pub background: Option<Background>,
/// The border radius of the container.
pub border_radius: f32,
/// The border width of the container.
pub border_width: f32,
/// The border [`Color`] of the container.
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.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the [`Appearance`] of a container.

View file

@ -15,6 +15,7 @@
clippy::new_without_default,
clippy::useless_conversion
)]
#![deny(missing_docs, unused_results)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub use iced_core::{Background, Color};

View file

@ -1,19 +1,30 @@
//! Change the appearance of menus.
use iced_core::{Background, Color};
/// The appearance of a menu.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the menu.
pub text_color: Color,
/// The [`Background`] of the menu.
pub background: Background,
/// The border width of the menu.
pub border_width: f32,
/// The border radius of the menu.
pub border_radius: f32,
/// The border [`Color`] of the menu.
pub border_color: Color,
/// The text [`Color`] of a selected option in the menu.
pub selected_text_color: Color,
/// The background [`Color`] of a selected option in the menu.
pub selected_background: Background,
}
/// The style sheet of a menu.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Clone;
/// Produces the [`Appearance`] of a menu.
fn appearance(&self, style: &Self::Style) -> Appearance;
}

View file

@ -1,9 +1,9 @@
//! Let your users split regions of your application and organize layout
//! dynamically.
//! Change the appearance of a pane grid.
use iced_core::Color;
/// A set of rules that dictate the style of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// The [`Line`] to draw when a split is picked.

View file

@ -1,22 +1,33 @@
//! Change the appearance of a pick list.
use iced_core::{Background, Color};
/// The appearance of a pick list.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the pick list.
pub text_color: Color,
/// The placeholder [`Color`] of the pick list.
pub placeholder_color: Color,
/// The [`Background`] of the pick list.
pub background: Background,
/// The border radius of the pick list.
pub border_radius: f32,
/// The border width of the pick list.
pub border_width: f32,
/// The border color of the pick list.
pub border_color: Color,
/// The size of the arrow icon of the pick list.
pub icon_size: f32,
}
/// A set of rules that dictate the style of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Clone;
/// Produces the active [`Appearance`] of a pick list.
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;
}

View file

@ -1,17 +1,22 @@
//! Provide progress feedback to your users.
//! Change the appearance of a progress bar.
use iced_core::Background;
/// The appearance of a progress bar.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the progress bar.
pub background: Background,
/// The [`Background`] of the bar of the progress bar.
pub bar: Background,
/// The border radius of the progress bar.
pub border_radius: f32,
}
/// A set of rules that dictate the style of a progress bar.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the [`Appearance`] of the progress bar.
fn appearance(&self, style: &Self::Style) -> Appearance;
}

View file

@ -1,21 +1,29 @@
//! Create choices using radio buttons.
//! Change the appearance of radio buttons.
use iced_core::{Background, Color};
/// The appearance of a radio button.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the radio button.
pub background: Background,
/// The [`Color`] of the dot of the radio button.
pub dot_color: Color,
/// The border width of the radio button.
pub border_width: f32,
/// The border [`Color`] of the radio button.
pub border_color: Color,
/// The text [`Color`] of the radio button.
pub text_color: Option<Color>,
}
/// A set of rules that dictate the style of a radio button.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the active [`Appearance`] of a radio button.
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;
}

View file

@ -1,4 +1,4 @@
//! Display a horizontal or vertical rule for dividing content.
//! Change the appearance of a rule.
use iced_core::Color;
/// The appearance of a rule.
@ -16,6 +16,7 @@ pub struct Appearance {
/// A set of rules that dictate the style of a rule.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the style of a rule.

View file

@ -1,27 +1,37 @@
//! Navigate an endless amount of content with a scrollbar.
//! Change the appearance of a scrollable.
use iced_core::{Background, Color};
/// The appearance of a scrollable.
#[derive(Debug, Clone, Copy)]
pub struct Scrollbar {
/// The [`Background`] of a scrollable.
pub background: Option<Background>,
/// The border radius of a scrollable.
pub border_radius: f32,
/// The border width of a scrollable.
pub border_width: f32,
/// The border [`Color`] of a scrollable.
pub border_color: Color,
/// The appearance of the [`Scroller`] of a scrollable.
pub scroller: Scroller,
}
/// The appearance of the scroller of a scrollable.
#[derive(Debug, Clone, Copy)]
pub struct Scroller {
/// The [`Color`] of the scroller.
pub color: Color,
/// The border radius of the scroller.
pub border_radius: f32,
/// The border width of the scroller.
pub border_width: f32,
/// The border [`Color`] of the scroller.
pub border_color: Color,
}
/// A set of rules that dictate the style of a scrollable.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the style of an active scrollbar.

View file

@ -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;
/// The appearance of a slider.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The colors of the rail of the slider.
pub rail_colors: (Color, Color),
/// The appearance of the [`Handle`] of the slider.
pub handle: Handle,
}
/// The appearance of the handle of a slider.
#[derive(Debug, Clone, Copy)]
pub struct Handle {
/// The shape of the handle.
pub shape: HandleShape,
/// The [`Color`] of the handle.
pub color: Color,
/// The border width of the handle.
pub border_width: f32,
/// The border [`Color`] of the handle.
pub border_color: Color,
}
/// The shape of the handle of a slider.
#[derive(Debug, Clone, Copy)]
pub enum HandleShape {
Circle { radius: f32 },
Rectangle { width: u16, border_radius: f32 },
/// A circular handle.
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.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the style of an active slider.

View file

@ -1,12 +1,20 @@
//! Change the appearance of text.
use iced_core::Color;
/// The style sheet of some text.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Copy;
/// Produces the [`Appearance`] of some text.
fn appearance(&self, style: Self::Style) -> Appearance;
}
/// The apperance of some text.
#[derive(Debug, Clone, Copy, Default)]
pub struct Appearance {
/// The [`Color`] of the text.
///
/// The default, `None`, means using the inherited color.
pub color: Option<Color>,
}

View file

@ -1,17 +1,22 @@
//! Display fields that can be filled with text.
//! Change the appearance of a text input.
use iced_core::{Background, Color};
/// The appearance of a text input.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the text input.
pub background: Background,
/// The border radius of the text input.
pub border_radius: f32,
/// The border width of the text input.
pub border_width: f32,
/// The border [`Color`] of the text input.
pub border_color: Color,
}
/// A set of rules that dictate the style of a text input.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the style of an active text input.
@ -20,10 +25,13 @@ pub trait StyleSheet {
/// Produces the style of a focused text input.
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;
/// Produces the [`Color`] of the value of a text input.
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;
/// Produces the style of an hovered text input.

View file

@ -1,3 +1,4 @@
//! Use the built-in theme and styles.
pub mod palette;
use self::palette::Extended;
@ -23,19 +24,25 @@ use iced_core::{Background, Color, Vector};
use std::rc::Rc;
/// A built-in theme.
#[derive(Debug, Clone, PartialEq, Default)]
pub enum Theme {
/// The built-in light variant.
#[default]
Light,
/// The built-in dark variant.
Dark,
/// A [`Theme`] that uses a [`Custom`] palette.
Custom(Box<Custom>),
}
impl Theme {
/// Creates a new custom [`Theme`] from the given [`Palette`].
pub fn custom(palette: Palette) -> Self {
Self::Custom(Box::new(Custom::new(palette)))
}
/// Returns the [`Palette`] of the [`Theme`].
pub fn palette(&self) -> Palette {
match self {
Self::Light => Palette::LIGHT,
@ -44,6 +51,7 @@ impl Theme {
}
}
/// Returns the [`palette::Extended`] of the [`Theme`].
pub fn extended_palette(&self) -> &palette::Extended {
match self {
Self::Light => &palette::EXTENDED_LIGHT,
@ -53,6 +61,7 @@ impl Theme {
}
}
/// A [`Theme`] with a customized [`Palette`].
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Custom {
palette: Palette,
@ -60,6 +69,7 @@ pub struct Custom {
}
impl Custom {
/// Creates a [`Custom`] theme from the given [`Palette`].
pub fn new(palette: Palette) -> Self {
Self {
palette,
@ -68,10 +78,13 @@ impl Custom {
}
}
/// The style of an application.
#[derive(Default)]
pub enum Application {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn application::StyleSheet<Style = Theme>>),
}
@ -105,17 +118,23 @@ impl From<fn(&Theme) -> application::Appearance> for Application {
}
}
/*
* Button
*/
/// The style of a button.
#[derive(Default)]
pub enum Button {
/// The primary style.
#[default]
Primary,
/// The secondary style.
Secondary,
/// The positive style.
Positive,
/// The destructive style.
Destructive,
/// The text style.
///
/// Useful for links!
Text,
/// A custom style.
Custom(Box<dyn button::StyleSheet<Style = Theme>>),
}
@ -207,16 +226,19 @@ impl button::StyleSheet for Theme {
}
}
/*
* Checkbox
*/
/// The style of a checkbox.
#[derive(Default)]
pub enum Checkbox {
/// The primary style.
#[default]
Primary,
/// The secondary style.
Secondary,
/// The success style.
Success,
/// The danger style.
Danger,
/// A custom style.
Custom(Box<dyn checkbox::StyleSheet<Style = Theme>>),
}
@ -316,14 +338,15 @@ fn checkbox_appearance(
}
}
/*
* Container
*/
/// The style of a container.
#[derive(Default)]
pub enum Container {
/// No style.
#[default]
Transparent,
/// A simple box.
Box,
/// A custom style.
Custom(Box<dyn container::StyleSheet<Style = Theme>>),
}
@ -363,13 +386,13 @@ impl container::StyleSheet for fn(&Theme) -> container::Appearance {
}
}
/*
* Slider
*/
/// The style of a slider.
#[derive(Default)]
pub enum Slider {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn slider::StyleSheet<Style = Theme>>),
}
@ -444,13 +467,13 @@ impl slider::StyleSheet for Theme {
}
}
/*
* Menu
*/
/// The style of a menu.
#[derive(Clone, Default)]
pub enum Menu {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Rc<dyn menu::StyleSheet<Style = Theme>>),
}
@ -486,13 +509,13 @@ impl From<PickList> for Menu {
}
}
/*
* Pick List
*/
/// The style of a pick list.
#[derive(Clone, Default)]
pub enum PickList {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(
Rc<dyn pick_list::StyleSheet<Style = Theme>>,
Rc<dyn menu::StyleSheet<Style = Theme>>,
@ -541,13 +564,13 @@ impl pick_list::StyleSheet for Theme {
}
}
/*
* Radio
*/
/// The style of a radio button.
#[derive(Default)]
pub enum Radio {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn radio::StyleSheet<Style = Theme>>),
}
@ -596,13 +619,13 @@ impl radio::StyleSheet for Theme {
}
}
/*
* Toggler
*/
/// The style of a toggler.
#[derive(Default)]
pub enum Toggler {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn toggler::StyleSheet<Style = Theme>>),
}
@ -663,13 +686,13 @@ impl toggler::StyleSheet for Theme {
}
}
/*
* Pane Grid
*/
/// The style of a pane grid.
#[derive(Default)]
pub enum PaneGrid {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn pane_grid::StyleSheet<Style = Theme>>),
}
@ -705,15 +728,17 @@ impl pane_grid::StyleSheet for Theme {
}
}
/*
* Progress Bar
*/
/// The style of a progress bar.
#[derive(Default)]
pub enum ProgressBar {
/// The primary style.
#[default]
Primary,
/// The success style.
Success,
/// The danger style.
Danger,
/// A custom style.
Custom(Box<dyn progress_bar::StyleSheet<Style = Theme>>),
}
@ -756,13 +781,13 @@ impl progress_bar::StyleSheet for fn(&Theme) -> progress_bar::Appearance {
}
}
/*
* Rule
*/
/// The style of a rule.
#[derive(Default)]
pub enum Rule {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn rule::StyleSheet<Style = Theme>>),
}
@ -798,13 +823,13 @@ impl rule::StyleSheet for fn(&Theme) -> rule::Appearance {
}
}
/*
* Scrollable
*/
/// The style of a scrollable.
#[derive(Default)]
pub enum Scrollable {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn scrollable::StyleSheet<Style = Theme>>),
}
@ -863,13 +888,13 @@ impl scrollable::StyleSheet for Theme {
}
}
/*
* Text
*/
/// The style of text.
#[derive(Clone, Copy, Default)]
pub enum Text {
/// The default style.
#[default]
Default,
/// Colored text.
Color(Color),
}
@ -890,13 +915,13 @@ impl text::StyleSheet for Theme {
}
}
/*
* Text Input
*/
/// The style of a text input.
#[derive(Default)]
pub enum TextInput {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn text_input::StyleSheet<Style = Theme>>),
}

View file

@ -1,18 +1,26 @@
//! Define the colors of a theme.
use iced_core::Color;
use once_cell::sync::Lazy;
use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb};
/// A color palette.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Palette {
/// The background [`Color`] of the [`Palette`].
pub background: Color,
/// The text [`Color`] of the [`Palette`].
pub text: Color,
/// The primary [`Color`] of the [`Palette`].
pub primary: Color,
/// The success [`Color`] of the [`Palette`].
pub success: Color,
/// The danger [`Color`] of the [`Palette`].
pub danger: Color,
}
impl Palette {
/// The built-in light variant of a [`Palette`].
pub const LIGHT: Self = Self {
background: Color::WHITE,
text: Color::BLACK,
@ -33,6 +41,7 @@ impl Palette {
),
};
/// The built-in dark variant of a [`Palette`].
pub const DARK: Self = Self {
background: Color::from_rgb(
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)]
pub struct Extended {
/// The set of background colors.
pub background: Background,
/// The set of primary colors.
pub primary: Primary,
/// The set of secondary colors.
pub secondary: Secondary,
/// The set of success colors.
pub success: Success,
/// The set of danger colors.
pub danger: Danger,
}
/// The built-in light variant of an [`Extended`] palette.
pub static EXTENDED_LIGHT: Lazy<Extended> =
Lazy::new(|| Extended::generate(Palette::LIGHT));
/// The built-in dark variant of an [`Extended`] palette.
pub static EXTENDED_DARK: Lazy<Extended> =
Lazy::new(|| Extended::generate(Palette::DARK));
impl Extended {
/// Generates an [`Extended`] palette from a simple [`Palette`].
pub fn generate(palette: Palette) -> Self {
Self {
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)]
pub struct Pair {
/// The background 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,
}
impl Pair {
/// Creates a new [`Pair`] from a background [`Color`] and some text [`Color`].
pub fn new(color: Color, text: Color) -> Self {
Self {
color,
@ -111,14 +139,19 @@ impl Pair {
}
}
/// A set of background colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Background {
/// The base background color.
pub base: Pair,
/// A weaker version of the base background color.
pub weak: Pair,
/// A stronger version of the base background color.
pub strong: Pair,
}
impl Background {
/// Generates a set of [`Background`] colors from the base and text colors.
pub fn new(base: Color, text: Color) -> Self {
let weak = mix(base, text, 0.15);
let strong = mix(base, text, 0.40);
@ -131,14 +164,19 @@ impl Background {
}
}
/// A set of primary colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Primary {
/// The base primary color.
pub base: Pair,
/// A weaker version of the base primary color.
pub weak: Pair,
/// A stronger version of the base primary color.
pub strong: Pair,
}
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 {
let weak = mix(base, background, 0.4);
let strong = deviate(base, 0.1);
@ -151,14 +189,19 @@ impl Primary {
}
}
/// A set of secondary colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Secondary {
/// The base secondary color.
pub base: Pair,
/// A weaker version of the base secondary color.
pub weak: Pair,
/// A stronger version of the base secondary color.
pub strong: Pair,
}
impl Secondary {
/// Generates a set of [`Secondary`] colors from the base and text colors.
pub fn generate(base: Color, text: Color) -> Self {
let base = mix(base, text, 0.2);
let weak = mix(base, text, 0.1);
@ -172,14 +215,19 @@ impl Secondary {
}
}
/// A set of success colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Success {
/// The base success color.
pub base: Pair,
/// A weaker version of the base success color.
pub weak: Pair,
/// A stronger version of the base success color.
pub strong: Pair,
}
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 {
let weak = mix(base, background, 0.4);
let strong = deviate(base, 0.1);
@ -192,14 +240,19 @@ impl Success {
}
}
/// A set of danger colors.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Danger {
/// The base danger color.
pub base: Pair,
/// A weaker version of the base danger color.
pub weak: Pair,
/// A stronger version of the base danger color.
pub strong: Pair,
}
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 {
let weak = mix(base, background, 0.4);
let strong = deviate(base, 0.1);

View file

@ -1,20 +1,31 @@
//! Show toggle controls using togglers.
//! Change the appearance of a toggler.
use iced_core::Color;
/// The appearance of a toggler.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The background [`Color`] of the toggler.
pub background: Color,
/// The [`Color`] of the background border of the toggler.
pub background_border: Option<Color>,
/// The foreground [`Color`] of the toggler.
pub foreground: Color,
/// The [`Color`] of the foreground border of the toggler.
pub foreground_border: Option<Color>,
}
/// A set of rules that dictate the style of a toggler.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
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;
/// Returns the hovered [`Appearance`] of the toggler for the provided [`Style`].
///
/// [`Style`]: Self::Style
fn hovered(&self, style: &Self::Style, is_active: bool) -> Appearance;
}