mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
feat(tracker, gioui): add the ability to reorder / drag tracks in order list
This commit is contained in:
parent
442715334e
commit
5aa16b4a97
@ -25,6 +25,7 @@ const patternRowMarkerWidth = 30
|
|||||||
|
|
||||||
type OrderEditor struct {
|
type OrderEditor struct {
|
||||||
list *layout.List
|
list *layout.List
|
||||||
|
titleList *DragList
|
||||||
scrollBar *ScrollBar
|
scrollBar *ScrollBar
|
||||||
tag bool
|
tag bool
|
||||||
focused bool
|
focused bool
|
||||||
@ -34,6 +35,7 @@ type OrderEditor struct {
|
|||||||
func NewOrderEditor() *OrderEditor {
|
func NewOrderEditor() *OrderEditor {
|
||||||
return &OrderEditor{
|
return &OrderEditor{
|
||||||
list: &layout.List{Axis: layout.Vertical},
|
list: &layout.List{Axis: layout.Vertical},
|
||||||
|
titleList: &DragList{List: &layout.List{Axis: layout.Horizontal}},
|
||||||
scrollBar: &ScrollBar{Axis: layout.Vertical},
|
scrollBar: &ScrollBar{Axis: layout.Vertical},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,22 +171,25 @@ func (oe *OrderEditor) doLayout(gtx C, t *Tracker) D {
|
|||||||
// draw the single letter titles for tracks
|
// draw the single letter titles for tracks
|
||||||
{
|
{
|
||||||
gtx := gtx
|
gtx := gtx
|
||||||
curVoice := 0
|
|
||||||
stack := op.Save(gtx.Ops)
|
stack := op.Save(gtx.Ops)
|
||||||
op.Offset(f32.Pt(patternRowMarkerWidth, 0)).Add(gtx.Ops)
|
op.Offset(f32.Pt(patternRowMarkerWidth, 0)).Add(gtx.Ops)
|
||||||
gtx.Constraints = layout.Exact(image.Pt(patternCellWidth, patternCellHeight))
|
gtx.Constraints = layout.Exact(image.Pt(gtx.Constraints.Max.X-patternRowMarkerWidth, patternCellHeight))
|
||||||
for _, track := range t.Song().Score.Tracks {
|
elem := func(gtx C, i int) D {
|
||||||
instr, err := t.Song().Patch.InstrumentForVoice(curVoice)
|
gtx.Constraints = layout.Exact(image.Pt(patternCellWidth, patternCellHeight))
|
||||||
|
instr, err := t.Song().Patch.InstrumentForVoice(t.Song().Score.FirstVoiceForTrack(i))
|
||||||
var title string
|
var title string
|
||||||
if err == nil && len(t.Song().Patch[instr].Name) > 0 {
|
if err == nil && len(t.Song().Patch[instr].Name) > 0 {
|
||||||
title = string(t.Song().Patch[instr].Name[0])
|
title = string(t.Song().Patch[instr].Name[0])
|
||||||
} else {
|
} else {
|
||||||
title = "I"
|
title = "?"
|
||||||
}
|
}
|
||||||
LabelStyle{Alignment: layout.N, Text: title, FontSize: unit.Dp(12), Color: mediumEmphasisTextColor}.Layout(gtx)
|
LabelStyle{Alignment: layout.N, Text: title, FontSize: unit.Dp(12), Color: mediumEmphasisTextColor}.Layout(gtx)
|
||||||
op.Offset(f32.Pt(patternCellWidth, 0)).Add(gtx.Ops)
|
return D{Size: gtx.Constraints.Min}
|
||||||
curVoice += track.NumVoices
|
|
||||||
}
|
}
|
||||||
|
style := FilledDragList(t.Theme, oe.titleList, len(t.Song().Score.Tracks), elem, t.SwapTracks)
|
||||||
|
style.HoverColor = transparent
|
||||||
|
style.SelectedColor = transparent
|
||||||
|
style.Layout(gtx)
|
||||||
stack.Load()
|
stack.Load()
|
||||||
}
|
}
|
||||||
op.Offset(f32.Pt(0, patternCellHeight)).Add(gtx.Ops)
|
op.Offset(f32.Pt(0, patternCellHeight)).Add(gtx.Ops)
|
||||||
|
@ -245,6 +245,17 @@ func (m *Model) CanDeleteTrack() bool {
|
|||||||
return len(m.song.Score.Tracks) > 1
|
return len(m.song.Score.Tracks) > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) SwapTracks(i, j int) {
|
||||||
|
if i < 0 || j < 0 || i >= len(m.song.Score.Tracks) || j >= len(m.song.Score.Tracks) || i == j {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.saveUndo("SwapTracks", 10)
|
||||||
|
tracks := m.song.Score.Tracks
|
||||||
|
tracks[i], tracks[j] = tracks[j], tracks[i]
|
||||||
|
m.clampPositions()
|
||||||
|
m.notifyScoreChange()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Model) SetTrackVoices(value int) {
|
func (m *Model) SetTrackVoices(value int) {
|
||||||
if value < 1 {
|
if value < 1 {
|
||||||
value = 1
|
value = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user