Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tapped triggered after Drag #2235

Closed
stuartmscott opened this issue May 10, 2021 · 10 comments
Closed

Tapped triggered after Drag #2235

stuartmscott opened this issue May 10, 2021 · 10 comments
Labels
unverified A bug that has been reported but not verified

Comments

@stuartmscott
Copy link
Member

stuartmscott commented May 10, 2021

Describe the bug:

Tapped is triggered after Drag which can interfere with the user interface; consider the selection scenario where the user can tap to select, or drag to define a rectangle selection. The user drags out a selection but after they release the mouse the selection gets dropped and instead the single element under the mouse gets selected.

Example code:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
	"image/color"
	"log"
)

func main() {
	a := app.New()
	w := a.NewWindow("Events")
	w.SetContent(&interactiveRect{})
	w.Resize(fyne.NewSize(200, 200))
	w.ShowAndRun()
}

var _ fyne.Tappable = (*interactiveRect)(nil)
var _ fyne.SecondaryTappable = (*interactiveRect)(nil)
var _ fyne.Draggable = (*interactiveRect)(nil)

type interactiveRect struct {
	widget.BaseWidget
}

func (r *interactiveRect) CreateRenderer() fyne.WidgetRenderer {
	r.ExtendBaseWidget(r)
	return &interactiveRectRenderer{
		rect: canvas.NewRectangle(theme.PrimaryColor()),
	}
}

func (r *interactiveRect) MinSize() fyne.Size {
	r.ExtendBaseWidget(r)
	return r.BaseWidget.MinSize()
}

func (r *interactiveRect) Tapped(event *fyne.PointEvent) {
	log.Println("Tapped", event)
}

func (r *interactiveRect) TappedSecondary(event *fyne.PointEvent) {
	log.Println("TappedSecondary", event)
}

func (r *interactiveRect) Dragged(event *fyne.DragEvent) {
	log.Println("Dragged", event)
}

func (r *interactiveRect) DragEnd() {
	log.Println("DragEnd")
}

var _ fyne.WidgetRenderer = (*interactiveRectRenderer)(nil)

type interactiveRectRenderer struct {
	rect *canvas.Rectangle
}

func (r *interactiveRectRenderer) BackgroundColor() color.Color {
	return color.Transparent
}

func (r *interactiveRectRenderer) Destroy() {
}

func (r *interactiveRectRenderer) Layout(size fyne.Size) {
	r.rect.Resize(size)
}

func (r *interactiveRectRenderer) MinSize() fyne.Size {
	return r.rect.MinSize()
}

func (r *interactiveRectRenderer) Objects() []fyne.CanvasObject {
	return []fyne.CanvasObject{r.rect}
}

func (r *interactiveRectRenderer) Refresh() {
	r.rect.Refresh()
}

Aside:

In v1.3.3 the Tapped is triggered after the last Drag, but before the DragEnd so it was possible to maintain a dragging bool and ignore Tapped if dragging == true.

v2.0.3

2021/05/10 14:15:01 Dragged &{{{130 75} {126 71}} {-1 0}}
2021/05/10 14:15:01 Dragged &{{{125 75} {121 71}} {-5 0}}
2021/05/10 14:15:01 Dragged &{{{119 75} {115 71}} {-6 0}}
2021/05/10 14:15:01 Dragged &{{{110 76} {106 72}} {-9 1}}
2021/05/10 14:15:01 Dragged &{{{106 77} {102 73}} {-4 1}}
2021/05/10 14:15:01 Dragged &{{{101 78} {97 74}} {-5 1}}
2021/05/10 14:15:01 Dragged &{{{100 79} {96 75}} {-1 1}}
2021/05/10 14:15:01 Dragged &{{{98 80} {94 76}} {-2 1}}
2021/05/10 14:15:01 Dragged &{{{97 80} {93 76}} {-1 0}}
2021/05/10 14:15:01 Dragged &{{{97 80} {93 76}} {0 0}}
2021/05/10 14:15:01 Dragged &{{{97 81} {93 77}} {0 1}}
2021/05/10 14:15:01 Dragged &{{{96 81} {92 77}} {-1 0}}
2021/05/10 14:15:01 DragEnd
2021/05/10 14:15:01 Tapped &{{96 81} {92 77}}

v1.3.3

2021/05/10 14:20:42 Dragged &{{{0 0} {88 45}} -1 0}
2021/05/10 14:20:42 Dragged &{{{0 0} {86 48}} -2 3}
2021/05/10 14:20:42 Dragged &{{{0 0} {85 50}} -1 2}
2021/05/10 14:20:42 Dragged &{{{0 0} {83 52}} -2 2}
2021/05/10 14:20:42 Dragged &{{{0 0} {81 54}} -2 2}
2021/05/10 14:20:42 Dragged &{{{0 0} {78 58}} -3 4}
2021/05/10 14:20:42 Dragged &{{{0 0} {77 59}} -1 1}
2021/05/10 14:20:42 Dragged &{{{0 0} {76 61}} -1 2}
2021/05/10 14:20:42 Dragged &{{{0 0} {74 64}} -2 3}
2021/05/10 14:20:42 Dragged &{{{0 0} {71 67}} -3 3}
2021/05/10 14:20:42 Dragged &{{{0 0} {70 70}} -1 3}
2021/05/10 14:20:42 Dragged &{{{0 0} {68 74}} -2 4}
2021/05/10 14:20:42 Dragged &{{{0 0} {67 75}} -1 1}
2021/05/10 14:20:42 Dragged &{{{0 0} {67 75}} 0 0}
2021/05/10 14:20:42 Tapped &{{71 79} {67 75}}
2021/05/10 14:20:42 DragEnd

Device (please complete the following information):

  • OS: MacOS
  • Version: Big Sur
  • Go version: 1.15
  • Fyne version: 76e0133
@stuartmscott stuartmscott added the unverified A bug that has been reported but not verified label May 10, 2021
@andydotxyz
Copy link
Member

This is really strange. I cannot replicate it within the Entry widget adding debug lines on release/v2.0.x or develop branches.

@andydotxyz
Copy link
Member

P.S. your example is not using the version of Fyne you think it is - that's v1

@stuartmscott
Copy link
Member Author

stuartmscott commented May 11, 2021

This is really strange. I cannot replicate it within the Entry widget adding debug lines on release/v2.0.x or develop branches.

Yes very strange, I also could not replicate with Entry.

Can you reproduce with the provided code sample?

I can reproduce in two ways; with a go.mod containing require fyne.io/fyne/v2 v2.0.3 and with replace fyne.io/fyne/v2 => ../../../fyne.io/fyne where the replacement points to a repo holding develop (76e0133)

P.S. your example is not using the version of Fyne you think it is - that's v1

Yup, it had the v2 suffix when I ran it with v2.0.3, but then I removed it and changed the go.mod so I could test with v1.3.3. I've edited the original message to re-add the v2 suffix.

@andydotxyz
Copy link
Member

Can you reproduce with the provided code sample?

yes I can. But I can’t quite understand how it happens here but not in entry. More work required to hunt down the cause I think.

but then I removed it and changed the go.mod so I could test with v1.3.3.

goodness I’m sorry, misread your message - I was convinced you were reporting against develop and v2.0.3. Oops.

@stuartmscott
Copy link
Member Author

I wonder if it is because Entry implements more interfaces than this example (ie. the desktop MouseIn/Move/Out) so it takes a slightly different path through the driver

@andydotxyz
Copy link
Member

You are probably right about that. I have tagged 2.0.x in case we get a simple fix on this before any other patch releases go out.

@s77rt
Copy link
Contributor

s77rt commented May 15, 2021

not sure i follow correctly but why not just:

if button == desktop.MouseButtonSecondary && altTap {

to:
if button == desktop.MouseButtonSecondary && altTap && !mouseDragStarted {

and

if action == glfw.Release && button == desktop.MouseButtonPrimary {

to:
if action == glfw.Release && button == desktop.MouseButtonPrimary && !mouseDragStarted {

@andydotxyz
Copy link
Member

I think you are probably right @s77rt

@andydotxyz
Copy link
Member

On develop for testing.

@andydotxyz
Copy link
Member

Merged to release/v2.0.x as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

3 participants