pub struct Toast {
pub id: ToastId,
pub content: ToastContent,
pub config: ToastConfig,
pub state: ToastState,
pub actions: Vec<ToastAction>,
/* private fields */
}Expand description
A toast notification widget.
Toasts display transient messages to the user, typically in a corner of the screen. They can auto-dismiss after a duration or be manually dismissed.
§Example
let toast = Toast::new("Operation completed")
.icon(ToastIcon::Success)
.position(ToastPosition::TopRight)
.duration(Duration::from_secs(3));
// Render the toast
toast.render(area, frame);Fields§
§id: ToastIdUnique identifier.
content: ToastContentToast content.
config: ToastConfigConfiguration.
state: ToastStateInternal state.
actions: Vec<ToastAction>Interactive action buttons (e.g., “Undo”, “Retry”).
Implementations§
Source§impl Toast
impl Toast
Sourcepub fn with_id(id: ToastId, message: impl Into<String>) -> Self
pub fn with_id(id: ToastId, message: impl Into<String>) -> Self
Create a toast with a specific ID.
Sourcepub fn position(self, position: ToastPosition) -> Self
pub fn position(self, position: ToastPosition) -> Self
Set the toast position.
Sourcepub fn persistent(self) -> Self
pub fn persistent(self) -> Self
Make the toast persistent (no auto-dismiss).
Sourcepub fn style_variant(self, variant: ToastStyle) -> Self
pub fn style_variant(self, variant: ToastStyle) -> Self
Set the style variant.
Sourcepub fn dismissable(self, dismissable: bool) -> Self
pub fn dismissable(self, dismissable: bool) -> Self
Set whether the toast is dismissable.
Sourcepub fn with_icon_style(self, style: Style) -> Self
pub fn with_icon_style(self, style: Style) -> Self
Set the icon style.
Sourcepub fn with_title_style(self, style: Style) -> Self
pub fn with_title_style(self, style: Style) -> Self
Set the title style.
Sourcepub fn entrance_animation(self, animation: ToastEntranceAnimation) -> Self
pub fn entrance_animation(self, animation: ToastEntranceAnimation) -> Self
Set the entrance animation.
Sourcepub fn exit_animation(self, animation: ToastExitAnimation) -> Self
pub fn exit_animation(self, animation: ToastExitAnimation) -> Self
Set the exit animation.
Sourcepub fn entrance_duration(self, duration: Duration) -> Self
pub fn entrance_duration(self, duration: Duration) -> Self
Set the entrance animation duration.
Sourcepub fn exit_duration(self, duration: Duration) -> Self
pub fn exit_duration(self, duration: Duration) -> Self
Set the exit animation duration.
Sourcepub fn entrance_easing(self, easing: ToastEasing) -> Self
pub fn entrance_easing(self, easing: ToastEasing) -> Self
Set the entrance easing function.
Sourcepub fn exit_easing(self, easing: ToastEasing) -> Self
pub fn exit_easing(self, easing: ToastEasing) -> Self
Set the exit easing function.
Sourcepub fn action(self, action: ToastAction) -> Self
pub fn action(self, action: ToastAction) -> Self
Add a single action button to the toast.
Sourcepub fn actions(self, actions: Vec<ToastAction>) -> Self
pub fn actions(self, actions: Vec<ToastAction>) -> Self
Set all action buttons at once.
Sourcepub fn with_action_style(self, style: Style) -> Self
pub fn with_action_style(self, style: Style) -> Self
Set the style for action buttons.
Sourcepub fn with_action_focus_style(self, style: Style) -> Self
pub fn with_action_focus_style(self, style: Style) -> Self
Set the style for the focused action button.
Sourcepub fn no_animation(self) -> Self
pub fn no_animation(self) -> Self
Disable all animations.
Sourcepub fn reduced_motion(self, enabled: bool) -> Self
pub fn reduced_motion(self, enabled: bool) -> Self
Enable reduced motion mode (skips animations).
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the toast has expired based on its duration.
Accounts for time spent paused (when actions are focused).
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Check if the toast should be visible.
A toast is visible if it’s not dismissed, not expired, and not in the Hidden animation phase.
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Check if the toast is currently animating.
Sourcepub fn dismiss_immediately(&mut self)
pub fn dismiss_immediately(&mut self)
Dismiss immediately without animation.
Sourcepub fn tick_animation(&mut self) -> bool
pub fn tick_animation(&mut self) -> bool
Update the animation state. Call this each frame.
Returns true if the animation phase changed.
Sourcepub fn animation_phase(&self) -> ToastAnimationPhase
pub fn animation_phase(&self) -> ToastAnimationPhase
Get the current animation phase.
Sourcepub fn animation_offset(&self) -> (i16, i16)
pub fn animation_offset(&self) -> (i16, i16)
Get the current animation offset for rendering.
Returns (dx, dy) offset to apply to the position.
Sourcepub fn animation_opacity(&self) -> f64
pub fn animation_opacity(&self) -> f64
Get the current opacity for rendering (0.0 to 1.0).
Sourcepub fn remaining_time(&self) -> Option<Duration>
pub fn remaining_time(&self) -> Option<Duration>
Get the remaining time before auto-dismiss.
Accounts for paused time.
Sourcepub fn handle_key(&mut self, key: KeyEvent) -> ToastEvent
pub fn handle_key(&mut self, key: KeyEvent) -> ToastEvent
Handle a key event for toast interaction.
Supported keys:
Esc: Dismiss the toast (if dismissable).Tab: Cycle focus through action buttons (round-robin).Enter: Invoke the focused action. ReturnsToastEvent::Action(id).
Sourcepub fn pause_timer(&mut self)
pub fn pause_timer(&mut self)
Pause the auto-dismiss timer.
Sourcepub fn resume_timer(&mut self)
pub fn resume_timer(&mut self)
Resume the auto-dismiss timer.
Sourcepub fn clear_focus(&mut self)
pub fn clear_focus(&mut self)
Clear action focus and resume the timer.
Sourcepub fn focused_action(&self) -> Option<&ToastAction>
pub fn focused_action(&self) -> Option<&ToastAction>
Get the currently focused action, if any.
Sourcepub fn calculate_dimensions(&self) -> (u16, u16)
pub fn calculate_dimensions(&self) -> (u16, u16)
Calculate the toast dimensions based on content.