mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-17 20:44:29 -04:00
refactor(gioui): update gioui to v0.5.0
This commit is contained in:
parent
267973e061
commit
1c020fffa3
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
@ -19,9 +20,9 @@ import (
|
||||
"github.com/vsariola/sointu/tracker"
|
||||
)
|
||||
|
||||
const patternCellHeight = 16
|
||||
const patternCellWidth = 16
|
||||
const patternRowMarkerWidth = 30
|
||||
const patternCellHeight = unit.Dp(16)
|
||||
const patternCellWidth = unit.Dp(16)
|
||||
const patternRowMarkerWidth = unit.Dp(30)
|
||||
const orderTitleHeight = unit.Dp(52)
|
||||
|
||||
type OrderEditor struct {
|
||||
@ -57,18 +58,11 @@ func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
||||
t.TrackEditor.scrollTable.RowTitleList.CenterOn(cursor.Y)
|
||||
}
|
||||
|
||||
for _, e := range gtx.Events(&oe.tag) {
|
||||
switch e := e.(type) {
|
||||
case key.Event:
|
||||
if e.State != key.Press {
|
||||
continue
|
||||
}
|
||||
oe.command(gtx, t, e)
|
||||
}
|
||||
}
|
||||
oe.handleEvents(gtx, t)
|
||||
|
||||
defer op.Offset(image.Point{}).Push(gtx.Ops).Pop()
|
||||
defer clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Push(gtx.Ops).Pop()
|
||||
key.InputOp{Tag: &oe.tag, Keys: "Ctrl-⌫|Ctrl-⌦|⏎|Ctrl-⏎|0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"}.Add(gtx.Ops)
|
||||
event.Op(gtx.Ops, &oe.tag)
|
||||
|
||||
colTitle := func(gtx C, i int) D {
|
||||
h := gtx.Dp(orderTitleHeight)
|
||||
@ -77,13 +71,13 @@ func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
||||
gtx.Constraints = layout.Exact(image.Pt(1e6, 1e6))
|
||||
title := t.Model.Order().Title(i)
|
||||
LabelStyle{Alignment: layout.NW, Text: title, FontSize: unit.Sp(12), Color: mediumEmphasisTextColor, Shaper: t.Theme.Shaper}.Layout(gtx)
|
||||
return D{Size: image.Pt(patternCellWidth, h)}
|
||||
return D{Size: image.Pt(gtx.Dp(patternCellWidth), h)}
|
||||
}
|
||||
|
||||
rowTitle := func(gtx C, j int) D {
|
||||
w := gtx.Dp(unit.Dp(30))
|
||||
if playPos := t.PlayPosition(); t.SongPanel.PlayingBtn.Bool.Value() && j == playPos.OrderRow {
|
||||
paint.FillShape(gtx.Ops, patternPlayColor, clip.Rect{Max: image.Pt(gtx.Constraints.Max.X, patternCellHeight)}.Op())
|
||||
paint.FillShape(gtx.Ops, patternPlayColor, clip.Rect{Max: image.Pt(gtx.Constraints.Max.X, gtx.Dp(patternCellHeight))}.Op())
|
||||
}
|
||||
color := rowMarkerPatternTextColor
|
||||
if l := t.Loop(); j >= l.Start && j < l.Start+l.Length {
|
||||
@ -92,7 +86,7 @@ func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
||||
paint.ColorOp{Color: color}.Add(gtx.Ops)
|
||||
defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop()
|
||||
widget.Label{}.Layout(gtx, t.Theme.Shaper, trackerFont, trackerFontSize, strings.ToUpper(fmt.Sprintf("%02x", j)), op.CallOp{})
|
||||
return D{Size: image.Pt(w, patternCellHeight)}
|
||||
return D{Size: image.Pt(w, gtx.Dp(patternCellHeight))}
|
||||
}
|
||||
|
||||
selection := oe.scrollTable.Table.Range()
|
||||
@ -114,7 +108,7 @@ func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
||||
paint.ColorOp{Color: patternTextColor}.Add(gtx.Ops)
|
||||
defer op.Offset(image.Pt(0, -2)).Push(gtx.Ops).Pop()
|
||||
widget.Label{Alignment: text.Middle}.Layout(gtx, t.Theme.Shaper, trackerFont, trackerFontSize, val, op.CallOp{})
|
||||
return D{Size: image.Pt(patternCellWidth, patternCellHeight)}
|
||||
return D{Size: image.Pt(gtx.Dp(patternCellWidth), gtx.Dp(patternCellHeight))}
|
||||
}
|
||||
|
||||
table := FilledScrollTable(t.Theme, oe.scrollTable, cell, colTitle, rowTitle, nil, nil)
|
||||
@ -123,6 +117,61 @@ func (oe *OrderEditor) Layout(gtx C, t *Tracker) D {
|
||||
return table.Layout(gtx)
|
||||
}
|
||||
|
||||
func (oe *OrderEditor) handleEvents(gtx C, t *Tracker) {
|
||||
for {
|
||||
e, ok := gtx.Event(
|
||||
key.Filter{Focus: oe.scrollTable, Name: key.NameDeleteBackward, Optional: key.ModShortcut},
|
||||
key.Filter{Focus: oe.scrollTable, Name: key.NameDeleteForward, Optional: key.ModShortcut},
|
||||
key.Filter{Focus: oe.scrollTable, Name: key.NameReturn, Optional: key.ModShortcut},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "0"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "1"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "2"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "3"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "4"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "5"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "6"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "7"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "8"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "9"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "A"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "B"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "C"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "D"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "E"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "F"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "G"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "H"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "I"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "J"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "K"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "L"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "M"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "N"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "O"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "P"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "Q"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "R"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "S"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "T"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "U"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "V"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "W"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "X"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "Y"},
|
||||
key.Filter{Focus: oe.scrollTable, Name: "Z"},
|
||||
)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if e, ok := e.(key.Event); ok {
|
||||
if e.State != key.Press {
|
||||
continue
|
||||
}
|
||||
oe.command(gtx, t, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (oe *OrderEditor) command(gtx C, t *Tracker, e key.Event) {
|
||||
switch e.Name {
|
||||
case key.NameDeleteBackward:
|
||||
@ -140,7 +189,7 @@ func (oe *OrderEditor) command(gtx C, t *Tracker, e key.Event) {
|
||||
}
|
||||
t.Model.AddOrderRow(!e.Modifiers.Contain(key.ModShortcut)).Do()
|
||||
}
|
||||
if iv, err := strconv.Atoi(e.Name); err == nil {
|
||||
if iv, err := strconv.Atoi(string(e.Name)); err == nil {
|
||||
t.Model.Order().SetValue(oe.scrollTable.Table.Cursor(), iv)
|
||||
oe.scrollTable.EnsureCursorVisible()
|
||||
}
|
||||
|
Reference in New Issue
Block a user