Add weakest and strongest to Background palette
... and tweak background shade generation logic.
This commit is contained in:
parent
f1ed99cb47
commit
954f49d4d7
8 changed files with 76 additions and 31 deletions
|
|
@ -207,7 +207,7 @@ impl Palette {
|
||||||
pub const KANAGAWA_WAVE: Self = Self {
|
pub const KANAGAWA_WAVE: Self = Self {
|
||||||
background: color!(0x363646), // Sumi Ink 3
|
background: color!(0x363646), // Sumi Ink 3
|
||||||
text: color!(0xCD7BA), // Fuji White
|
text: color!(0xCD7BA), // Fuji White
|
||||||
primary: color!(0x2D4F67), // Wave Blue 2
|
primary: color!(0x7FB4CA), // Wave Blue
|
||||||
success: color!(0x76946A), // Autumn Green
|
success: color!(0x76946A), // Autumn Green
|
||||||
warning: color!(0xff9e3b), // Ronin Yellow
|
warning: color!(0xff9e3b), // Ronin Yellow
|
||||||
danger: color!(0xC34043), // Autumn Red
|
danger: color!(0xC34043), // Autumn Red
|
||||||
|
|
@ -231,7 +231,7 @@ impl Palette {
|
||||||
pub const KANAGAWA_LOTUS: Self = Self {
|
pub const KANAGAWA_LOTUS: Self = Self {
|
||||||
background: color!(0xf2ecbc), // Lotus White 3
|
background: color!(0xf2ecbc), // Lotus White 3
|
||||||
text: color!(0x545464), // Lotus Ink 1
|
text: color!(0x545464), // Lotus Ink 1
|
||||||
primary: color!(0xc9cbd1), // Lotus Violet 3
|
primary: color!(0x4d699b), // Lotus Blue
|
||||||
success: color!(0x6f894e), // Lotus Green
|
success: color!(0x6f894e), // Lotus Green
|
||||||
warning: color!(0xe98a00), // Lotus Orange 2
|
warning: color!(0xe98a00), // Lotus Orange 2
|
||||||
danger: color!(0xc84053), // Lotus Red
|
danger: color!(0xc84053), // Lotus Red
|
||||||
|
|
@ -453,22 +453,30 @@ impl Pair {
|
||||||
pub struct Background {
|
pub struct Background {
|
||||||
/// The base background color.
|
/// The base background color.
|
||||||
pub base: Pair,
|
pub base: Pair,
|
||||||
|
/// The weakest version of the base background color.
|
||||||
|
pub weakest: Pair,
|
||||||
/// A weaker version of the base background color.
|
/// A weaker version of the base background color.
|
||||||
pub weak: Pair,
|
pub weak: Pair,
|
||||||
/// A stronger version of the base background color.
|
/// A stronger version of the base background color.
|
||||||
pub strong: Pair,
|
pub strong: Pair,
|
||||||
|
/// The strongest version of the base background color.
|
||||||
|
pub strongest: Pair,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Background {
|
impl Background {
|
||||||
/// Generates a set of [`Background`] colors from the base and text colors.
|
/// 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 weakest = deviate(base, 0.03);
|
||||||
let strong = mix(base, text, 0.40);
|
let weak = muted(deviate(base, 0.1));
|
||||||
|
let strong = muted(deviate(base, 0.2));
|
||||||
|
let strongest = muted(deviate(base, 0.3));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
base: Pair::new(base, text),
|
base: Pair::new(base, text),
|
||||||
|
weakest: Pair::new(weakest, text),
|
||||||
weak: Pair::new(weak, text),
|
weak: Pair::new(weak, text),
|
||||||
strong: Pair::new(strong, text),
|
strong: Pair::new(strong, text),
|
||||||
|
strongest: Pair::new(strongest, text),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -627,10 +635,18 @@ fn deviate(color: Color, amount: f32) -> Color {
|
||||||
if is_dark(color) {
|
if is_dark(color) {
|
||||||
lighten(color, amount)
|
lighten(color, amount)
|
||||||
} else {
|
} else {
|
||||||
darken(color, amount)
|
darken(color, amount * 0.7)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn muted(color: Color) -> Color {
|
||||||
|
let mut hsl = to_hsl(color);
|
||||||
|
|
||||||
|
hsl.saturation = hsl.saturation.min(0.5);
|
||||||
|
|
||||||
|
from_hsl(hsl)
|
||||||
|
}
|
||||||
|
|
||||||
fn mix(a: Color, b: Color, factor: f32) -> Color {
|
fn mix(a: Color, b: Color, factor: f32) -> Color {
|
||||||
let a_lin = Rgb::from(a).into_linear();
|
let a_lin = Rgb::from(a).into_linear();
|
||||||
let b_lin = Rgb::from(b).into_linear();
|
let b_lin = Rgb::from(b).into_linear();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use iced::keyboard;
|
use iced::keyboard;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
button, center, checkbox, column, horizontal_rule, pick_list, progress_bar,
|
button, center, checkbox, column, container, horizontal_rule, pick_list,
|
||||||
row, scrollable, slider, text, text_input, toggler, vertical_rule,
|
progress_bar, row, scrollable, slider, text, text_input, toggler,
|
||||||
vertical_space,
|
vertical_rule, vertical_space,
|
||||||
};
|
};
|
||||||
use iced::{Center, Element, Fill, Subscription, Theme};
|
use iced::{Center, Element, Fill, Subscription, Theme};
|
||||||
|
|
||||||
|
|
@ -90,9 +90,9 @@ impl Styling {
|
||||||
let danger = styled_button("Danger").style(button::danger);
|
let danger = styled_button("Danger").style(button::danger);
|
||||||
|
|
||||||
let slider =
|
let slider =
|
||||||
slider(0.0..=100.0, self.slider_value, Message::SliderChanged);
|
|| slider(0.0..=100.0, self.slider_value, Message::SliderChanged);
|
||||||
|
|
||||||
let progress_bar = progress_bar(0.0..=100.0, self.slider_value);
|
let progress_bar = || progress_bar(0.0..=100.0, self.slider_value);
|
||||||
|
|
||||||
let scrollable = scrollable(column![
|
let scrollable = scrollable(column![
|
||||||
"Scroll me!",
|
"Scroll me!",
|
||||||
|
|
@ -110,6 +110,20 @@ impl Styling {
|
||||||
.on_toggle(Message::TogglerToggled)
|
.on_toggle(Message::TogglerToggled)
|
||||||
.spacing(10);
|
.spacing(10);
|
||||||
|
|
||||||
|
let card = {
|
||||||
|
container(
|
||||||
|
column![
|
||||||
|
text("Card Example").size(24),
|
||||||
|
slider(),
|
||||||
|
progress_bar(),
|
||||||
|
]
|
||||||
|
.spacing(20),
|
||||||
|
)
|
||||||
|
.width(Fill)
|
||||||
|
.padding(20)
|
||||||
|
.style(container::bordered_box)
|
||||||
|
};
|
||||||
|
|
||||||
let content = column![
|
let content = column![
|
||||||
choose_theme,
|
choose_theme,
|
||||||
horizontal_rule(38),
|
horizontal_rule(38),
|
||||||
|
|
@ -117,8 +131,8 @@ impl Styling {
|
||||||
row![primary, success, warning, danger]
|
row![primary, success, warning, danger]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.align_y(Center),
|
.align_y(Center),
|
||||||
slider,
|
slider(),
|
||||||
progress_bar,
|
progress_bar(),
|
||||||
row![
|
row![
|
||||||
scrollable,
|
scrollable,
|
||||||
vertical_rule(38),
|
vertical_rule(38),
|
||||||
|
|
@ -127,6 +141,7 @@ impl Styling {
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.height(100)
|
.height(100)
|
||||||
.align_y(Center),
|
.align_y(Center),
|
||||||
|
card
|
||||||
]
|
]
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
.padding(20)
|
.padding(20)
|
||||||
|
|
|
||||||
|
|
@ -591,12 +591,12 @@ impl Catalog for Theme {
|
||||||
/// A primary button; denoting a main action.
|
/// A primary button; denoting a main action.
|
||||||
pub fn primary(theme: &Theme, status: Status) -> Style {
|
pub fn primary(theme: &Theme, status: Status) -> Style {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
let base = styled(palette.primary.strong);
|
let base = styled(palette.primary.base);
|
||||||
|
|
||||||
match status {
|
match status {
|
||||||
Status::Active | Status::Pressed => base,
|
Status::Active | Status::Pressed => base,
|
||||||
Status::Hovered => Style {
|
Status::Hovered => Style {
|
||||||
background: Some(Background::Color(palette.primary.base.color)),
|
background: Some(Background::Color(palette.primary.strong.color)),
|
||||||
..base
|
..base
|
||||||
},
|
},
|
||||||
Status::Disabled => disabled(base),
|
Status::Disabled => disabled(base),
|
||||||
|
|
|
||||||
|
|
@ -555,18 +555,21 @@ pub fn primary(theme: &Theme, status: Status) -> Style {
|
||||||
match status {
|
match status {
|
||||||
Status::Active { is_checked } => styled(
|
Status::Active { is_checked } => styled(
|
||||||
palette.primary.strong.text,
|
palette.primary.strong.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.base,
|
palette.background.base,
|
||||||
palette.primary.strong,
|
palette.primary.base,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Hovered { is_checked } => styled(
|
Status::Hovered { is_checked } => styled(
|
||||||
palette.primary.strong.text,
|
palette.primary.strong.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.primary.base,
|
palette.primary.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Disabled { is_checked } => styled(
|
Status::Disabled { is_checked } => styled(
|
||||||
palette.primary.strong.text,
|
palette.primary.strong.text,
|
||||||
|
palette.background.weak.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.background.strong,
|
palette.background.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
|
|
@ -581,18 +584,21 @@ pub fn secondary(theme: &Theme, status: Status) -> Style {
|
||||||
match status {
|
match status {
|
||||||
Status::Active { is_checked } => styled(
|
Status::Active { is_checked } => styled(
|
||||||
palette.background.base.text,
|
palette.background.base.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.base,
|
palette.background.base,
|
||||||
palette.background.strong,
|
palette.background.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Hovered { is_checked } => styled(
|
Status::Hovered { is_checked } => styled(
|
||||||
palette.background.base.text,
|
palette.background.base.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.background.strong,
|
palette.background.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Disabled { is_checked } => styled(
|
Status::Disabled { is_checked } => styled(
|
||||||
palette.background.strong.color,
|
palette.background.strong.color,
|
||||||
|
palette.background.weak.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
is_checked,
|
is_checked,
|
||||||
|
|
@ -607,18 +613,21 @@ pub fn success(theme: &Theme, status: Status) -> Style {
|
||||||
match status {
|
match status {
|
||||||
Status::Active { is_checked } => styled(
|
Status::Active { is_checked } => styled(
|
||||||
palette.success.base.text,
|
palette.success.base.text,
|
||||||
|
palette.background.weak.color,
|
||||||
palette.background.base,
|
palette.background.base,
|
||||||
palette.success.base,
|
palette.success.base,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Hovered { is_checked } => styled(
|
Status::Hovered { is_checked } => styled(
|
||||||
palette.success.base.text,
|
palette.success.base.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.success.base,
|
palette.success.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Disabled { is_checked } => styled(
|
Status::Disabled { is_checked } => styled(
|
||||||
palette.success.base.text,
|
palette.success.base.text,
|
||||||
|
palette.background.weak.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.success.weak,
|
palette.success.weak,
|
||||||
is_checked,
|
is_checked,
|
||||||
|
|
@ -633,18 +642,21 @@ pub fn danger(theme: &Theme, status: Status) -> Style {
|
||||||
match status {
|
match status {
|
||||||
Status::Active { is_checked } => styled(
|
Status::Active { is_checked } => styled(
|
||||||
palette.danger.base.text,
|
palette.danger.base.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.base,
|
palette.background.base,
|
||||||
palette.danger.base,
|
palette.danger.base,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Hovered { is_checked } => styled(
|
Status::Hovered { is_checked } => styled(
|
||||||
palette.danger.base.text,
|
palette.danger.base.text,
|
||||||
|
palette.background.strongest.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.danger.base,
|
palette.danger.strong,
|
||||||
is_checked,
|
is_checked,
|
||||||
),
|
),
|
||||||
Status::Disabled { is_checked } => styled(
|
Status::Disabled { is_checked } => styled(
|
||||||
palette.danger.base.text,
|
palette.danger.base.text,
|
||||||
|
palette.background.weak.color,
|
||||||
palette.background.weak,
|
palette.background.weak,
|
||||||
palette.danger.weak,
|
palette.danger.weak,
|
||||||
is_checked,
|
is_checked,
|
||||||
|
|
@ -654,6 +666,7 @@ pub fn danger(theme: &Theme, status: Status) -> Style {
|
||||||
|
|
||||||
fn styled(
|
fn styled(
|
||||||
icon_color: Color,
|
icon_color: Color,
|
||||||
|
border_color: Color,
|
||||||
base: palette::Pair,
|
base: palette::Pair,
|
||||||
accent: palette::Pair,
|
accent: palette::Pair,
|
||||||
is_checked: bool,
|
is_checked: bool,
|
||||||
|
|
@ -668,7 +681,11 @@ fn styled(
|
||||||
border: Border {
|
border: Border {
|
||||||
radius: 2.0.into(),
|
radius: 2.0.into(),
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
color: accent.color,
|
color: if is_checked {
|
||||||
|
accent.color
|
||||||
|
} else {
|
||||||
|
border_color
|
||||||
|
},
|
||||||
},
|
},
|
||||||
text_color: None,
|
text_color: None,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -703,10 +703,10 @@ pub fn bordered_box(theme: &Theme) -> Style {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
Style {
|
Style {
|
||||||
background: Some(palette.background.weak.color.into()),
|
background: Some(palette.background.weakest.color.into()),
|
||||||
border: Border {
|
border: Border {
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
radius: 0.0.into(),
|
radius: 5.0.into(),
|
||||||
color: palette.background.strong.color,
|
color: palette.background.strong.color,
|
||||||
},
|
},
|
||||||
..Style::default()
|
..Style::default()
|
||||||
|
|
|
||||||
|
|
@ -288,10 +288,7 @@ impl Catalog for Theme {
|
||||||
pub fn primary(theme: &Theme) -> Style {
|
pub fn primary(theme: &Theme) -> Style {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
styled(
|
styled(palette.background.strong.color, palette.primary.base.color)
|
||||||
palette.background.strong.color,
|
|
||||||
palette.primary.strong.color,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The secondary style of a [`ProgressBar`].
|
/// The secondary style of a [`ProgressBar`].
|
||||||
|
|
|
||||||
|
|
@ -670,14 +670,14 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
let palette = theme.extended_palette();
|
let palette = theme.extended_palette();
|
||||||
|
|
||||||
let color = match status {
|
let color = match status {
|
||||||
Status::Active => palette.primary.strong.color,
|
Status::Active => palette.primary.base.color,
|
||||||
Status::Hovered => palette.primary.base.color,
|
Status::Hovered => palette.primary.strong.color,
|
||||||
Status::Dragged => palette.primary.strong.color,
|
Status::Dragged => palette.primary.weak.color,
|
||||||
};
|
};
|
||||||
|
|
||||||
Style {
|
Style {
|
||||||
rail: Rail {
|
rail: Rail {
|
||||||
backgrounds: (color.into(), palette.secondary.base.color.into()),
|
backgrounds: (color.into(), palette.background.strong.color.into()),
|
||||||
width: 4.0,
|
width: 4.0,
|
||||||
border: Border {
|
border: Border {
|
||||||
radius: 2.0.into(),
|
radius: 2.0.into(),
|
||||||
|
|
|
||||||
|
|
@ -1802,10 +1802,10 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
border: Border {
|
border: Border {
|
||||||
radius: 2.0.into(),
|
radius: 2.0.into(),
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
color: palette.background.strong.color,
|
color: palette.background.strongest.color,
|
||||||
},
|
},
|
||||||
icon: palette.background.weak.text,
|
icon: palette.background.weak.text,
|
||||||
placeholder: palette.background.strong.color,
|
placeholder: palette.background.strongest.color,
|
||||||
value: palette.background.base.text,
|
value: palette.background.base.text,
|
||||||
selection: palette.primary.weak.color,
|
selection: palette.primary.weak.color,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue