mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-08 10:55:35 +00:00
gesture,widget: drop press markers on gesture cancel
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -96,6 +96,9 @@ const (
|
|||||||
// TypeClick is reported when a click action
|
// TypeClick is reported when a click action
|
||||||
// is complete.
|
// is complete.
|
||||||
TypeClick
|
TypeClick
|
||||||
|
// TypeCancel is reported when the gesture is
|
||||||
|
// cancelled.
|
||||||
|
TypeCancel
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -146,7 +149,11 @@ func (c *Click) Events(q event.Queue) []ClickEvent {
|
|||||||
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position, Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
events = append(events, ClickEvent{Type: TypeClick, Position: e.Position, Source: e.Source, Modifiers: e.Modifiers, NumClicks: c.clicks})
|
||||||
}
|
}
|
||||||
case pointer.Cancel:
|
case pointer.Cancel:
|
||||||
|
wasPressed := c.state == StatePressed
|
||||||
c.state = StateNormal
|
c.state = StateNormal
|
||||||
|
if wasPressed {
|
||||||
|
events = append(events, ClickEvent{Type: TypeCancel})
|
||||||
|
}
|
||||||
case pointer.Press:
|
case pointer.Press:
|
||||||
if c.state == StatePressed {
|
if c.state == StatePressed {
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ func (b *Clickable) update(gtx layout.Context) {
|
|||||||
|
|
||||||
for _, e := range b.click.Events(gtx) {
|
for _, e := range b.click.Events(gtx) {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
|
case gesture.TypeCancel:
|
||||||
|
b.history = nil
|
||||||
case gesture.TypeClick:
|
case gesture.TypeClick:
|
||||||
b.clicks = append(b.clicks, Click{
|
b.clicks = append(b.clicks, Click{
|
||||||
Modifiers: e.Modifiers,
|
Modifiers: e.Modifiers,
|
||||||
|
|||||||
Reference in New Issue
Block a user