mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-12 11:13:03 -05:00
refactor(tracker): change so that all icon initialization is a lazy & cache in iconcache
This commit is contained in:
22
tracker/iconcache.go
Normal file
22
tracker/iconcache.go
Normal file
@ -0,0 +1,22 @@
|
||||
package tracker
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
var iconCache = map[*byte]*widget.Icon{}
|
||||
|
||||
// widgetForIcon returns a widget for IconVG data, but caching the results
|
||||
func widgetForIcon(icon []byte) *widget.Icon {
|
||||
if widget, ok := iconCache[&icon[0]]; ok {
|
||||
return widget
|
||||
}
|
||||
widget, err := widget.NewIcon(icon)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
iconCache[&icon[0]] = widget
|
||||
return widget
|
||||
}
|
||||
Reference in New Issue
Block a user