refactor(tracker/gioui): make iconCache part of Theme

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-06-20 19:05:40 +03:00
parent b291959a97
commit 4fa0e04788
6 changed files with 22 additions and 31 deletions

View File

@ -107,6 +107,9 @@ type Theme struct {
Shadow color.NRGBA
}
ScrollBar ScrollBarStyle
// iconCache is used to cache the icons created from iconvg data
iconCache map[*byte]*widget.Icon
}
type CursorStyle struct {
@ -127,9 +130,19 @@ func NewTheme() (*Theme, error) {
ret.Material.Icon.CheckBoxUnchecked = must(widget.NewIcon(icons.ToggleCheckBoxOutlineBlank))
ret.Material.Icon.RadioChecked = must(widget.NewIcon(icons.ToggleRadioButtonChecked))
ret.Material.Icon.RadioUnchecked = must(widget.NewIcon(icons.ToggleRadioButtonUnchecked))
ret.iconCache = make(map[*byte]*widget.Icon)
return &ret, warn
}
func (th *Theme) Icon(data []byte) *widget.Icon {
if icon, ok := th.iconCache[&data[0]]; ok {
return icon
}
icon := must(widget.NewIcon(data))
th.iconCache[&data[0]] = icon
return icon
}
func must[T any](ic T, err error) T {
if err != nil {
panic(err)