Toast Widget
Overview
The Toast widget displays temporary notification messages that auto-dismiss after a timeout. It supports different types (info, success, warning, error) and positions with smooth animations.
Properties
message: The notification message texttoast_type: Type of toast (.info,.success,.warning,.error_toast)position: Screen position (.top_left,.top_center,.top_right,.bottom_left,.bottom_center,.bottom_right)visible: Whether the toast is currently visibleduration_ms: Display duration in millisecondselapsed_ms: Time elapsed since showingbase: Base widget state
Methods
init(message: []const u8): Creates a new toast with the given messagewithType(toast_type: ToastType): Sets the toast typewithPosition(position: ToastPosition): Sets the display positionwithDuration(duration_ms: u32): Sets the display durationshow(): Shows the toasthide(): Hides the toastupdate(delta_ms: u32): Updates the toast state for auto-dismissrender(ctx: *RenderContext): Renders the toast with icon and progress bar
Events
None - this widget is not interactive.
Examples
Basic Info Toast
zig
const tui = @import("tui");
const Toast = tui.widgets.Toast;
var toast = Toast.init("Operation completed successfully")
.withType(.success)
.withDuration(3000);
toast.show();Error Toast
zig
var toast = Toast.init("Failed to save file")
.withType(.error_toast)
.withPosition(.top_right);
toast.show();Toast Manager
zig
const ToastManager = tui.widgets.ToastManager;
var manager = ToastManager.init(allocator);
defer manager.deinit();
var toast = Toast.init("Message").withType(.info);
try manager.show(toast);
// In main loop:
manager.update(16); // Update with delta time
manager.render(ctx);