mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
feat(tracker): add row number markers to the left
This commit is contained in:
parent
82d26b79a4
commit
92ab035101
@ -42,7 +42,7 @@ func (t *Tracker) Layout(gtx layout.Context) {
|
||||
}
|
||||
|
||||
func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
||||
flexTracks := make([]layout.FlexChild, len(t.song.Tracks))
|
||||
flexTracks := make([]layout.FlexChild, len(t.song.Tracks)+1)
|
||||
t.playRowPatMutex.RLock()
|
||||
defer t.playRowPatMutex.RUnlock()
|
||||
|
||||
@ -51,8 +51,17 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
|
||||
playPat = -1
|
||||
}
|
||||
|
||||
flexTracks[0] = layout.Rigid(Lowered(t.layoutRowMarkers(
|
||||
len(t.song.Tracks[0].Patterns[0]),
|
||||
len(t.song.Tracks[0].Sequence),
|
||||
t.CursorRow,
|
||||
t.DisplayPattern,
|
||||
t.CursorColumn,
|
||||
t.PlayRow,
|
||||
playPat,
|
||||
)))
|
||||
for i, trk := range t.song.Tracks {
|
||||
flexTracks[i] = layout.Rigid(Lowered(t.layoutTrack(
|
||||
flexTracks[i+1] = layout.Rigid(Lowered(t.layoutTrack(
|
||||
trk.Patterns,
|
||||
trk.Sequence,
|
||||
t.ActiveTrack == i,
|
||||
|
53
tracker/rowmarkers.go
Normal file
53
tracker/rowmarkers.go
Normal file
@ -0,0 +1,53 @@
|
||||
package tracker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"strings"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/widget"
|
||||
)
|
||||
|
||||
const rowMarkerWidth = 50
|
||||
|
||||
func (t *Tracker) layoutRowMarkers(patternRows, sequenceLength, cursorRow, cursorPattern, cursorCol, playRow, playPattern int) layout.Widget {
|
||||
return func(gtx layout.Context) layout.Dimensions {
|
||||
gtx.Constraints.Min.X = rowMarkerWidth
|
||||
gtx.Constraints.Max.X = rowMarkerWidth
|
||||
paint.FillShape(gtx.Ops, inactiveTrackColor, clip.Rect{
|
||||
Max: gtx.Constraints.Max,
|
||||
}.Op())
|
||||
defer op.Push(gtx.Ops).Pop()
|
||||
clip.Rect{Max: gtx.Constraints.Max}.Add(gtx.Ops)
|
||||
op.Offset(f32.Pt(0, float32(gtx.Constraints.Max.Y/2)-trackRowHeight)).Add(gtx.Ops)
|
||||
cursorSongRow := cursorPattern*patternRows + cursorRow
|
||||
playSongRow := playPattern*patternRows + playRow
|
||||
op.Offset(f32.Pt(0, (-1*trackRowHeight)*float32(cursorSongRow))).Add(gtx.Ops)
|
||||
for i := 0; i < sequenceLength; i++ {
|
||||
for j := 0; j < patternRows; j++ {
|
||||
songRow := i*patternRows + j
|
||||
if songRow == playSongRow {
|
||||
paint.FillShape(gtx.Ops, trackerPlayColor, clip.Rect{Max: image.Pt(trackWidth, trackRowHeight)}.Op())
|
||||
}
|
||||
if j == 0 {
|
||||
paint.ColorOp{Color: trackerPatMarker}.Add(gtx.Ops)
|
||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", i)))
|
||||
}
|
||||
if songRow == cursorSongRow {
|
||||
paint.ColorOp{Color: trackerActiveTextColor}.Add(gtx.Ops)
|
||||
} else {
|
||||
paint.ColorOp{Color: trackerInactiveTextColor}.Add(gtx.Ops)
|
||||
}
|
||||
op.Offset(f32.Pt(rowMarkerWidth/2, 0)).Add(gtx.Ops)
|
||||
widget.Label{}.Layout(gtx, textShaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", j)))
|
||||
op.Offset(f32.Pt(-rowMarkerWidth/2, trackRowHeight)).Add(gtx.Ops)
|
||||
}
|
||||
}
|
||||
return layout.Dimensions{Size: gtx.Constraints.Max}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user