mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
gesture,widget: detect multi-click on pointer.Press
References: https://todo.sr.ht/~eliasnaur/gio/455 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-7
@@ -192,12 +192,6 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
}
|
}
|
||||||
c.pressed = false
|
c.pressed = false
|
||||||
if !c.entered || c.hovered {
|
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})
|
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position.Round(), Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
||||||
} else {
|
} else {
|
||||||
events = append(events, ClickEvent{Type: TypeCancel})
|
events = append(events, ClickEvent{Type: TypeCancel})
|
||||||
@@ -224,7 +218,13 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
c.pressed = true
|
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:
|
case pointer.Leave:
|
||||||
if !c.pressed {
|
if !c.pressed {
|
||||||
c.pid = e.PointerID
|
c.pid = e.PointerID
|
||||||
|
|||||||
@@ -98,9 +98,10 @@ func mouseClickEvents(times ...time.Duration) []event.Event {
|
|||||||
}
|
}
|
||||||
events := make([]event.Event, 0, 2*len(times))
|
events := make([]event.Event, 0, 2*len(times))
|
||||||
for _, t := range times {
|
for _, t := range times {
|
||||||
|
press := press
|
||||||
|
press.Time = t
|
||||||
release := press
|
release := press
|
||||||
release.Type = pointer.Release
|
release.Type = pointer.Release
|
||||||
release.Time = t
|
|
||||||
events = append(events, press, release)
|
events = append(events, press, release)
|
||||||
}
|
}
|
||||||
return events
|
return events
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/quick"
|
"testing/quick"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -846,6 +847,7 @@ g 2 4 6 8 g
|
|||||||
font := text.Font{}
|
font := text.Font{}
|
||||||
fontSize := unit.Sp(10)
|
fontSize := unit.Sp(10)
|
||||||
|
|
||||||
|
var tim time.Duration
|
||||||
selected := func(start, end int) string {
|
selected := func(start, end int) string {
|
||||||
// Layout once with no events; populate e.lines.
|
// Layout once with no events; populate e.lines.
|
||||||
gtx.Queue = nil
|
gtx.Queue = nil
|
||||||
@@ -861,15 +863,18 @@ g 2 4 6 8 g
|
|||||||
Buttons: pointer.ButtonPrimary,
|
Buttons: pointer.ButtonPrimary,
|
||||||
Type: pointer.Press,
|
Type: pointer.Press,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
|
Time: tim,
|
||||||
Position: f32.Pt(textWidth(e, startPos.lineCol.Y, 0, startPos.lineCol.X), textHeight(e, startPos.lineCol.Y)),
|
Position: f32.Pt(textWidth(e, startPos.lineCol.Y, 0, startPos.lineCol.X), textHeight(e, startPos.lineCol.Y)),
|
||||||
},
|
},
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Release,
|
Type: pointer.Release,
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
|
Time: tim,
|
||||||
Position: f32.Pt(textWidth(e, endPos.lineCol.Y, 0, endPos.lineCol.X), textHeight(e, endPos.lineCol.Y)),
|
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
|
gtx.Queue = tq
|
||||||
|
|
||||||
e.Layout(gtx, cache, font, fontSize, nil)
|
e.Layout(gtx, cache, font, fontSize, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user