feat(sointu): add functions to figure out the stack use and need of a unit

This commit is contained in:
vsariola
2021-02-10 22:39:08 +02:00
parent 35d2ff6308
commit 8cfd915311
4 changed files with 63 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package tracker
import (
"image"
"strconv"
"gioui.org/io/pointer"
"gioui.org/layout"
@ -154,15 +155,41 @@ func (t *Tracker) layoutInstrumentEditor(gtx C) D {
addUnitBtnStyle.Inset = layout.UniformInset(unit.Dp(4))
margin := layout.UniformInset(unit.Dp(2))
for len(t.StackUse) < len(t.song.Patch.Instruments[t.CurrentInstrument].Units) {
t.StackUse = append(t.StackUse, 0)
}
stackHeight := 0
for i, u := range t.song.Patch.Instruments[t.CurrentInstrument].Units {
stackHeight += u.StackChange()
t.StackUse[i] = stackHeight
}
element := func(gtx C, i int) D {
gtx.Constraints = layout.Exact(image.Pt(gtx.Px(unit.Dp(120)), gtx.Px(unit.Dp(20))))
u := t.song.Patch.Instruments[t.CurrentInstrument].Units[i]
labelStyle := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
if labelStyle.Text == "" {
labelStyle.Text = "---"
labelStyle.Alignment = layout.Center
unitNameLabel := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
if unitNameLabel.Text == "" {
unitNameLabel.Text = "---"
unitNameLabel.Alignment = layout.Center
}
return labelStyle.Layout(gtx)
var stackText string
if i < len(t.StackUse) {
stackText = strconv.FormatInt(int64(t.StackUse[i]), 10)
var prevStackUse int
if i > 0 {
prevStackUse = t.StackUse[i-1]
}
if u.StackNeed() > prevStackUse || (i == len(t.StackUse)-1 && t.StackUse[i] > 0) {
unitNameLabel.Color = errorColor
}
}
stackLabel := LabelStyle{Text: stackText, ShadeColor: black, Color: mediumEmphasisTextColor, Font: labelDefaultFont, FontSize: unit.Sp(12)}
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Flexed(1, unitNameLabel.Layout),
layout.Rigid(stackLabel.Layout),
)
}
unitList := FilledDragList(t.Theme, t.UnitDragList, len(t.song.Patch.Instruments[t.CurrentInstrument].Units), element, t.SwapUnits)

View File

@ -109,3 +109,5 @@ var activeLightSurfaceColor = color.NRGBA{R: 45, G: 45, B: 45, A: 255}
var cursorColor = color.NRGBA{R: 100, G: 140, B: 255, A: 48}
var selectionColor = color.NRGBA{R: 100, G: 140, B: 255, A: 8}
var inactiveSelectionColor = color.NRGBA{R: 140, G: 140, B: 140, A: 16}
var errorColor = color.NRGBA{R: 207, G: 102, B: 121, A: 255}

View File

@ -76,6 +76,7 @@ type Tracker struct {
TopHorizontalSplit *Split
BottomHorizontalSplit *Split
VerticalSplit *Split
StackUse []int
sequencer *Sequencer
ticked chan struct{}