refactor(tracker): use go v1.23 style iterators throughout

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2024-10-15 00:01:02 +03:00
parent 2b7ce39069
commit 97e59c5650
7 changed files with 108 additions and 87 deletions

View File

@ -338,13 +338,13 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
addUnitBtnStyle.IconButtonStyle.Background = t.Theme.Fg
addUnitBtnStyle.IconButtonStyle.Inset = layout.UniformInset(unit.Dp(4))
index := 0
var units [256]tracker.UnitListItem
(*tracker.Units)(t.Model).Iterate(func(item tracker.UnitListItem) (ok bool) {
units[index] = item
index++
return index <= 256
})
for i, item := range (*tracker.Units)(t.Model).Iterate() {
if i >= 256 {
break
}
units[i] = item
}
count := intMin(ie.unitDragList.TrackerList.Count(), 256)
element := func(gtx C, i int) D {

View File

@ -36,7 +36,7 @@ func (a *PopupAlert) Layout(gtx C) D {
a.prevUpdate = now
var totalY float64 = float64(gtx.Dp(38))
a.alerts.Iterate(func(alert tracker.Alert) {
for _, alert := range a.alerts.Iterate() {
var color, textColor, shadeColor color.NRGBA
switch alert.Priority {
case tracker.Warning:
@ -76,6 +76,6 @@ func (a *PopupAlert) Layout(gtx C) D {
return dims
})
})
})
}
return D{}
}

View File

@ -102,11 +102,10 @@ func (pe *UnitEditor) layoutSliders(gtx C, t *Tracker) D {
}
index := 0
t.Model.Params().Iterate(func(param tracker.Parameter) {
for param := range t.Model.Params().Iterate() {
pe.Parameters[index].Parameter = param
index++
})
}
element := func(gtx C, index int) D {
if index < 0 || index >= numItems {
return D{}
@ -177,12 +176,12 @@ func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D {
func (pe *UnitEditor) layoutUnitTypeChooser(gtx C, t *Tracker) D {
var names [256]string
index := 0
t.Model.SearchResults().Iterate(func(item string) (ok bool) {
names[index] = item
index++
return index <= 256
})
for i, item := range t.Model.SearchResults().Iterate() {
if i >= 256 {
break
}
names[i] = item
}
element := func(gtx C, i int) D {
w := LabelStyle{Text: names[i], ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12), Shaper: t.Theme.Shaper}
if i == pe.searchList.TrackerList.Selected() {