mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-06-17 07:23:12 +00:00
Fix drawing when UI overlapping, add toast messages
This commit is contained in:
parent
832fcdc7c4
commit
a2c0d9d825
4 changed files with 184 additions and 41 deletions
49
application/toast.go
Normal file
49
application/toast.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
raylib "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
toasts = []Toast{}
|
||||
toastHeight = float32(0)
|
||||
toastMaxAge = 5 * time.Second
|
||||
)
|
||||
|
||||
type Toast struct {
|
||||
Text string
|
||||
Age time.Time
|
||||
}
|
||||
|
||||
func AddToast(text string) {
|
||||
toast := Toast{Text: text, Age: time.Now()}
|
||||
toasts = append(toasts, toast)
|
||||
}
|
||||
|
||||
func UpdateToasts() {
|
||||
if len(toasts) != 0 {
|
||||
toastHeight = raylib.Lerp(toastHeight, float32(20*len(toasts))+10, 0.1)
|
||||
} else {
|
||||
toastHeight = raylib.Lerp(toastHeight, 0, 0.1)
|
||||
}
|
||||
|
||||
for i := 0; i < len(toasts); i++ {
|
||||
if time.Since(toasts[i].Age) > toastMaxAge {
|
||||
toasts = append(toasts[:i], toasts[i+1:]...)
|
||||
i--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func DrawToasts() {
|
||||
raylib.BeginScissorMode(0, 0, WindowWidth, int32(toastHeight))
|
||||
raylib.DrawRectangle(0, 0, WindowWidth, WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||
for i := 0; i < len(toasts); i++ {
|
||||
text := fmt.Sprintf("%s (%s)", toasts[i].Text, time.Since(toasts[i].Age).Round(time.Second))
|
||||
raylib.DrawText(text, 10, int32(20*i)+10, 10, raylib.White)
|
||||
}
|
||||
raylib.EndScissorMode()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue