类型 ToastQueue

API 文档由 Go 源码生成,内容为英文。

type ToastQueue struct {
	// Timeout is the lifetime of a new non-loading toast; zero means
	// ToastQueueTimeout.
	Timeout time.Duration
	// Limit is the maximum number of queued toasts; zero means ToastQueueLimit.
	Limit int

}

ToastQueue is caller-owned toast lifetime policy: Base UI's five-second timeout, pause on hover/focus/window blur, loading toasts that do not expire, and a visible limit. It never starts a timer; the caller asks Expire when NextDeadline comes due and pauses or resumes as the pointer and focus move. Painting remains PaintSonner's job.

方法

Add#

func (queue *ToastQueue) Add(id ui.ID, now time.Time, loading bool) (evicted ui.ID, ok bool)

Add enqueues a toast. When the limit is full it drops the oldest and returns its ID so the caller can paint its exit. Add reports false for a zero ID or one that is already queued.

Entries#

func (queue *ToastQueue) Entries(now time.Time, dst []ToastQueueEntry) []ToastQueueEntry

Entries copies the live toasts into dst in queue order (oldest first) and returns the result, for building ToastSnapshots without allocating when dst has room.

Expire#

func (queue *ToastQueue) Expire(now time.Time) (ui.ID, bool)

Expire removes and returns the first toast whose time is up. Loading and paused toasts never expire. Call it after NextDeadline comes due; it reports false when nothing is due.

Len#

func (queue *ToastQueue) Len() int

Len is how many toasts are queued.

NextDeadline#

func (queue *ToastQueue) NextDeadline() (time.Time, bool)

NextDeadline is the earliest time an unpaused, non-loading toast expires, for scheduling one frame. It reports false when no toast has a deadline.

Pause#

func (queue *ToastQueue) Pause(id ui.ID, now time.Time) bool

Pause stops a toast's clock, remembering how much time was left, as hovering or focusing its viewport does.

PauseAll#

func (queue *ToastQueue) PauseAll(now time.Time)

PauseAll stops every toast, as losing window focus does.

Remove#

func (queue *ToastQueue) Remove(id ui.ID) bool

Remove drops a toast, as its close button or a swipe does.

Resume#

func (queue *ToastQueue) Resume(id ui.ID, now time.Time) bool

Resume restarts a paused toast's remaining time.

ResumeAll#

func (queue *ToastQueue) ResumeAll(now time.Time)

ResumeAll restarts every paused toast.

SetLoading#

func (queue *ToastQueue) SetLoading(id ui.ID, loading bool, now time.Time) bool

SetLoading changes whether a toast expires. A toast that stops loading gets a fresh timeout; one that starts loading never expires.