From 0444caa9e36c34f88593e13678671585123d3f59 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 8 Jun 2020 21:44:57 +0200 Subject: [PATCH] gesture,widget: drop press markers on gesture cancel Signed-off-by: Elias Naur --- gesture/gesture.go | 7 +++++++ widget/button.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/gesture/gesture.go b/gesture/gesture.go index 7d37e1a7..13774419 100644 --- a/gesture/gesture.go +++ b/gesture/gesture.go @@ -96,6 +96,9 @@ const ( // TypeClick is reported when a click action // is complete. TypeClick + // TypeCancel is reported when the gesture is + // cancelled. + TypeCancel ) 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}) } case pointer.Cancel: + wasPressed := c.state == StatePressed c.state = StateNormal + if wasPressed { + events = append(events, ClickEvent{Type: TypeCancel}) + } case pointer.Press: if c.state == StatePressed { break diff --git a/widget/button.go b/widget/button.go index 6a1ddbed..2d739ea4 100644 --- a/widget/button.go +++ b/widget/button.go @@ -91,6 +91,8 @@ func (b *Clickable) update(gtx layout.Context) { for _, e := range b.click.Events(gtx) { switch e.Type { + case gesture.TypeCancel: + b.history = nil case gesture.TypeClick: b.clicks = append(b.clicks, Click{ Modifiers: e.Modifiers,