Fix chart drawing tools: place once per click, let tooltip pass clicks through

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 15:08:03 -04:00
1 parent f7fdd2d0bd
commit 8394eea44c
3 files changed
+10 -6

No files matched your search

+2 -3
View File
@@ -67,6 +67,7 @@ type mktCore struct {
candles []Candle
view *MarketView
from, to int
act int // keyboard or click activation, mark plus one; zero is none
lo, hi float64
base float64 // percent mode divides by this close; 0 is prices
dec int
@@ -277,9 +278,7 @@ func (m *mktCore) spec() ChartSpec {
}
if d := m.opts.Drawings; d != nil {
spec.Activate = func(i int) {
if !d.Locked && d.Tool != ToolSelect {
d.place(m, DrawingPoint{m.candles[i].Time, m.candles[i].Close})
}
m.act = i + 1
}
}
spec.Readout = m.readout
+3 -3
View File
@@ -47,7 +47,7 @@ func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Ele
}
var tip *ui.Element
ui.Overlay(c, func() {
tip = ui.Column(c).Absolute().Left(left).Top(top).Size(w, h).Role(ui.RoleNone)
tip = ui.Column(c).Absolute().Left(left).Top(top).Size(w, h).Role(ui.RoleNone).PassThrough()
core.OverlayStyle(c, tip, core.OverlayEnter(c, tip))
tip.Children(func() {
inner := max(1, w-2*pad)
@@ -60,8 +60,8 @@ func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Ele
_, lh[i] = c.MeasureText(width, ui.Span{Text: l.Text, Size: size, Weight: chartTipWeight(i)})
content += lh[i]
}
ui.Scroll(c).Fill().Padding(pad).Children(func() {
ui.Box(c).Width(inner).Height(content).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
ui.Scroll(c).Fill().Padding(pad).PassThrough().Children(func() {
ui.Box(c).Width(inner).Height(content).Shrink(0).PassThrough().Draw(func(p *ui.Painter, r ui.Rect) {
at := r.Y
for i, l := range lines {
tx, width := r.X, inner
+5
View File
@@ -63,6 +63,11 @@ func (m *mktCore) input(plot *ui.Element) {
used := false
if d := m.opts.Drawings; d != nil {
used = d.input(m, plot, g, x, y, over, held, dx, dy)
// A click is placed by input at the pointer; only a key press lands here.
if i := m.act - 1; i >= 0 && !used && !d.Locked && d.Tool != ToolSelect {
d.place(m, DrawingPoint{m.candles[i].Time, m.candles[i].Close})
used = true
}
}
if !used {
m.alertsKeyboard(plot)