M gesture/gesture.go => gesture/gesture.go +7 -7
@@ 192,12 192,6 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
}
c.pressed = false
if !c.entered || c.hovered {
- if e.Time-c.clickedAt < doubleClickDuration {
- c.clicks++
- } else {
- c.clicks = 1
- }
- c.clickedAt = e.Time
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
} else {
events = append(events, ClickEvent{Type: TypeCancel})
@@ 224,7 218,13 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
break
}
c.pressed = true
- events = append(events, ClickEvent{Type: TypePress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers})
+ if e.Time-c.clickedAt < doubleClickDuration {
+ c.clicks++
+ } else {
+ c.clicks = 1
+ }
+ c.clickedAt = e.Time
+ events = append(events, ClickEvent{Type: TypePress, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
case pointer.Leave:
if !c.pressed {
c.pid = e.PointerID
M gesture/gesture_test.go => gesture/gesture_test.go +2 -1
@@ 98,9 98,10 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
}
events := make([]event.Event, 0, 2*len(times))
for _, t := range times {
+ press := press
+ press.Time = t
release := press
release.Type = pointer.Release
- release.Time = t
events = append(events, press, release)
}
return events
M widget/editor_test.go => widget/editor_test.go +5 -0
@@ 12,6 12,7 @@ import (
"strings"
"testing"
"testing/quick"
+ "time"
"unicode"
"unicode/utf8"
@@ 846,6 847,7 @@ g 2 4 6 8 g
font := text.Font{}
fontSize := unit.Sp(10)
+ var tim time.Duration
selected := func(start, end int) string {
// Layout once with no events; populate e.lines.
gtx.Queue = nil
@@ 861,15 863,18 @@ g 2 4 6 8 g
Buttons: pointer.ButtonPrimary,
Type: pointer.Press,
Source: pointer.Mouse,
+ Time: tim,
Position: f32.Pt(textWidth(e, startPos.lineCol.Y, 0, startPos.lineCol.X), textHeight(e, startPos.lineCol.Y)),
},
pointer.Event{
Type: pointer.Release,
Source: pointer.Mouse,
+ Time: tim,
Position: f32.Pt(textWidth(e, endPos.lineCol.Y, 0, endPos.lineCol.X), textHeight(e, endPos.lineCol.Y)),
},
},
}
+ tim += time.Second // Avoid multi-clicks.
gtx.Queue = tq
e.Layout(gtx, cache, font, fontSize, nil)