mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(tracker): make beveling follow tightly the edges of widgets, instead of maximum
This commit is contained in:
parent
8b23fb5c05
commit
c032978f05
@ -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,
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user