summaryrefslogtreecommitdiffstats
path: root/style/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-26 01:10:26 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-26 01:10:26 +0200
commit822a3cd04f9edeb887d85164b0b3e556c3fde6bb (patch)
treea9696674d844af5892f46daef6d36407fb076383 /style/src
parent3a820b45f336398c48f8bedf7b8c4b8af876efff (diff)
downloadiced-822a3cd04f9edeb887d85164b0b3e556c3fde6bb.tar.gz
iced-822a3cd04f9edeb887d85164b0b3e556c3fde6bb.tar.bz2
iced-822a3cd04f9edeb887d85164b0b3e556c3fde6bb.zip
Let a `Theme` control the `text_color` of an application
Diffstat (limited to 'style/src')
-rw-r--r--style/src/theme.rs10
-rw-r--r--style/src/theme/palette.rs40
2 files changed, 34 insertions, 16 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs
index e3c0efc6..1ddf97c3 100644
--- a/style/src/theme.rs
+++ b/style/src/theme.rs
@@ -31,12 +31,14 @@ impl Theme {
impl Default for Theme {
fn default() -> Self {
- Self::Light
+ Self::Dark
}
}
pub trait Definition {
fn background_color(&self) -> Color;
+
+ fn text_color(&self) -> Color;
}
impl Definition for Theme {
@@ -45,6 +47,12 @@ impl Definition for Theme {
palette.background.base
}
+
+ fn text_color(&self) -> Color {
+ let palette = self.extended_palette();
+
+ palette.background.text
+ }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
diff --git a/style/src/theme/palette.rs b/style/src/theme/palette.rs
index bbb122ef..0394700b 100644
--- a/style/src/theme/palette.rs
+++ b/style/src/theme/palette.rs
@@ -34,8 +34,12 @@ impl Palette {
};
pub const DARK: Self = Self {
- background: Color::WHITE,
- text: Color::BLACK,
+ background: Color::from_rgb(
+ 0x20 as f32 / 255.0,
+ 0x22 as f32 / 255.0,
+ 0x25 as f32 / 255.0,
+ ),
+ text: Color::from_rgb(0.90, 0.90, 0.90),
primary: Color::from_rgb(
0x5E as f32 / 255.0,
0x7C as f32 / 255.0,
@@ -119,21 +123,17 @@ pub struct Group {
impl Group {
pub fn new(base: Color, background: Color, text: Color) -> Self {
+ let strong = if is_dark(base) {
+ lighten(base, 0.1)
+ } else {
+ darken(base, 0.1)
+ };
+
Self {
base,
weak: mix(base, background, 0.4),
- strong: if is_dark(background) {
- lighten(base, 0.1)
- } else {
- darken(base, 0.1)
- },
- text: if is_readable(base, text) {
- text
- } else if is_dark(text) {
- Color::WHITE
- } else {
- Color::BLACK
- },
+ strong,
+ text: readable(strong, text),
}
}
}
@@ -184,8 +184,18 @@ fn lighten(color: Color, amount: f32) -> Color {
from_hsl(hsl)
}
+fn readable(background: Color, text: Color) -> Color {
+ if is_readable(background, text) {
+ text
+ } else if is_dark(background) {
+ Color::WHITE
+ } else {
+ Color::BLACK
+ }
+}
+
fn is_dark(color: Color) -> bool {
- to_hsl(color).lightness < 0.5
+ to_hsl(color).lightness < 0.6
}
fn is_readable(a: Color, b: Color) -> bool {