Fix chart drawing tools: place once per click, let tooltip pass clicks through
This commit is contained in:
3 files changed
+10
-6
No files matched your search
@@ -67,6 +67,7 @@ type mktCore struct {
|
|||||||
candles []Candle
|
candles []Candle
|
||||||
view *MarketView
|
view *MarketView
|
||||||
from, to int
|
from, to int
|
||||||
|
act int // keyboard or click activation, mark plus one; zero is none
|
||||||
lo, hi float64
|
lo, hi float64
|
||||||
base float64 // percent mode divides by this close; 0 is prices
|
base float64 // percent mode divides by this close; 0 is prices
|
||||||
dec int
|
dec int
|
||||||
@@ -277,9 +278,7 @@ func (m *mktCore) spec() ChartSpec {
|
|||||||
}
|
}
|
||||||
if d := m.opts.Drawings; d != nil {
|
if d := m.opts.Drawings; d != nil {
|
||||||
spec.Activate = func(i int) {
|
spec.Activate = func(i int) {
|
||||||
if !d.Locked && d.Tool != ToolSelect {
|
m.act = i + 1
|
||||||
d.place(m, DrawingPoint{m.candles[i].Time, m.candles[i].Close})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spec.Readout = m.readout
|
spec.Readout = m.readout
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func ChartTooltip(c *ui.Context, x, y float32, lines []ChartTooltipLine) *ui.Ele
|
|||||||
}
|
}
|
||||||
var tip *ui.Element
|
var tip *ui.Element
|
||||||
ui.Overlay(c, func() {
|
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))
|
core.OverlayStyle(c, tip, core.OverlayEnter(c, tip))
|
||||||
tip.Children(func() {
|
tip.Children(func() {
|
||||||
inner := max(1, w-2*pad)
|
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)})
|
_, lh[i] = c.MeasureText(width, ui.Span{Text: l.Text, Size: size, Weight: chartTipWeight(i)})
|
||||||
content += lh[i]
|
content += lh[i]
|
||||||
}
|
}
|
||||||
ui.Scroll(c).Fill().Padding(pad).Children(func() {
|
ui.Scroll(c).Fill().Padding(pad).PassThrough().Children(func() {
|
||||||
ui.Box(c).Width(inner).Height(content).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
|
ui.Box(c).Width(inner).Height(content).Shrink(0).PassThrough().Draw(func(p *ui.Painter, r ui.Rect) {
|
||||||
at := r.Y
|
at := r.Y
|
||||||
for i, l := range lines {
|
for i, l := range lines {
|
||||||
tx, width := r.X, inner
|
tx, width := r.X, inner
|
||||||
|
|||||||
@@ -63,6 +63,11 @@ func (m *mktCore) input(plot *ui.Element) {
|
|||||||
used := false
|
used := false
|
||||||
if d := m.opts.Drawings; d != nil {
|
if d := m.opts.Drawings; d != nil {
|
||||||
used = d.input(m, plot, g, x, y, over, held, dx, dy)
|
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 {
|
if !used {
|
||||||
m.alertsKeyboard(plot)
|
m.alertsKeyboard(plot)
|
||||||
|
|||||||
Reference in new issue
Block a user