This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-07-07 16:53:21 +03:00
parent 0d21afa2c1
commit 95515ee4a8
4 changed files with 57 additions and 13 deletions

View File

@ -85,14 +85,15 @@ type Theme struct {
} }
} }
UnitEditor struct { UnitEditor struct {
Name LabelStyle Name LabelStyle
Chooser LabelStyle Chooser LabelStyle
Hint LabelStyle Hint LabelStyle
WireColor color.NRGBA WireColor color.NRGBA
WireHint LabelStyle WireHint LabelStyle
Width unit.Dp Width unit.Dp
Height unit.Dp Height unit.Dp
UnitList struct { RackComment LabelStyle
UnitList struct {
LabelWidth unit.Dp LabelWidth unit.Dp
Name LabelStyle Name LabelStyle
Disabled LabelStyle Disabled LabelStyle

View File

@ -221,6 +221,7 @@ uniteditor:
{ textsize: 12, color: *disabled, font: { style: 1 }, alignment: 2 } { textsize: 12, color: *disabled, font: { style: 1 }, alignment: 2 }
error: *errorcolor error: *errorcolor
divider: { r: 255, g: 255, b: 255, a: 5 } divider: { r: 255, g: 255, b: 255, a: 5 }
rackcomment: { textsize: 16, color: *mediumemphasis, shadowcolor: *black }
knob: knob:
diameter: 36 diameter: 36
value: { textsize: 12, color: *highemphasis } value: { textsize: 12, color: *highemphasis }

View File

@ -5,6 +5,7 @@ import (
"image" "image"
"io" "io"
"math" "math"
"time"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/io/clipboard" "gioui.org/io/clipboard"
@ -137,6 +138,12 @@ func (pe *UnitEditor) update(gtx C, t *Tracker) {
case key.NameDeleteBackward, key.NameDeleteForward: case key.NameDeleteBackward, key.NameDeleteForward:
t.Model.Params().Table().Clear() t.Model.Params().Table().Clear()
} }
c := t.Model.Params().Cursor()
if c.X >= 0 && c.Y >= 0 && c.Y < len(pe.Parameters) && c.X < len(pe.Parameters[c.Y]) {
ta := &pe.Parameters[c.Y][c.X].knobState.tipArea
ta.Appear(gtx.Now)
ta.Exit.SetTarget(gtx.Now.Add(ta.ExitDuration))
}
} }
} }
for { for {
@ -191,7 +198,7 @@ func (pe *UnitEditor) layoutRack(gtx C) D {
columnTitleHeight := gtx.Dp(0) columnTitleHeight := gtx.Dp(0)
for i := range pe.Parameters { for i := range pe.Parameters {
for len(pe.Parameters[i]) < width { for len(pe.Parameters[i]) < width {
pe.Parameters[i] = append(pe.Parameters[i], &ParameterState{}) pe.Parameters[i] = append(pe.Parameters[i], &ParameterState{knobState: KnobState{tipArea: TipArea{ExitDuration: time.Second * 2}}})
} }
} }
coltitle := func(gtx C, x int) D { coltitle := func(gtx C, x int) D {
@ -242,6 +249,15 @@ func (pe *UnitEditor) layoutRack(gtx C) D {
param := t.Model.Params().Item(point) param := t.Model.Params().Item(point)
paramStyle := t.ParamStyle(param, t.Theme, pe.Parameters[y][x], pe.paramTable.Table.Cursor() == point) paramStyle := t.ParamStyle(param, t.Theme, pe.Parameters[y][x], pe.paramTable.Table.Cursor() == point)
paramStyle.Layout(gtx) paramStyle.Layout(gtx)
comment := t.Units().Item(y).Comment
if comment != "" && x == t.Model.Params().RowWidth(y) {
label := Label(t.Theme, &t.Theme.UnitEditor.RackComment, comment)
return layout.W.Layout(gtx, func(gtx C) D {
gtx.Constraints.Max.X = 1e6
gtx.Constraints.Min.Y = 0
return label.Layout(gtx)
})
}
return D{Size: image.Pt(gtx.Constraints.Max.X, gtx.Constraints.Max.Y)} return D{Size: image.Pt(gtx.Constraints.Max.X, gtx.Constraints.Max.Y)}
} }
table := FilledScrollTable(t.Theme, pe.paramTable) table := FilledScrollTable(t.Theme, pe.paramTable)
@ -368,10 +384,9 @@ func mulVec(a, b f32.Point) f32.Point {
func (pe *UnitEditor) layoutFooter(gtx C) D { func (pe *UnitEditor) layoutFooter(gtx C) D {
t := TrackerFromContext(gtx) t := TrackerFromContext(gtx)
st := t.Units().SelectedType()
text := "Choose unit type" text := "Choose unit type"
if !t.UnitSearching().Value() { if !t.UnitSearching().Value() {
text = pe.caser.String(st) text = pe.caser.String(t.Units().SelectedType())
} }
hintText := Label(t.Theme, &t.Theme.UnitEditor.Hint, text) hintText := Label(t.Theme, &t.Theme.UnitEditor.Hint, text)
deleteUnitBtn := ActionIconBtn(t.DeleteUnit(), t.Theme, pe.DeleteUnitBtn, icons.ActionDelete, "Delete unit (Ctrl+Backspace)") deleteUnitBtn := ActionIconBtn(t.DeleteUnit(), t.Theme, pe.DeleteUnitBtn, icons.ActionDelete, "Delete unit (Ctrl+Backspace)")

View File

@ -175,6 +175,12 @@ func (pt *Params) Width() int {
} }
return pt.derived.patch[pt.d.InstrIndex].paramsWidth return pt.derived.patch[pt.d.InstrIndex].paramsWidth
} }
func (pt *Params) RowWidth(y int) int {
if pt.d.InstrIndex < 0 || pt.d.InstrIndex >= len(pt.derived.patch) || y < 0 || y >= len(pt.derived.patch[pt.d.InstrIndex].params) {
return 0
}
return len(pt.derived.patch[pt.d.InstrIndex].params[y])
}
func (pt *Params) Height() int { return (*Model)(pt).Units().Count() } func (pt *Params) Height() int { return (*Model)(pt).Units().Count() }
func (pt *Params) MoveCursor(dx, dy int) (ok bool) { func (pt *Params) MoveCursor(dx, dy int) (ok bool) {
p := pt.Cursor() p := pt.Cursor()
@ -260,8 +266,29 @@ func (pt *Params) unmarshalAtCursor(data []byte) (ret bool) {
} }
return ret return ret
} }
func (pt *Params) unmarshalRange(rect Rect, data []byte) (ok bool) { func (pt *Params) unmarshalRange(rect Rect, data []byte) (ret bool) {
panic("NOT IMPLEMENTED") table, ok := pt.unmarshal(data)
if !ok {
return false
}
if len(table.Params) == 0 || len(table.Params[0]) == 0 {
return false
}
width := rect.BottomRight.X - rect.TopLeft.X + 1
height := rect.BottomRight.Y - rect.TopLeft.Y + 1
if len(table.Params) < width {
return false
}
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
if len(table.Params[0]) < height {
return false
}
p := pt.Item(Point{x + rect.TopLeft.X, y + rect.TopLeft.Y})
ret = p.SetValue(table.Params[x][y]) || ret
}
}
return ret
} }
func (pt *Params) change(kind string, severity ChangeSeverity) func() { func (pt *Params) change(kind string, severity ChangeSeverity) func() {
return (*Model)(pt).change(kind, PatchChange, severity) return (*Model)(pt).change(kind, PatchChange, severity)