Skip to main content

ToastEngine

Struct ToastEngine 

Source
pub struct ToastEngine<A>
where A: From<ToastMessage> + Send + 'static,
{ /* private fields */ }
Expand description

A toast engine for displaying temporary messages in a terminal UI. The ToastEngine manages the display of toasts, which are temporary messages that appear on the screen for a short duration. It supports different types of toasts (info, success, warning, error) and allows customization of their position and duration. You can call show_toast to display a toast, and hide_toast to hide the toast. To animate, you can get the area of the toast using toast_area and implement your animation logic based on that area. #[derive(Debug)] Caveat: If you’re not using the tokio feature, create a ToastEngine<()>. There is a (hacky) impl to make it work without the tokio feature.

Implementations§

Source§

impl<A> ToastEngine<A>
where A: From<ToastMessage> + Send + 'static,

Source

pub fn new(_: Self) -> Self

Creates a new ToastEngine. Consider using the ToastEngineBuilder instead.

Source

pub fn from_builder(_: ToastEngineBuilder<A>) -> Self

Creates a new ToastEngine from a ToastEngineBuilder. This method takes the configuration from the builder and initializes the ToastEngine accordingly. It sets up the area for displaying toasts, the default duration for toasts, and any channel sender if provided (when using the tokio feature).

Source

pub fn show_toast(&mut self, toast: ToastBuilder)

Shows a toast message using the provided ToastBuilder. This method calculates the area for the toast based on the message content and the specified position, creates a new Toast instance, and sets it as the current toast to be rendered. If the tokio feature is enabled and a channel sender is configured, it also spawns a task to automatically hide the toast after the default duration.

Source

pub fn toast_area(&self) -> Rect

Get the area where the toast will be rendered.

Source

pub fn has_toast(&self) -> bool

Whether a toast is currently being displayed.

Source

pub fn hide_toast(&mut self)

Hides the currently displayed toast, if any. This method sets the current toast to None, which will cause it to no longer be rendered on the screen.

Source

pub fn set_area(&mut self, area: Rect)

Sets the area for the toast engine. This method allows you to update the area where toasts will be displayed, which can be useful if the layout of your terminal UI changes and you need to adjust the toast display area accordingly.

Trait Implementations§

Source§

impl<A> Widget for &ToastEngine<A>
where A: From<ToastMessage> + Send + 'static,

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl<A> WidgetRef for ToastEngine<A>
where A: From<ToastMessage> + Send + 'static,

Source§

fn render_ref(&self, _area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<A> Freeze for ToastEngine<A>

§

impl<A> RefUnwindSafe for ToastEngine<A>
where A: RefUnwindSafe,

§

impl<A> Send for ToastEngine<A>

§

impl<A> Sync for ToastEngine<A>
where A: Sync,

§

impl<A> Unpin for ToastEngine<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for ToastEngine<A>

§

impl<A> UnwindSafe for ToastEngine<A>
where A: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.