mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-08 00:30:18 -05:00
drafting
This commit is contained in:
parent
fcb9a06249
commit
06a1fb6b52
@ -11,6 +11,7 @@ import (
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -25,14 +26,15 @@ type (
|
||||
}
|
||||
|
||||
PlotStyle struct {
|
||||
CurveColors [2]color.NRGBA `yaml:",flow"`
|
||||
CurveColors [3]color.NRGBA `yaml:",flow"`
|
||||
LimitColor color.NRGBA `yaml:",flow"`
|
||||
CursorColor color.NRGBA `yaml:",flow"`
|
||||
Ticks LabelStyle
|
||||
DpPerTick unit.Dp
|
||||
}
|
||||
|
||||
PlotDataFunc func(chn int, xr plotRange) (yr plotRange)
|
||||
PlotTickFunc func(r plotRange, yield func(pos float32, label string))
|
||||
PlotDataFunc func(chn int, xr plotRange) (yr plotRange, ok bool)
|
||||
PlotTickFunc func(r plotRange, num int, yield func(pos float32, label string))
|
||||
plotRange struct{ a, b float32 }
|
||||
plotRel float32
|
||||
plotPx int
|
||||
@ -61,8 +63,8 @@ func (p *Plot) Layout(gtx C, data PlotDataFunc, xticks, yticks PlotTickFunc, cur
|
||||
ylim := p.ylim()
|
||||
|
||||
// draw tick marks
|
||||
|
||||
xticks(xlim, func(x float32, txt string) {
|
||||
numxticks := s.X / gtx.Dp(style.DpPerTick)
|
||||
xticks(xlim, numxticks, func(x float32, txt string) {
|
||||
paint.ColorOp{Color: style.LimitColor}.Add(gtx.Ops)
|
||||
sx := plotPx(s.X).toScreen(xlim.toRelative(x))
|
||||
fillRect(gtx, clip.Rect{Min: image.Pt(sx, 0), Max: image.Pt(sx+1, s.Y)})
|
||||
@ -70,7 +72,8 @@ func (p *Plot) Layout(gtx C, data PlotDataFunc, xticks, yticks PlotTickFunc, cur
|
||||
Label(t.Theme, &t.Theme.Plot.Ticks, txt).Layout(gtx)
|
||||
})
|
||||
|
||||
yticks(ylim, func(y float32, txt string) {
|
||||
numyticks := s.Y / gtx.Dp(style.DpPerTick)
|
||||
yticks(ylim, numyticks, func(y float32, txt string) {
|
||||
paint.ColorOp{Color: style.LimitColor}.Add(gtx.Ops)
|
||||
sy := plotPx(s.Y).toScreen(ylim.toRelative(y))
|
||||
fillRect(gtx, clip.Rect{Min: image.Pt(0, sy), Max: image.Pt(s.X, sy+1)})
|
||||
@ -91,13 +94,13 @@ func (p *Plot) Layout(gtx C, data PlotDataFunc, xticks, yticks PlotTickFunc, cur
|
||||
// left and right is the sample range covered by the pixel
|
||||
left := right
|
||||
right = xlim.fromRelative(plotPx(s.X).fromScreen(sx + 1))
|
||||
yr := data(chn, plotRange{left, right})
|
||||
if yr.b < yr.a {
|
||||
yr, ok := data(chn, plotRange{left, right})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
y1 := plotPx(s.Y).toScreen(ylim.toRelative(yr.a))
|
||||
y2 := plotPx(s.Y).toScreen(ylim.toRelative(yr.b))
|
||||
fillRect(gtx, clip.Rect{Min: image.Pt(sx, y1), Max: image.Pt(sx+1, y2+1)})
|
||||
fillRect(gtx, clip.Rect{Min: image.Pt(sx, min(y1, y2)), Max: image.Pt(sx+1, max(y1, y2)+1)})
|
||||
}
|
||||
}
|
||||
return D{Size: s}
|
||||
|
||||
Reference in New Issue
Block a user