Merge pull request #2936 from mariinkys/add_toast_warning
Add `warning` status to `toast` example
This commit is contained in:
commit
bdeeaaade5
1 changed files with 14 additions and 39 deletions
|
|
@ -169,7 +169,6 @@ mod toast {
|
||||||
use iced::advanced::widget::{self, Operation, Tree};
|
use iced::advanced::widget::{self, Operation, Tree};
|
||||||
use iced::advanced::{Clipboard, Shell, Widget};
|
use iced::advanced::{Clipboard, Shell, Widget};
|
||||||
use iced::mouse;
|
use iced::mouse;
|
||||||
use iced::theme;
|
|
||||||
use iced::time::{self, Duration, Instant};
|
use iced::time::{self, Duration, Instant};
|
||||||
use iced::widget::{button, column, container, row, rule, space, text};
|
use iced::widget::{button, column, container, row, rule, space, text};
|
||||||
use iced::window;
|
use iced::window;
|
||||||
|
|
@ -187,11 +186,17 @@ mod toast {
|
||||||
Secondary,
|
Secondary,
|
||||||
Success,
|
Success,
|
||||||
Danger,
|
Danger,
|
||||||
|
Warning,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub const ALL: &'static [Self] =
|
pub const ALL: &'static [Self] = &[
|
||||||
&[Self::Primary, Self::Secondary, Self::Success, Self::Danger];
|
Self::Primary,
|
||||||
|
Self::Secondary,
|
||||||
|
Self::Success,
|
||||||
|
Self::Danger,
|
||||||
|
Self::Warning,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Status {
|
impl fmt::Display for Status {
|
||||||
|
|
@ -201,6 +206,7 @@ mod toast {
|
||||||
Status::Secondary => "Secondary",
|
Status::Secondary => "Secondary",
|
||||||
Status::Success => "Success",
|
Status::Success => "Success",
|
||||||
Status::Danger => "Danger",
|
Status::Danger => "Danger",
|
||||||
|
Status::Warning => "Warning",
|
||||||
}
|
}
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
@ -247,10 +253,11 @@ mod toast {
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.style(match toast.status {
|
.style(match toast.status {
|
||||||
Status::Primary => primary,
|
Status::Primary => container::primary,
|
||||||
Status::Secondary => secondary,
|
Status::Secondary => container::secondary,
|
||||||
Status::Success => success,
|
Status::Success => container::success,
|
||||||
Status::Danger => danger,
|
Status::Danger => container::danger,
|
||||||
|
Status::Warning => container::warning,
|
||||||
}),
|
}),
|
||||||
rule::horizontal(1),
|
rule::horizontal(1),
|
||||||
container(text(toast.body.as_str()))
|
container(text(toast.body.as_str()))
|
||||||
|
|
@ -632,36 +639,4 @@ mod toast {
|
||||||
Element::new(manager)
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue