package main import ( "time" raylib "github.com/gen2brain/raylib-go/raylib" ) type toast struct { Text string Age time.Time MaxAge time.Duration } var ( toasts = []toast{} toastDimHeight = float32(0) ) func AddToast(text string) { t := toast{Text: text, Age: time.Now(), MaxAge: 1 * time.Second} toasts = append(toasts, t) } func UpdateToasts() { if len(toasts) != 0 { toastDimHeight = raylib.Lerp(toastDimHeight, float32(20*len(toasts))+10, 0.1) } else { toastDimHeight = raylib.Lerp(toastDimHeight, 0, 0.1) } for i, t := range toasts { if time.Since(t.Age) > t.MaxAge { toasts = append(toasts[:i], toasts[i+1:]...) i -= 1 } } } func DrawToasts() { raylib.BeginScissorMode(0, 0, applicationWindowWidth, int32(toastDimHeight)) { raylib.DrawRectangle(0, 0, applicationWindowWidth, applicationWindowHeight, raylib.Fade(raylib.Black, 0.5)) for i, t := range toasts { raylib.DrawText(t.Text, 10, int32(20*i)+10, 10, raylib.White) } } raylib.EndScissorMode() }