From 1b40f89fdd0c5552bd6a77c0d838ddca8e8646f4 Mon Sep 17 00:00:00 2001 From: mariinkys Date: Wed, 7 May 2025 15:20:44 +0200 Subject: [PATCH 1/2] add warning status to toast --- examples/toast/src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index cca0e789..5dbd9daa 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -187,11 +187,17 @@ mod toast { Secondary, Success, Danger, + Warning, } impl Status { - pub const ALL: &'static [Self] = - &[Self::Primary, Self::Secondary, Self::Success, Self::Danger]; + pub const ALL: &'static [Self] = &[ + Self::Primary, + Self::Secondary, + Self::Success, + Self::Danger, + Self::Warning, + ]; } impl fmt::Display for Status { @@ -201,6 +207,7 @@ mod toast { Status::Secondary => "Secondary", Status::Success => "Success", Status::Danger => "Danger", + Status::Warning => "Warning", } .fmt(f) } @@ -251,6 +258,7 @@ mod toast { Status::Secondary => secondary, Status::Success => success, Status::Danger => danger, + Status::Warning => warning, }), rule::horizontal(1), container(text(toast.body.as_str())) @@ -664,4 +672,10 @@ mod toast { styled(palette.danger.weak) } + + fn warning(theme: &Theme) -> container::Style { + let palette = theme.extended_palette(); + + styled(palette.warning.weak) + } } From 30d9a2ff57f5880ded5895786683938fe5528c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 25 Nov 2025 23:19:49 +0100 Subject: [PATCH 2/2] Use `container` style helpers directly in `toast` example --- examples/toast/src/main.rs | 49 ++++---------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index 5dbd9daa..47749e8e 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -169,7 +169,6 @@ mod toast { use iced::advanced::widget::{self, Operation, Tree}; use iced::advanced::{Clipboard, Shell, Widget}; use iced::mouse; - use iced::theme; use iced::time::{self, Duration, Instant}; use iced::widget::{button, column, container, row, rule, space, text}; use iced::window; @@ -254,11 +253,11 @@ mod toast { .width(Fill) .padding(5) .style(match toast.status { - Status::Primary => primary, - Status::Secondary => secondary, - Status::Success => success, - Status::Danger => danger, - Status::Warning => warning, + Status::Primary => container::primary, + Status::Secondary => container::secondary, + Status::Success => container::success, + Status::Danger => container::danger, + Status::Warning => container::warning, }), rule::horizontal(1), container(text(toast.body.as_str())) @@ -640,42 +639,4 @@ mod toast { Element::new(manager) } } - - fn styled(pair: theme::palette::Pair) -> container::Style { - container::Style { - background: Some(pair.color.into()), - text_color: pair.text.into(), - ..Default::default() - } - } - - fn primary(theme: &Theme) -> container::Style { - let palette = theme.extended_palette(); - - styled(palette.primary.weak) - } - - fn secondary(theme: &Theme) -> container::Style { - let palette = theme.extended_palette(); - - styled(palette.secondary.weak) - } - - fn success(theme: &Theme) -> container::Style { - let palette = theme.extended_palette(); - - styled(palette.success.weak) - } - - fn danger(theme: &Theme) -> container::Style { - let palette = theme.extended_palette(); - - styled(palette.danger.weak) - } - - fn warning(theme: &Theme) -> container::Style { - let palette = theme.extended_palette(); - - styled(palette.warning.weak) - } }