pub struct Toast;Expand description
A toast notification component.
Toast displays temporary notification messages in a vertical stack.
Toasts can have different severity levels and auto-dismiss after a
configurable duration.
§Timer Integration
The component uses a Tick message to track time. Your application
should send periodic Tick(elapsed_ms) messages (e.g., every 100ms)
to drive auto-dismiss functionality.
§Visual Format
Toasts render in the bottom-right corner, stacking upward:
┌──────────────────────────────────┐
│ ✓ Operation completed! │
└──────────────────────────────────┘
┌──────────────────────────────────┐
│ ℹ Processing your request... │
└──────────────────────────────────┘§Severity Levels
Info- Blue border, ℹ prefixSuccess- Green border, ✓ prefixWarning- Yellow border, ⚠ prefixError- Red border, ✗ prefix
§Example
use envision::component::{Toast, ToastMessage, ToastOutput, ToastState, Component};
let mut state = ToastState::with_duration(3000);
// Add a success toast
let id = state.success("File saved!");
// Tick to advance time
let output = Toast::update(&mut state, ToastMessage::Tick(3000));
assert_eq!(output, Some(ToastOutput::Expired(vec![id])));
assert!(state.is_empty());Trait Implementations§
Source§impl Component for Toast
impl Component for Toast
Source§type State = ToastState
type State = ToastState
The component’s internal state type. Read more
Source§type Message = ToastMessage
type Message = ToastMessage
Messages this component can receive. Read more
Source§type Output = ToastOutput
type Output = ToastOutput
Messages this component can emit to its parent. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
Update component state based on a message. Read more
Source§fn view(
state: &Self::State,
frame: &mut Frame<'_>,
area: Rect,
theme: &Theme,
_ctx: &ViewContext,
)
fn view( state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme, _ctx: &ViewContext, )
Render the component to the given area. Read more
Source§fn traced_view(
state: &Self::State,
frame: &mut Frame<'_>,
area: Rect,
theme: &Theme,
ctx: &ViewContext,
)
fn traced_view( state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme, ctx: &ViewContext, )
Renders the component with optional tracing instrumentation. Read more
Source§fn handle_event(
state: &Self::State,
event: &Event,
ctx: &ViewContext,
) -> Option<Self::Message>
fn handle_event( state: &Self::State, event: &Event, ctx: &ViewContext, ) -> Option<Self::Message>
Maps an input event to a component message. Read more
Source§fn dispatch_event(
state: &mut Self::State,
event: &Event,
ctx: &ViewContext,
) -> Option<Self::Output>
fn dispatch_event( state: &mut Self::State, event: &Event, ctx: &ViewContext, ) -> Option<Self::Output>
Dispatches an event by mapping it to a message and updating state. Read more
Auto Trait Implementations§
impl Freeze for Toast
impl RefUnwindSafe for Toast
impl Send for Toast
impl Sync for Toast
impl Unpin for Toast
impl UnsafeUnpin for Toast
impl UnwindSafe for Toast
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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