This commit is contained in:
5684185+vsariola@users.noreply.github.com
2026-01-01 19:59:23 +02:00
parent 179ebb7cc3
commit fcb9a06249
5 changed files with 44 additions and 19 deletions

View File

@ -8,6 +8,7 @@ import (
"gioui.org/f32"
"gioui.org/io/event"
"gioui.org/io/pointer"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
@ -27,6 +28,7 @@ type (
CurveColors [2]color.NRGBA `yaml:",flow"`
LimitColor color.NRGBA `yaml:",flow"`
CursorColor color.NRGBA `yaml:",flow"`
Ticks LabelStyle
}
PlotDataFunc func(chn int, xr plotRange) (yr plotRange)
@ -47,7 +49,7 @@ func NewPlot(xlim, ylim plotRange) *Plot {
func (p *Plot) Layout(gtx C, data PlotDataFunc, xticks, yticks PlotTickFunc, cursornx float32, numchns int) D {
p.update(gtx)
t := TrackerFromContext(gtx)
style := t.Theme.Oscilloscope
style := t.Theme.Plot
s := gtx.Constraints.Max
if s.X <= 1 || s.Y <= 1 {
return D{}
@ -59,16 +61,21 @@ func (p *Plot) Layout(gtx C, data PlotDataFunc, xticks, yticks PlotTickFunc, cur
ylim := p.ylim()
// draw tick marks
paint.ColorOp{Color: style.LimitColor}.Add(gtx.Ops)
xticks(xlim, func(x float32, label string) {
xticks(xlim, 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)})
defer op.Offset(image.Pt(sx, gtx.Dp(2))).Push(gtx.Ops).Pop()
Label(t.Theme, &t.Theme.Plot.Ticks, txt).Layout(gtx)
})
yticks(ylim, func(y float32, label string) {
yticks(ylim, 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)})
defer op.Offset(image.Pt(gtx.Dp(2), sy)).Push(gtx.Ops).Pop()
Label(t.Theme, &t.Theme.Plot.Ticks, txt).Layout(gtx)
})
// draw cursor