zntg/ui/desiredsizecache.go

22 lines
408 B
Go
Raw Permalink Normal View History

package ui
import (
"github.com/minio/highwayhash"
"opslag.de/schobers/geom"
)
type desiredSizeCache struct {
sum [32]byte
size geom.PointF32
}
func (c *desiredSizeCache) Update(ctx Context, data string, calcFn func(Context) geom.PointF32) geom.PointF32 {
var key = [32]byte{}
sum := highwayhash.Sum([]byte(data), key[:])
if c.sum != sum {
c.size = calcFn(ctx)
c.sum = sum
}
return c.size
}