feat(tracker): move new instrument button to the top right

This commit is contained in:
vsariola 2021-01-14 00:44:33 +02:00
parent ed67408d6e
commit a29f34734b
2 changed files with 28 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import (
"sort"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
"gioui.org/unit"
@ -24,15 +25,34 @@ func (t *Tracker) updateInstrumentScroll() {
}
func (t *Tracker) layoutInstruments() layout.Widget {
btnStyle := material.IconButton(t.Theme, t.NewInstrumentBtn, addIcon)
btnStyle.Background = transparent
btnStyle.Inset = layout.UniformInset(unit.Dp(6))
if t.song.Patch.TotalVoices() < 32 {
btnStyle.Color = primaryColor
} else {
btnStyle.Color = disabledTextColor
}
return func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(t.layoutInstrumentNames()),
layout.Rigid(func(gtx C) D {
return layout.Flex{}.Layout(
gtx,
layout.Flexed(1, t.layoutInstrumentNames()),
layout.Rigid(func(gtx C) D {
return layout.E.Layout(gtx, btnStyle.Layout)
}),
)
}),
layout.Flexed(1, t.layoutInstrumentEditor()))
}
}
func (t *Tracker) layoutInstrumentNames() layout.Widget {
return func(gtx C) D {
gtx.Constraints.Max.Y = gtx.Px(unit.Dp(36))
gtx.Constraints.Min.Y = gtx.Px(unit.Dp(36))
count := len(t.song.Patch.Instruments)
if len(t.InstrumentBtns) < count {
tail := make([]*widget.Clickable, count-len(t.InstrumentBtns))
@ -41,7 +61,10 @@ func (t *Tracker) layoutInstrumentNames() layout.Widget {
}
t.InstrumentBtns = append(t.InstrumentBtns, tail...)
}
return t.InstrumentList.Layout(gtx, count, func(gtx C, index int) D {
defer op.Push(gtx.Ops).Pop()
t.InstrumentList.Layout(gtx, count, func(gtx C, index int) D {
for t.InstrumentBtns[index].Clicked() {
t.CurrentInstrument = index
}
@ -54,6 +77,8 @@ func (t *Tracker) layoutInstrumentNames() layout.Widget {
}
return btnStyle.Layout(gtx)
})
return layout.Dimensions{Size: gtx.Constraints.Max}
}
}
func (t *Tracker) layoutInstrumentEditor() layout.Widget {

View File

@ -206,8 +206,6 @@ func (t *Tracker) layoutControls(gtx layout.Context) layout.Dimensions {
gtx.Constraints.Min.Y = 250
gtx.Constraints.Max.Y = 250
in := layout.UniformInset(unit.Dp(1))
go func() {
for t.BPMUpBtn.Clicked() {
t.ChangeBPM(1)
@ -230,15 +228,7 @@ func (t *Tracker) layoutControls(gtx layout.Context) layout.Dimensions {
return t.TopSplit.Layout(gtx,
t.layoutSongPanel,
func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Flexed(1, t.layoutInstruments()),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
iconBtn := enableButton(material.IconButton(t.Theme, t.NewInstrumentBtn, addIcon), t.song.Patch.TotalVoices() < 32)
return in.Layout(gtx, iconBtn.Layout)
}),
)
},
t.layoutInstruments(),
)
}