zntg/ui/desiredsizecache.go
Sander Schobers 36d620108c Optimized rendering a lot of labels.
- Added caching of the desired size of a label.
2019-07-04 22:15:32 +02:00

22 lines
408 B
Go

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
}