refactor(tracker): split Volume to PeakVolume and AverageVolume

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-19 22:16:13 +03:00
parent 1a8a317464
commit 50ccfe03da
5 changed files with 65 additions and 47 deletions

View File

@ -11,8 +11,9 @@ import (
)
type VuMeter struct {
Volume tracker.Volume
Range float32
AverageVolume tracker.Volume
PeakVolume tracker.Volume
Range float32
}
func (v VuMeter) Layout(gtx C) D {
@ -20,7 +21,7 @@ func (v VuMeter) Layout(gtx C) D {
gtx.Constraints.Max.Y = gtx.Dp(unit.Dp(12))
height := gtx.Dp(unit.Dp(6))
for j := 0; j < 2; j++ {
value := float32(v.Volume.Average[j]) + v.Range
value := float32(v.AverageVolume[j]) + v.Range
if value > 0 {
x := int(value/v.Range*float32(gtx.Constraints.Max.X) + 0.5)
if x > gtx.Constraints.Max.X {
@ -28,7 +29,7 @@ func (v VuMeter) Layout(gtx C) D {
}
paint.FillShape(gtx.Ops, mediumEmphasisTextColor, clip.Rect(image.Rect(0, 0, x, height)).Op())
}
valueMax := float32(v.Volume.Peak[j]) + v.Range
valueMax := float32(v.PeakVolume[j]) + v.Range
if valueMax > 0 {
color := white
if valueMax >= v.Range {