From 9e2f7b2d50a39db31465ca094a53ee274e7c468f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 13:10:11 +0200 Subject: [PATCH 01/10] Added warning field to palette and assigned colors to it in the LIGHT, DARK, DRACULA, NORD and SOLARIZED(both) themes --- core/src/theme/palette.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index e0ff397ab0..0aa904ee16 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -19,6 +19,8 @@ pub struct Palette { pub success: Color, /// The danger [`Color`] of the [`Palette`]. pub danger: Color, + /// The warning [`Color`] of the [`Palette`]. + pub warning: Color, } impl Palette { @@ -41,6 +43,11 @@ impl Palette { 0x42 as f32 / 255.0, 0x3F as f32 / 255.0, ), + warning: Color::from_rgb( + 0xFF as f32 / 255.0, + 0xC1 as f32 / 255.0, + 0x4E as f32 / 255.0, + ), }; /// The built-in dark variant of a [`Palette`]. @@ -66,6 +73,11 @@ impl Palette { 0x42 as f32 / 255.0, 0x3F as f32 / 255.0, ), + warning: Color::from_rgb( + 0xFF as f32 / 255.0, + 0xC1 as f32 / 255.0, + 0x4E as f32 / 255.0, + ), }; /// The built-in [Dracula] variant of a [`Palette`]. @@ -77,6 +89,7 @@ impl Palette { primary: color!(0xbd93f9), // PURPLE success: color!(0x50fa7b), // GREEN danger: color!(0xff5555), // RED + warning: color!(0xf1fa8c), // YELLOW }; /// The built-in [Nord] variant of a [`Palette`]. @@ -88,6 +101,7 @@ impl Palette { primary: color!(0x8fbcbb), // nord7 success: color!(0xa3be8c), // nord14 danger: color!(0xbf616a), // nord11 + warning: color!(0xebcb8b), // nord13 }; /// The built-in [Solarized] Light variant of a [`Palette`]. @@ -99,6 +113,7 @@ impl Palette { primary: color!(0x2aa198), // cyan success: color!(0x859900), // green danger: color!(0xdc322f), // red + warning: color!(0xb58900), // yellow }; /// The built-in [Solarized] Dark variant of a [`Palette`]. @@ -110,6 +125,7 @@ impl Palette { primary: color!(0x2aa198), // cyan success: color!(0x859900), // green danger: color!(0xdc322f), // red + warning: color!(0xb58900), // yellow }; /// The built-in [Gruvbox] Light variant of a [`Palette`]. From c768aba64cd5c7e14e2527bd56fed19b80e28823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 13:20:13 +0200 Subject: [PATCH 02/10] Added color for warning for GRUVBOX and CATPPUCCIN --- core/src/theme/palette.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 0aa904ee16..05b8008cc1 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -137,6 +137,7 @@ impl Palette { primary: color!(0x458588), // light BLUE_4 success: color!(0x98971a), // light GREEN_2 danger: color!(0xcc241d), // light RED_1 + warning: color!(0xd79921), // light YELLOW_3 }; /// The built-in [Gruvbox] Dark variant of a [`Palette`]. @@ -148,6 +149,7 @@ impl Palette { primary: color!(0x458588), // dark BLUE_4 success: color!(0x98971a), // dark GREEN_2 danger: color!(0xcc241d), // dark RED_1 + warning: color!(0xd79921), // dark YELLOW_3 }; /// The built-in [Catppuccin] Latte variant of a [`Palette`]. @@ -159,6 +161,7 @@ impl Palette { primary: color!(0x1e66f5), // Blue success: color!(0x40a02b), // Green danger: color!(0xd20f39), // Red + warning: color!(0xdf8e1d), // Yellow }; /// The built-in [Catppuccin] Frappé variant of a [`Palette`]. @@ -170,6 +173,7 @@ impl Palette { primary: color!(0x8caaee), // Blue success: color!(0xa6d189), // Green danger: color!(0xe78284), // Red + warning: color!(0xe5c890), // Yellow }; /// The built-in [Catppuccin] Macchiato variant of a [`Palette`]. @@ -181,6 +185,7 @@ impl Palette { primary: color!(0x8aadf4), // Blue success: color!(0xa6da95), // Green danger: color!(0xed8796), // Red + warning: color!(0xeed49f), // Yellow }; /// The built-in [Catppuccin] Mocha variant of a [`Palette`]. @@ -192,6 +197,7 @@ impl Palette { primary: color!(0x89b4fa), // Blue success: color!(0xa6e3a1), // Green danger: color!(0xf38ba8), // Red + warning: color!(0xf9e2af), // Yellow }; /// The built-in [Tokyo Night] variant of a [`Palette`]. From 91439dc172d0a6ed66c236baa38939615b38a730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 13:37:55 +0200 Subject: [PATCH 03/10] Added color for warning for TOKYO_NIGHT and KANAGAWA --- core/src/theme/palette.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 05b8008cc1..fd4f15d2ab 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -209,6 +209,7 @@ impl Palette { primary: color!(0x2ac3de), // Blue success: color!(0x9ece6a), // Green danger: color!(0xf7768e), // Red + warning: color!(0xe0af68), // Yellow }; /// The built-in [Tokyo Night] Storm variant of a [`Palette`]. @@ -220,6 +221,7 @@ impl Palette { primary: color!(0x2ac3de), // Blue success: color!(0x9ece6a), // Green danger: color!(0xf7768e), // Red + warning: color!(0xe0af68), // Yellow }; /// The built-in [Tokyo Night] Light variant of a [`Palette`]. @@ -231,6 +233,7 @@ impl Palette { primary: color!(0x166775), // Blue success: color!(0x485e30), // Green danger: color!(0x8c4351), // Red + warning: color!(0x8f5e15), // Yellow }; /// The built-in [Kanagawa] Wave variant of a [`Palette`]. @@ -242,6 +245,7 @@ impl Palette { primary: color!(0x2D4F67), // Wave Blue 2 success: color!(0x76946A), // Autumn Green danger: color!(0xC34043), // Autumn Red + warning: color!(0xff9e3b), // Ronin Yellow }; /// The built-in [Kanagawa] Dragon variant of a [`Palette`]. @@ -253,6 +257,7 @@ impl Palette { primary: color!(0x223249), // Wave Blue 1 success: color!(0x8a9a7b), // Dragon Green 2 danger: color!(0xc4746e), // Dragon Red + warning: color!(0xff9e3b), // Ronin Yellow }; /// The built-in [Kanagawa] Lotus variant of a [`Palette`]. @@ -264,6 +269,7 @@ impl Palette { primary: color!(0xc9cbd1), // Lotus Violet 3 success: color!(0x6f894e), // Lotus Green danger: color!(0xc84053), // Lotus Red + warning: color!(0xe98a00), // Lotus Orange 2 }; /// The built-in [Moonfly] variant of a [`Palette`]. From c3aefdc27b1b1f1825beb1cb4621022971fbb31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 13:52:34 +0200 Subject: [PATCH 04/10] Added color for warning for MOONFLY and NIGHTFLY --- core/src/theme/palette.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index fd4f15d2ab..31df15e9ba 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -281,6 +281,7 @@ impl Palette { primary: color!(0x80a0ff), // Blue (normal) success: color!(0x8cc85f), // Green (normal) danger: color!(0xff5454), // Red (normal) + warning: color!(0xe3c78a), // Yellow (normal) }; /// The built-in [Nightfly] variant of a [`Palette`]. @@ -292,6 +293,7 @@ impl Palette { primary: color!(0x82aaff), // Blue (normal) success: color!(0xa1cd5e), // Green (normal) danger: color!(0xfc514e), // Red (normal) + warning: color!(0xe3d18a), // Yellow (normal) }; /// The built-in [Oxocarbon] variant of a [`Palette`]. From 39f2cdd9466d35201e1e4c7e4b2209a7fdeb74de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 13:53:04 +0200 Subject: [PATCH 05/10] Added color for warning for OXOCARBON, used a purple since it is the one used for diagnostic warnings in the nvim theme --- core/src/theme/palette.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 31df15e9ba..83803c9aaa 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -305,6 +305,7 @@ impl Palette { primary: color!(0x00b4ff), success: color!(0x00c15a), danger: color!(0xf62d0f), + warning: color!(0xbe95ff), // Base 14 }; /// The built-in [Ferra] variant of a [`Palette`]. From 3bc836827a808d17e7575923059904b7d2dbcc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 14:48:00 +0200 Subject: [PATCH 06/10] Added color for warning for TERRA, and added warning field to Extended with the needed struct and generate --- core/src/theme/palette.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 83803c9aaa..d4ec84f2e0 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -317,6 +317,7 @@ impl Palette { primary: color!(0xd1d1e0), success: color!(0xb1b695), danger: color!(0xe06b75), + warning: color!(0xf5d76e), // Honey }; } @@ -333,6 +334,8 @@ pub struct Extended { pub success: Success, /// The set of danger colors. pub danger: Danger, + /// The set of warning colors. + pub warning: Warning, /// Whether the palette is dark or not. pub is_dark: bool, } @@ -446,6 +449,11 @@ impl Extended { palette.background, palette.text, ), + warning: Warning::generate( + palette.warning, + palette.background, + palette.text, + ), is_dark: is_dark(palette.background), } } @@ -601,6 +609,31 @@ impl Danger { } } +/// A set of warning colors. +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Warning { + /// The base warning color. + pub base: Pair, + /// A weaker version of the base warning color. + pub weak: Pair, + /// A stronger version of the base warning color. + pub strong: Pair, +} + +impl Warning { + /// Generates a set of [`Warning`] 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); + + Self { + base: Pair::new(base, text), + weak: Pair::new(weak, text), + strong: Pair::new(strong, text), + } + } +} + fn darken(color: Color, amount: f32) -> Color { let mut hsl = to_hsl(color); From feef71a382f9ff87b2f2b7da5e7f31b6a18af388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Aguil=C3=B3=20Dom=C3=ADnguez?= Date: Wed, 25 Sep 2024 15:25:54 +0200 Subject: [PATCH 07/10] Moved warning to be between success and danger --- core/src/theme/palette.rs | 104 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index d4ec84f2e0..00c3801981 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -17,10 +17,10 @@ pub struct Palette { pub primary: Color, /// The success [`Color`] of the [`Palette`]. pub success: Color, - /// The danger [`Color`] of the [`Palette`]. - pub danger: Color, /// The warning [`Color`] of the [`Palette`]. pub warning: Color, + /// The danger [`Color`] of the [`Palette`]. + pub danger: Color, } impl Palette { @@ -38,16 +38,16 @@ impl Palette { 0x66 as f32 / 255.0, 0x4F as f32 / 255.0, ), - danger: Color::from_rgb( - 0xC3 as f32 / 255.0, - 0x42 as f32 / 255.0, - 0x3F as f32 / 255.0, - ), warning: Color::from_rgb( 0xFF as f32 / 255.0, 0xC1 as f32 / 255.0, 0x4E as f32 / 255.0, ), + danger: Color::from_rgb( + 0xC3 as f32 / 255.0, + 0x42 as f32 / 255.0, + 0x3F as f32 / 255.0, + ), }; /// The built-in dark variant of a [`Palette`]. @@ -68,16 +68,16 @@ impl Palette { 0x66 as f32 / 255.0, 0x4F as f32 / 255.0, ), - danger: Color::from_rgb( - 0xC3 as f32 / 255.0, - 0x42 as f32 / 255.0, - 0x3F as f32 / 255.0, - ), warning: Color::from_rgb( 0xFF as f32 / 255.0, 0xC1 as f32 / 255.0, 0x4E as f32 / 255.0, ), + danger: Color::from_rgb( + 0xC3 as f32 / 255.0, + 0x42 as f32 / 255.0, + 0x3F as f32 / 255.0, + ), }; /// The built-in [Dracula] variant of a [`Palette`]. @@ -88,8 +88,8 @@ impl Palette { text: color!(0xf8f8f2), // FOREGROUND primary: color!(0xbd93f9), // PURPLE success: color!(0x50fa7b), // GREEN - danger: color!(0xff5555), // RED warning: color!(0xf1fa8c), // YELLOW + danger: color!(0xff5555), // RED }; /// The built-in [Nord] variant of a [`Palette`]. @@ -100,8 +100,8 @@ impl Palette { text: color!(0xeceff4), // nord6 primary: color!(0x8fbcbb), // nord7 success: color!(0xa3be8c), // nord14 - danger: color!(0xbf616a), // nord11 warning: color!(0xebcb8b), // nord13 + danger: color!(0xbf616a), // nord11 }; /// The built-in [Solarized] Light variant of a [`Palette`]. @@ -112,8 +112,8 @@ impl Palette { text: color!(0x657b83), // base00 primary: color!(0x2aa198), // cyan success: color!(0x859900), // green - danger: color!(0xdc322f), // red warning: color!(0xb58900), // yellow + danger: color!(0xdc322f), // red }; /// The built-in [Solarized] Dark variant of a [`Palette`]. @@ -124,8 +124,8 @@ impl Palette { text: color!(0x839496), // base0 primary: color!(0x2aa198), // cyan success: color!(0x859900), // green - danger: color!(0xdc322f), // red warning: color!(0xb58900), // yellow + danger: color!(0xdc322f), // red }; /// The built-in [Gruvbox] Light variant of a [`Palette`]. @@ -136,8 +136,8 @@ impl Palette { text: color!(0x282828), // light FG0_29 primary: color!(0x458588), // light BLUE_4 success: color!(0x98971a), // light GREEN_2 - danger: color!(0xcc241d), // light RED_1 warning: color!(0xd79921), // light YELLOW_3 + danger: color!(0xcc241d), // light RED_1 }; /// The built-in [Gruvbox] Dark variant of a [`Palette`]. @@ -148,8 +148,8 @@ impl Palette { text: color!(0xfbf1c7), // dark FG0_29 primary: color!(0x458588), // dark BLUE_4 success: color!(0x98971a), // dark GREEN_2 - danger: color!(0xcc241d), // dark RED_1 warning: color!(0xd79921), // dark YELLOW_3 + danger: color!(0xcc241d), // dark RED_1 }; /// The built-in [Catppuccin] Latte variant of a [`Palette`]. @@ -160,8 +160,8 @@ impl Palette { text: color!(0x4c4f69), // Text primary: color!(0x1e66f5), // Blue success: color!(0x40a02b), // Green - danger: color!(0xd20f39), // Red warning: color!(0xdf8e1d), // Yellow + danger: color!(0xd20f39), // Red }; /// The built-in [Catppuccin] Frappé variant of a [`Palette`]. @@ -172,8 +172,8 @@ impl Palette { text: color!(0xc6d0f5), // Text primary: color!(0x8caaee), // Blue success: color!(0xa6d189), // Green - danger: color!(0xe78284), // Red warning: color!(0xe5c890), // Yellow + danger: color!(0xe78284), // Red }; /// The built-in [Catppuccin] Macchiato variant of a [`Palette`]. @@ -184,8 +184,8 @@ impl Palette { text: color!(0xcad3f5), // Text primary: color!(0x8aadf4), // Blue success: color!(0xa6da95), // Green - danger: color!(0xed8796), // Red warning: color!(0xeed49f), // Yellow + danger: color!(0xed8796), // Red }; /// The built-in [Catppuccin] Mocha variant of a [`Palette`]. @@ -196,8 +196,8 @@ impl Palette { text: color!(0xcdd6f4), // Text primary: color!(0x89b4fa), // Blue success: color!(0xa6e3a1), // Green - danger: color!(0xf38ba8), // Red warning: color!(0xf9e2af), // Yellow + danger: color!(0xf38ba8), // Red }; /// The built-in [Tokyo Night] variant of a [`Palette`]. @@ -208,8 +208,8 @@ impl Palette { text: color!(0x9aa5ce), // Text primary: color!(0x2ac3de), // Blue success: color!(0x9ece6a), // Green - danger: color!(0xf7768e), // Red warning: color!(0xe0af68), // Yellow + danger: color!(0xf7768e), // Red }; /// The built-in [Tokyo Night] Storm variant of a [`Palette`]. @@ -220,8 +220,8 @@ impl Palette { text: color!(0x9aa5ce), // Text primary: color!(0x2ac3de), // Blue success: color!(0x9ece6a), // Green - danger: color!(0xf7768e), // Red warning: color!(0xe0af68), // Yellow + danger: color!(0xf7768e), // Red }; /// The built-in [Tokyo Night] Light variant of a [`Palette`]. @@ -232,8 +232,8 @@ impl Palette { text: color!(0x565a6e), // Text primary: color!(0x166775), // Blue success: color!(0x485e30), // Green - danger: color!(0x8c4351), // Red warning: color!(0x8f5e15), // Yellow + danger: color!(0x8c4351), // Red }; /// The built-in [Kanagawa] Wave variant of a [`Palette`]. @@ -244,8 +244,8 @@ impl Palette { text: color!(0xCD7BA), // Fuji White primary: color!(0x2D4F67), // Wave Blue 2 success: color!(0x76946A), // Autumn Green - danger: color!(0xC34043), // Autumn Red warning: color!(0xff9e3b), // Ronin Yellow + danger: color!(0xC34043), // Autumn Red }; /// The built-in [Kanagawa] Dragon variant of a [`Palette`]. @@ -256,8 +256,8 @@ impl Palette { text: color!(0xc5c9c5), // Dragon White primary: color!(0x223249), // Wave Blue 1 success: color!(0x8a9a7b), // Dragon Green 2 - danger: color!(0xc4746e), // Dragon Red warning: color!(0xff9e3b), // Ronin Yellow + danger: color!(0xc4746e), // Dragon Red }; /// The built-in [Kanagawa] Lotus variant of a [`Palette`]. @@ -268,8 +268,8 @@ impl Palette { text: color!(0x545464), // Lotus Ink 1 primary: color!(0xc9cbd1), // Lotus Violet 3 success: color!(0x6f894e), // Lotus Green - danger: color!(0xc84053), // Lotus Red warning: color!(0xe98a00), // Lotus Orange 2 + danger: color!(0xc84053), // Lotus Red }; /// The built-in [Moonfly] variant of a [`Palette`]. @@ -280,8 +280,8 @@ impl Palette { text: color!(0xbdbdbd), // Foreground primary: color!(0x80a0ff), // Blue (normal) success: color!(0x8cc85f), // Green (normal) - danger: color!(0xff5454), // Red (normal) warning: color!(0xe3c78a), // Yellow (normal) + danger: color!(0xff5454), // Red (normal) }; /// The built-in [Nightfly] variant of a [`Palette`]. @@ -292,8 +292,8 @@ impl Palette { text: color!(0xbdc1c6), // Foreground primary: color!(0x82aaff), // Blue (normal) success: color!(0xa1cd5e), // Green (normal) - danger: color!(0xfc514e), // Red (normal) warning: color!(0xe3d18a), // Yellow (normal) + danger: color!(0xfc514e), // Red (normal) }; /// The built-in [Oxocarbon] variant of a [`Palette`]. @@ -304,8 +304,8 @@ impl Palette { text: color!(0xd0d0d0), primary: color!(0x00b4ff), success: color!(0x00c15a), - danger: color!(0xf62d0f), warning: color!(0xbe95ff), // Base 14 + danger: color!(0xf62d0f), }; /// The built-in [Ferra] variant of a [`Palette`]. @@ -316,8 +316,8 @@ impl Palette { text: color!(0xfecdb2), primary: color!(0xd1d1e0), success: color!(0xb1b695), - danger: color!(0xe06b75), warning: color!(0xf5d76e), // Honey + danger: color!(0xe06b75), }; } @@ -332,10 +332,10 @@ pub struct Extended { pub secondary: Secondary, /// The set of success colors. pub success: Success, - /// The set of danger colors. - pub danger: Danger, /// The set of warning colors. pub warning: Warning, + /// The set of danger colors. + pub danger: Danger, /// Whether the palette is dark or not. pub is_dark: bool, } @@ -444,13 +444,13 @@ impl Extended { palette.background, palette.text, ), - danger: Danger::generate( - palette.danger, + warning: Warning::generate( + palette.warning, palette.background, palette.text, ), - warning: Warning::generate( - palette.warning, + danger: Danger::generate( + palette.danger, palette.background, palette.text, ), @@ -584,19 +584,19 @@ impl Success { } } -/// A set of danger colors. +/// A set of warning colors. #[derive(Debug, Clone, Copy, PartialEq)] -pub struct Danger { - /// The base danger color. +pub struct Warning { + /// The base warning color. pub base: Pair, - /// A weaker version of the base danger color. + /// A weaker version of the base warning color. pub weak: Pair, - /// A stronger version of the base danger color. + /// A stronger version of the base warning color. pub strong: Pair, } -impl Danger { - /// Generates a set of [`Danger`] colors from the base, background, and text colors. +impl Warning { + /// Generates a set of [`Warning`] 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); @@ -609,19 +609,19 @@ impl Danger { } } -/// A set of warning colors. +/// A set of danger colors. #[derive(Debug, Clone, Copy, PartialEq)] -pub struct Warning { - /// The base warning color. +pub struct Danger { + /// The base danger color. pub base: Pair, - /// A weaker version of the base warning color. + /// A weaker version of the base danger color. pub weak: Pair, - /// A stronger version of the base warning color. + /// A stronger version of the base danger color. pub strong: Pair, } -impl Warning { - /// Generates a set of [`Warning`] colors from the base, background, and text colors. +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); From e01fb00d3b98de9cda60655c935ac3163f72926c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 6 Jan 2025 20:36:34 +0100 Subject: [PATCH 08/10] Fix missing `warning` field in `color_palette` example --- examples/color_palette/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/color_palette/src/main.rs b/examples/color_palette/src/main.rs index 7f21003b29..1a86b168f1 100644 --- a/examples/color_palette/src/main.rs +++ b/examples/color_palette/src/main.rs @@ -89,6 +89,7 @@ impl ColorPalette { primary: *self.theme.lower.first().unwrap(), text: *self.theme.higher.last().unwrap(), success: *self.theme.lower.last().unwrap(), + warning: *self.theme.higher.last().unwrap(), danger: *self.theme.higher.last().unwrap(), }, ) From edbb318cbd0d2f6263976eed40d58ce2c3468c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 6 Jan 2025 21:05:13 +0100 Subject: [PATCH 09/10] Add `warning` style for `button` --- widget/src/button.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/widget/src/button.rs b/widget/src/button.rs index a2f9945c19..11839d5eb2 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -633,6 +633,21 @@ pub fn success(theme: &Theme, status: Status) -> Style { } } +/// A warning button; denoting a risky action. +pub fn warning(theme: &Theme, status: Status) -> Style { + let palette = theme.extended_palette(); + let base = styled(palette.warning.base); + + match status { + Status::Active | Status::Pressed => base, + Status::Hovered => Style { + background: Some(Background::Color(palette.warning.strong.color)), + ..base + }, + Status::Disabled => disabled(base), + } +} + /// A danger button; denoting a destructive action. pub fn danger(theme: &Theme, status: Status) -> Style { let palette = theme.extended_palette(); From 8fc57628a0e95c8154c5000fd7ef92fa3c3cd82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 6 Jan 2025 21:05:29 +0100 Subject: [PATCH 10/10] Showcase different `button` styles in `styling` example --- examples/styling/src/main.rs | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index 534f5e32b0..594be4a7d0 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -1,12 +1,14 @@ +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, }; -use iced::{Center, Element, Fill, Theme}; +use iced::{Center, Element, Fill, Subscription, Theme}; pub fn main() -> iced::Result { iced::application("Styling - Iced", Styling::update, Styling::view) + .subscription(Styling::subscription) .theme(Styling::theme) .run() } @@ -28,6 +30,8 @@ enum Message { SliderChanged(f32), CheckboxToggled(bool), TogglerToggled(bool), + PreviousTheme, + NextTheme, } impl Styling { @@ -41,6 +45,23 @@ impl Styling { Message::SliderChanged(value) => self.slider_value = value, Message::CheckboxToggled(value) => self.checkbox_value = value, Message::TogglerToggled(value) => self.toggler_value = value, + Message::PreviousTheme | Message::NextTheme => { + if let Some(current) = Theme::ALL + .iter() + .position(|candidate| &self.theme == candidate) + { + self.theme = if matches!(message, Message::NextTheme) { + Theme::ALL[(current + 1) % Theme::ALL.len()].clone() + } else if current == 0 { + Theme::ALL + .last() + .expect("Theme::ALL must not be empty") + .clone() + } else { + Theme::ALL[current - 1].clone() + }; + } + } } } @@ -57,9 +78,16 @@ impl Styling { .padding(10) .size(20); - let button = button("Submit") - .padding(10) - .on_press(Message::ButtonPressed); + let styled_button = |label| { + button(text(label).width(Fill).center()) + .padding(10) + .on_press(Message::ButtonPressed) + }; + + let primary = styled_button("Primary"); + let success = styled_button("Success").style(button::success); + let warning = styled_button("Warning").style(button::warning); + let danger = styled_button("Danger").style(button::danger); let slider = slider(0.0..=100.0, self.slider_value, Message::SliderChanged); @@ -85,7 +113,10 @@ impl Styling { let content = column![ choose_theme, horizontal_rule(38), - row![text_input, button].spacing(10).align_y(Center), + text_input, + row![primary, success, warning, danger] + .spacing(10) + .align_y(Center), slider, progress_bar, row![ @@ -104,6 +135,19 @@ impl Styling { center(content).into() } + fn subscription(&self) -> Subscription { + keyboard::on_key_press(|key, _modifiers| match key { + keyboard::Key::Named( + keyboard::key::Named::ArrowUp | keyboard::key::Named::ArrowLeft, + ) => Some(Message::PreviousTheme), + keyboard::Key::Named( + keyboard::key::Named::ArrowDown + | keyboard::key::Named::ArrowRight, + ) => Some(Message::NextTheme), + _ => None, + }) + } + fn theme(&self) -> Theme { self.theme.clone() }