From c032978f056b413f654708cb5413b8aa6e116d87 Mon Sep 17 00:00:00 2001 From: vsariola Date: Thu, 7 Jan 2021 14:03:55 +0200 Subject: [PATCH] feat(tracker): make beveling follow tightly the edges of widgets, instead of maximum --- tracker/panels.go | 40 +++++++++++++++++++++------------------- tracker/patterns.go | 1 - tracker/track.go | 8 ++++---- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/tracker/panels.go b/tracker/panels.go index 3e2b079..3ee6b20 100644 --- a/tracker/panels.go +++ b/tracker/panels.go @@ -1,13 +1,14 @@ package tracker import ( + "image" + "image/color" + "gioui.org/f32" "gioui.org/layout" "gioui.org/op" "gioui.org/op/clip" "gioui.org/op/paint" - "image" - "image/color" ) func Raised(w layout.Widget) layout.Widget { @@ -20,31 +21,32 @@ func Lowered(w layout.Widget) layout.Widget { func Beveled(w layout.Widget, base, light, shade color.RGBA) layout.Widget { return func(gtx layout.Context) layout.Dimensions { - paint.FillShape(gtx.Ops, light, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, 1)).Op()) - paint.FillShape(gtx.Ops, light, clip.Rect(image.Rect(0, 0, 1, gtx.Constraints.Max.Y)).Op()) - paint.FillShape(gtx.Ops, base, clip.Rect(image.Rect(1, 1, gtx.Constraints.Max.X-1, gtx.Constraints.Max.Y-1)).Op()) - paint.FillShape(gtx.Ops, shade, clip.Rect(image.Rect(0, gtx.Constraints.Max.Y-1, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op()) - paint.FillShape(gtx.Ops, shade, clip.Rect(image.Rect(gtx.Constraints.Max.X-1, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op()) stack := op.Push(gtx.Ops) - mcs := gtx.Constraints - mcs.Max.X -= 2 - if mcs.Max.X < 0 { - mcs.Max.X = 0 + gtx.Constraints.Max.X -= 2 + if gtx.Constraints.Max.X < 0 { + gtx.Constraints.Max.X = 0 } - if mcs.Min.X > mcs.Max.X { - mcs.Min.X = mcs.Max.X + if gtx.Constraints.Min.X > gtx.Constraints.Max.X { + gtx.Constraints.Min.X = gtx.Constraints.Max.X } - mcs.Max.Y -= 2 - if mcs.Max.Y < 0 { - mcs.Max.Y = 0 + gtx.Constraints.Max.Y -= 2 + if gtx.Constraints.Max.Y < 0 { + gtx.Constraints.Max.Y = 0 } - if mcs.Min.Y > mcs.Max.Y { - mcs.Min.Y = mcs.Max.Y + if gtx.Constraints.Min.Y > gtx.Constraints.Max.Y { + gtx.Constraints.Min.Y = gtx.Constraints.Max.Y } + macro := op.Record(gtx.Ops) op.Offset(f32.Pt(1, 1)).Add(gtx.Ops) - gtx.Constraints = mcs dims := w(gtx) + c := macro.Stop() stack.Pop() + paint.FillShape(gtx.Ops, light, clip.Rect(image.Rect(0, 0, dims.Size.X+2, 1)).Op()) + paint.FillShape(gtx.Ops, light, clip.Rect(image.Rect(0, 0, 1, dims.Size.Y+2)).Op()) + paint.FillShape(gtx.Ops, base, clip.Rect(image.Rect(1, 1, dims.Size.X+1, dims.Size.Y+1)).Op()) + paint.FillShape(gtx.Ops, shade, clip.Rect(image.Rect(0, dims.Size.Y+1, dims.Size.X+2, dims.Size.Y+2)).Op()) + paint.FillShape(gtx.Ops, shade, clip.Rect(image.Rect(dims.Size.X+1, 0, dims.Size.X+2, dims.Size.Y+2)).Op()) + c.Add(gtx.Ops) return layout.Dimensions{ Size: dims.Size.Add(image.Point{X: 2, Y: 2}), Baseline: dims.Baseline + 1, diff --git a/tracker/patterns.go b/tracker/patterns.go index 4276d70..e3080d8 100644 --- a/tracker/patterns.go +++ b/tracker/patterns.go @@ -20,7 +20,6 @@ func (t *Tracker) layoutPatterns(tracks []sointu.Track, activeTrack, cursorPatte return func(gtx layout.Context) layout.Dimensions { gtx.Constraints.Min.X = patternCellWidth * len(tracks) gtx.Constraints.Max.X = patternCellWidth * len(tracks) - gtx.Constraints.Max.Y = 50 defer op.Push(gtx.Ops).Pop() clip.Rect{Max: gtx.Constraints.Max}.Add(gtx.Ops) paint.FillShape(gtx.Ops, panelColor, clip.Rect{Max: image.Pt(gtx.Constraints.Max.X, trackRowHeight)}.Op()) diff --git a/tracker/track.go b/tracker/track.go index 028af19..4ce56dc 100644 --- a/tracker/track.go +++ b/tracker/track.go @@ -34,17 +34,17 @@ func (t *Tracker) layoutTrack(patterns [][]byte, sequence []byte, active bool, c clip.Rect{Max: gtx.Constraints.Max}.Add(gtx.Ops) op.Offset(f32.Pt(0, float32(gtx.Constraints.Max.Y/2)-trackRowHeight)).Add(gtx.Ops) paint.FillShape(gtx.Ops, panelColor, clip.Rect{Max: image.Pt(gtx.Constraints.Max.X, trackRowHeight)}.Op()) - if active { + /*if active { switch cursorCol { case 0: - paint.FillShape(gtx.Ops, panelShadeColor, clip.Rect{Max: image.Pt(36, trackRowHeight)}.Op()) + //paint.FillShape(gtx.Ops, panelShadeColor, clip.Rect{Max: image.Pt(36, trackRowHeight)}.Op()) case 1, 2: s := op.Push(gtx.Ops) op.Offset(f32.Pt(trackWidth/2+float32(cursorCol-1)*10, 0)).Add(gtx.Ops) - paint.FillShape(gtx.Ops, panelShadeColor, clip.Rect{Max: image.Pt(10, trackRowHeight)}.Op()) + //paint.FillShape(gtx.Ops, panelShadeColor, clip.Rect{Max: image.Pt(10, trackRowHeight)}.Op()) s.Pop() } - } + }*/ // TODO: this is a time bomb; as soon as one of the patterns is not the same length as rest. Find a solution // to fix the pattern lengths to a constant value cursorSongRow := cursorPattern*len(patterns[0]) + cursorRow