From 95515ee4a8866a9294e169e6213b5e58ed78009b Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:53:21 +0300 Subject: [PATCH] drafting --- tracker/gioui/theme.go | 17 +++++++++-------- tracker/gioui/theme.yml | 1 + tracker/gioui/unit_editor.go | 21 ++++++++++++++++++--- tracker/params.go | 31 +++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/tracker/gioui/theme.go b/tracker/gioui/theme.go index 3d97691..cdaabda 100644 --- a/tracker/gioui/theme.go +++ b/tracker/gioui/theme.go @@ -85,14 +85,15 @@ type Theme struct { } } UnitEditor struct { - Name LabelStyle - Chooser LabelStyle - Hint LabelStyle - WireColor color.NRGBA - WireHint LabelStyle - Width unit.Dp - Height unit.Dp - UnitList struct { + Name LabelStyle + Chooser LabelStyle + Hint LabelStyle + WireColor color.NRGBA + WireHint LabelStyle + Width unit.Dp + Height unit.Dp + RackComment LabelStyle + UnitList struct { LabelWidth unit.Dp Name LabelStyle Disabled LabelStyle diff --git a/tracker/gioui/theme.yml b/tracker/gioui/theme.yml index 034dec3..f9c4bf3 100644 --- a/tracker/gioui/theme.yml +++ b/tracker/gioui/theme.yml @@ -221,6 +221,7 @@ uniteditor: { textsize: 12, color: *disabled, font: { style: 1 }, alignment: 2 } error: *errorcolor divider: { r: 255, g: 255, b: 255, a: 5 } + rackcomment: { textsize: 16, color: *mediumemphasis, shadowcolor: *black } knob: diameter: 36 value: { textsize: 12, color: *highemphasis } diff --git a/tracker/gioui/unit_editor.go b/tracker/gioui/unit_editor.go index 847e76e..7609318 100644 --- a/tracker/gioui/unit_editor.go +++ b/tracker/gioui/unit_editor.go @@ -5,6 +5,7 @@ import ( "image" "io" "math" + "time" "gioui.org/f32" "gioui.org/io/clipboard" @@ -137,6 +138,12 @@ func (pe *UnitEditor) update(gtx C, t *Tracker) { case key.NameDeleteBackward, key.NameDeleteForward: 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 { @@ -191,7 +198,7 @@ func (pe *UnitEditor) layoutRack(gtx C) D { columnTitleHeight := gtx.Dp(0) for i := range pe.Parameters { 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 { @@ -242,6 +249,15 @@ func (pe *UnitEditor) layoutRack(gtx C) D { param := t.Model.Params().Item(point) paramStyle := t.ParamStyle(param, t.Theme, pe.Parameters[y][x], pe.paramTable.Table.Cursor() == point) 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)} } 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 { t := TrackerFromContext(gtx) - st := t.Units().SelectedType() text := "Choose unit type" 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) deleteUnitBtn := ActionIconBtn(t.DeleteUnit(), t.Theme, pe.DeleteUnitBtn, icons.ActionDelete, "Delete unit (Ctrl+Backspace)") diff --git a/tracker/params.go b/tracker/params.go index e473085..cb5d337 100644 --- a/tracker/params.go +++ b/tracker/params.go @@ -175,6 +175,12 @@ func (pt *Params) Width() int { } 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) MoveCursor(dx, dy int) (ok bool) { p := pt.Cursor() @@ -260,8 +266,29 @@ func (pt *Params) unmarshalAtCursor(data []byte) (ret bool) { } return ret } -func (pt *Params) unmarshalRange(rect Rect, data []byte) (ok bool) { - panic("NOT IMPLEMENTED") +func (pt *Params) unmarshalRange(rect Rect, data []byte) (ret bool) { + 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() { return (*Model)(pt).change(kind, PatchChange, severity)