Skip to main content

Toast

Struct Toast 

Source
pub struct Toast<Msg> { /* private fields */ }
Expand description

A notification: a status marker and icon, a title, an optional body and action, and the shared three-cell close mark at the end of the title row.

A title too long for its row wraps, the lines after the first running under the action and the close mark to the right edge, so a narrow screen or a longer language never cuts it. The action and the mark stay on the first row.

Only a press on the close mark dismisses a toast; a press on the rest of it does nothing unless on_press gives it a message, e.g. to open where the news came from.

Style keys: toast (bg, padding) with hover while the pointer is on a pressable toast, toast-title, toast-body, toast-action with active on a raised toast and hover, and close-mark (see tabs). The marker and icon use the success, warning, danger and info colours; an animated icon uses spinner with the kind as its variant.

Implementations§

Source§

impl<Msg> Toast<Msg>

Source

pub fn new(kind: ToastKind, title: impl Into<String>) -> Self

A toast of kind saying title.

Source

pub fn success(title: impl Into<String>) -> Self

A success toast.

Source

pub fn warning(title: impl Into<String>) -> Self

A warning toast.

Source

pub fn danger(title: impl Into<String>) -> Self

A danger toast.

Source

pub fn info(title: impl Into<String>) -> Self

An info toast.

Source

pub fn body(self, body: impl Into<String>) -> Self

A faint line of detail under the title, wrapped to the toast width.

Source

pub fn action(self, label: impl Into<String>, message: Msg) -> Self

A button on the title row; clicking it sends message and dismisses the toast.

Source

pub fn duration(self, duration: Duration) -> Self

How long the toast stays while the pointer is not on it. Default: 5 s, or 8 s with an action.

Source

pub fn key(self, key: impl Into<String>) -> Self

Names the toast: showing another toast with the same key replaces it, and Command::dismiss_toast removes it.

Source

pub fn icon_motion(self, animation: impl Into<AnimationName>) -> Self

Plays a one-cell Spinner animation in the icon cell instead of the kind’s icon, in the kind’s colour, e.g. SpinnerStyle::Pulse while something is still running. It takes a spinner style or the name of any cell animation, such as one a theme defines. With reduced motion the kind’s icon stands still instead. Replace the toast through its key with one without animation when the work is done.

use qframe::prelude::*;
use qframe::widgets::{SpinnerStyle, Toast};

let running: Toast<()> = Toast::info("Deploying api-gateway").icon_motion(SpinnerStyle::Pulse).key("deploy");
let done: Toast<()> = Toast::success("Deployed api-gateway").key("deploy");
let _ = Command::batch([Command::toast(running), Command::toast(done)]);
Source§

impl<Msg: Clone + 'static> Toast<Msg>

Source

pub fn on_press(self, message: Msg) -> Self

Makes the toast pressable: a press anywhere on it but its action and close mark sends message, e.g. to open the log or the page the news came from. The toast stays; only the close mark dismisses it. While the pointer is on it the toast rises one tone.

use qframe::prelude::*;
use qframe::widgets::Toast;

#[derive(Clone)]
enum Msg {
    OpenDeployLog,
}

let toast: Toast<Msg> = Toast::success("Deployed api-gateway").on_press(Msg::OpenDeployLog);
let _ = Command::toast(toast);

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Toast<Msg>

§

impl<Msg> !Send for Toast<Msg>

§

impl<Msg> !Sync for Toast<Msg>

§

impl<Msg> !UnwindSafe for Toast<Msg>

§

impl<Msg> Freeze for Toast<Msg>
where Option<(String, Msg)>: Freeze, Option<Box<dyn Fn() -> Msg>>: Freeze,

§

impl<Msg> Unpin for Toast<Msg>
where Option<(String, Msg)>: Unpin, Option<Box<dyn Fn() -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Toast<Msg>
where Option<(String, Msg)>: UnsafeUnpin, Option<Box<dyn Fn() -> Msg>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.