summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-22 00:34:55 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-22 00:34:55 +0100
commit954f49d4d73d040ef9367800a662031cd92d9e09 (patch)
treed7a9429e73f79884dfaa3f2e56d8b9b3496be34b
parentf1ed99cb47997e1d194a41e7cdf2846f8eb5f8fa (diff)
downloadiced-954f49d4d73d040ef9367800a662031cd92d9e09.tar.gz
iced-954f49d4d73d040ef9367800a662031cd92d9e09.tar.bz2
iced-954f49d4d73d040ef9367800a662031cd92d9e09.zip
Add `weakest` and `strongest` to `Background` palette
... and tweak background shade generation logic.
-rw-r--r--core/src/theme/palette.rs26
-rw-r--r--examples/styling/src/main.rs29
-rw-r--r--widget/src/button.rs4
-rw-r--r--widget/src/checkbox.rs27
-rw-r--r--widget/src/container.rs4
-rw-r--r--widget/src/progress_bar.rs5
-rw-r--r--widget/src/slider.rs8
-rw-r--r--widget/src/text_input.rs4
8 files changed, 76 insertions, 31 deletions
diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs
index b4acaa83..3f30326b 100644
--- a/core/src/theme/palette.rs
+++ b/core/src/theme/palette.rs
@@ -207,7 +207,7 @@ impl Palette {
pub const KANAGAWA_WAVE: Self = Self {
background: color!(0x363646), // Sumi Ink 3
text: color!(0xCD7BA), // Fuji White
- primary: color!(0x2D4F67), // Wave Blue 2
+ primary: color!(0x7FB4CA), // Wave Blue
success: color!(0x76946A), // Autumn Green
warning: color!(0xff9e3b), // Ronin Yellow
danger: color!(0xC34043), // Autumn Red
@@ -231,7 +231,7 @@ impl Palette {
pub const KANAGAWA_LOTUS: Self = Self {
background: color!(0xf2ecbc), // Lotus White 3
text: color!(0x545464), // Lotus Ink 1
- primary: color!(0xc9cbd1), // Lotus Violet 3
+ primary: color!(0x4d699b), // Lotus Blue
success: color!(0x6f894e), // Lotus Green
warning: color!(0xe98a00), // Lotus Orange 2
danger: color!(0xc84053), // Lotus Red
@@ -453,22 +453,30 @@ impl Pair {
pub struct Background {
/// The base background color.
pub base: Pair,
+ /// The weakest version of the base background color.
+ pub weakest: Pair,
/// A weaker version of the base background color.
pub weak: Pair,
/// A stronger version of the base background color.
pub strong: Pair,
+ /// The strongest version of the base background color.
+ pub strongest: 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);
+ let weakest = deviate(base, 0.03);
+ let weak = muted(deviate(base, 0.1));
+ let strong = muted(deviate(base, 0.2));
+ let strongest = muted(deviate(base, 0.3));
Self {
base: Pair::new(base, text),
+ weakest: Pair::new(weakest, text),
weak: Pair::new(weak, 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) {
lighten(color, amount)
} 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 {
let a_lin = Rgb::from(a).into_linear();
let b_lin = Rgb::from(b).into_linear();
diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs
index 594be4a7..fce2b162 100644
--- a/examples/styling/src/main.rs
+++ b/examples/styling/src/main.rs
@@ -1,8 +1,8 @@
use iced::keyboard;
use iced::widget::{
- button, center, checkbox, column, horizontal_rule, pick_list, progress_bar,
- row, scrollable, slider, text, text_input, toggler, vertical_rule,
- vertical_space,
+ button, center, checkbox, column, container, horizontal_rule, pick_list,
+ progress_bar, row, scrollable, slider, text, text_input, toggler,
+ vertical_rule, vertical_space,
};
use iced::{Center, Element, Fill, Subscription, Theme};
@@ -90,9 +90,9 @@ impl Styling {
let danger = styled_button("Danger").style(button::danger);
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![
"Scroll me!",
@@ -110,6 +110,20 @@ impl Styling {
.on_toggle(Message::TogglerToggled)
.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![
choose_theme,
horizontal_rule(38),
@@ -117,8 +131,8 @@ impl Styling {
row![primary, success, warning, danger]
.spacing(10)
.align_y(Center),
- slider,
- progress_bar,
+ slider(),
+ progress_bar(),
row![
scrollable,
vertical_rule(38),
@@ -127,6 +141,7 @@ impl Styling {
.spacing(10)
.height(100)
.align_y(Center),
+ card
]
.spacing(20)
.padding(20)
diff --git a/widget/src/button.rs b/widget/src/button.rs
index 1b51065d..d4500888 100644
--- a/widget/src/button.rs
+++ b/widget/src/button.rs
@@ -591,12 +591,12 @@ impl Catalog for Theme {
/// A primary button; denoting a main action.
pub fn primary(theme: &Theme, status: Status) -> Style {
let palette = theme.extended_palette();
- let base = styled(palette.primary.strong);
+ let base = styled(palette.primary.base);
match status {
Status::Active | Status::Pressed => base,
Status::Hovered => Style {
- background: Some(Background::Color(palette.primary.base.color)),
+ background: Some(Background::Color(palette.primary.strong.color)),
..base
},
Status::Disabled => disabled(base),
diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs
index 6ed3e080..3c1ef276 100644
--- a/widget/src/checkbox.rs
+++ b/widget/src/checkbox.rs
@@ -555,18 +555,21 @@ pub fn primary(theme: &Theme, status: Status) -> Style {
match status {
Status::Active { is_checked } => styled(
palette.primary.strong.text,
+ palette.background.strongest.color,
palette.background.base,
- palette.primary.strong,
+ palette.primary.base,
is_checked,
),
Status::Hovered { is_checked } => styled(
palette.primary.strong.text,
+ palette.background.strongest.color,
palette.background.weak,
- palette.primary.base,
+ palette.primary.strong,
is_checked,
),
Status::Disabled { is_checked } => styled(
palette.primary.strong.text,
+ palette.background.weak.color,
palette.background.weak,
palette.background.strong,
is_checked,
@@ -581,18 +584,21 @@ pub fn secondary(theme: &Theme, status: Status) -> Style {
match status {
Status::Active { is_checked } => styled(
palette.background.base.text,
+ palette.background.strongest.color,
palette.background.base,
palette.background.strong,
is_checked,
),
Status::Hovered { is_checked } => styled(
palette.background.base.text,
+ palette.background.strongest.color,
palette.background.weak,
palette.background.strong,
is_checked,
),
Status::Disabled { is_checked } => styled(
palette.background.strong.color,
+ palette.background.weak.color,
palette.background.weak,
palette.background.weak,
is_checked,
@@ -607,18 +613,21 @@ pub fn success(theme: &Theme, status: Status) -> Style {
match status {
Status::Active { is_checked } => styled(
palette.success.base.text,
+ palette.background.weak.color,
palette.background.base,
palette.success.base,
is_checked,
),
Status::Hovered { is_checked } => styled(
palette.success.base.text,
+ palette.background.strongest.color,
palette.background.weak,
- palette.success.base,
+ palette.success.strong,
is_checked,
),
Status::Disabled { is_checked } => styled(
palette.success.base.text,
+ palette.background.weak.color,
palette.background.weak,
palette.success.weak,
is_checked,
@@ -633,18 +642,21 @@ pub fn danger(theme: &Theme, status: Status) -> Style {
match status {
Status::Active { is_checked } => styled(
palette.danger.base.text,
+ palette.background.strongest.color,
palette.background.base,
palette.danger.base,
is_checked,
),
Status::Hovered { is_checked } => styled(
palette.danger.base.text,
+ palette.background.strongest.color,
palette.background.weak,
- palette.danger.base,
+ palette.danger.strong,
is_checked,
),
Status::Disabled { is_checked } => styled(
palette.danger.base.text,
+ palette.background.weak.color,
palette.background.weak,
palette.danger.weak,
is_checked,
@@ -654,6 +666,7 @@ pub fn danger(theme: &Theme, status: Status) -> Style {
fn styled(
icon_color: Color,
+ border_color: Color,
base: palette::Pair,
accent: palette::Pair,
is_checked: bool,
@@ -668,7 +681,11 @@ fn styled(
border: Border {
radius: 2.0.into(),
width: 1.0,
- color: accent.color,
+ color: if is_checked {
+ accent.color
+ } else {
+ border_color
+ },
},
text_color: None,
}
diff --git a/widget/src/container.rs b/widget/src/container.rs
index da5b436f..82774186 100644
--- a/widget/src/container.rs
+++ b/widget/src/container.rs
@@ -703,10 +703,10 @@ pub fn bordered_box(theme: &Theme) -> Style {
let palette = theme.extended_palette();
Style {
- background: Some(palette.background.weak.color.into()),
+ background: Some(palette.background.weakest.color.into()),
border: Border {
width: 1.0,
- radius: 0.0.into(),
+ radius: 5.0.into(),
color: palette.background.strong.color,
},
..Style::default()
diff --git a/widget/src/progress_bar.rs b/widget/src/progress_bar.rs
index 554e8a44..a9b4eb65 100644
--- a/widget/src/progress_bar.rs
+++ b/widget/src/progress_bar.rs
@@ -288,10 +288,7 @@ impl Catalog for Theme {
pub fn primary(theme: &Theme) -> Style {
let palette = theme.extended_palette();
- styled(
- palette.background.strong.color,
- palette.primary.strong.color,
- )
+ styled(palette.background.strong.color, palette.primary.base.color)
}
/// The secondary style of a [`ProgressBar`].
diff --git a/widget/src/slider.rs b/widget/src/slider.rs
index 1908abc9..1a2f8b9d 100644
--- a/widget/src/slider.rs
+++ b/widget/src/slider.rs
@@ -670,14 +670,14 @@ pub fn default(theme: &Theme, status: Status) -> Style {
let palette = theme.extended_palette();
let color = match status {
- Status::Active => palette.primary.strong.color,
- Status::Hovered => palette.primary.base.color,
- Status::Dragged => palette.primary.strong.color,
+ Status::Active => palette.primary.base.color,
+ Status::Hovered => palette.primary.strong.color,
+ Status::Dragged => palette.primary.weak.color,
};
Style {
rail: Rail {
- backgrounds: (color.into(), palette.secondary.base.color.into()),
+ backgrounds: (color.into(), palette.background.strong.color.into()),
width: 4.0,
border: Border {
radius: 2.0.into(),
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index 697d0d64..5b6ee9e0 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -1802,10 +1802,10 @@ pub fn default(theme: &Theme, status: Status) -> Style {
border: Border {
radius: 2.0.into(),
width: 1.0,
- color: palette.background.strong.color,
+ color: palette.background.strongest.color,
},
icon: palette.background.weak.text,
- placeholder: palette.background.strong.color,
+ placeholder: palette.background.strongest.color,
value: palette.background.base.text,
selection: palette.primary.weak.color,
};