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

Child widget with Hoverable() interface keeps parent widget's Tapped() function from being called. #3906

Closed
2 tasks done
pbrown12303 opened this issue May 22, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@pbrown12303
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Create a widget with the Tappable interface. Add a child widget with the Hoverable interface. If the child widget is shown, the Tapped() function is never called. Hide the child widget and the Tapped() function is called as expected.

How to reproduce

  1. Run the example (it starts up with the child being shown
  2. Click on the child (solid black square)
  3. Note that there is no log entry indicating the Tapped() function being called on the parent widget. Click outside the child (solid black square) and you'll get the log entry.
  4. Remember the location of the child (solid black square). Click on the Hide Child button and the child will disappear. Now click where the child was. You'll get the Tapped() call.

Screenshots

image

Example code

package main

import (
	"image/color"
	"log"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/widget"
)

func main() {

	testApp := app.New()
	w := testApp.NewWindow("Test Tappable with Hoverable Child")
	w.Resize(fyne.NewSize(600, 600))

	pw := newParentWidget()

	showButton := widget.NewButton("Show Child", func() {
		pw.cw.Show()
	})
	hideButton := widget.NewButton("Hide Child", func() {
		pw.cw.Hide()
	})
	showButton.Resize(showButton.MinSize())
	hideButton.Resize(hideButton.MinSize())
	topVbox := container.NewVBox(showButton, hideButton)
	vBox := container.NewVBox(topVbox, pw)
	w.SetContent(vBox)
	w.ShowAndRun()
}

var _ fyne.Tappable = (*parentWidget)(nil)

type parentWidget struct {
	widget.BaseWidget
	cw *childWidget
}

func newParentWidget() *parentWidget {
	pw := &parentWidget{}
	pw.BaseWidget.ExtendBaseWidget(pw)
	pw.cw = newChildWidget()
	return pw
}

func (pw *parentWidget) CreateRenderer() fyne.WidgetRenderer {
	pwr := &parentWidgetRenderer{
		pw:         pw,
		parentRect: canvas.NewRectangle(color.Black),
	}
	pwr.parentRect.FillColor = color.Transparent
	return pwr
}

func (pw *parentWidget) Tapped(*fyne.PointEvent) {
	log.Print("Parent widget tapped")
}

type parentWidgetRenderer struct {
	pw         *parentWidget
	parentRect *canvas.Rectangle
}

func (pwr *parentWidgetRenderer) Destroy() {

}

func (pwr *parentWidgetRenderer) Layout(size fyne.Size) {
	pwr.parentRect.Resize(size)
	pwr.pw.cw.Move(fyne.NewPos(25, 25))
	pwr.pw.cw.Resize(fyne.NewSize(50, 50))
}

func (pwr *parentWidgetRenderer) MinSize() fyne.Size {
	return fyne.NewSize(100, 100)
}

func (pwr *parentWidgetRenderer) Objects() []fyne.CanvasObject {
	obj := []fyne.CanvasObject{
		pwr.parentRect,
		pwr.pw.cw,
	}
	return obj
}

func (pwr *parentWidgetRenderer) Refresh() {

}

var _ desktop.Hoverable = (*childWidget)(nil)

type childWidget struct {
	widget.BaseWidget
}

func newChildWidget() *childWidget {
	cw := &childWidget{}
	cw.BaseWidget.ExtendBaseWidget(cw)
	return cw
}

func (cw *childWidget) CreateRenderer() fyne.WidgetRenderer {
	cwr := &childWidgetRenderer{
		cw:             cw,
		childRectangle: canvas.NewRectangle(color.Black),
	}
	return cwr
}

func (cw *childWidget) MouseIn(*desktop.MouseEvent) {

}

func (cw *childWidget) MouseMoved(*desktop.MouseEvent) {

}

func (cw *childWidget) MouseOut() {

}

type childWidgetRenderer struct {
	cw             *childWidget
	childRectangle *canvas.Rectangle
}

func (cwr *childWidgetRenderer) Destroy() {

}

func (cwr *childWidgetRenderer) Layout(size fyne.Size) {
	cwr.childRectangle.Resize(size)
}

func (cwr *childWidgetRenderer) MinSize() fyne.Size {
	return fyne.NewSize(50, 50)
}

func (cwr *childWidgetRenderer) Objects() []fyne.CanvasObject {
	obj := []fyne.CanvasObject{
		cwr.childRectangle,
	}
	return obj
}

func (cwr *childWidgetRenderer) Refresh() {

}

Fyne version

2.3.3

Go compiler version

1.20.3

Operating system and version

Windows 10 19045.2965

Additional Information

No response

@pbrown12303 pbrown12303 added the unverified A bug that has been reported but not verified label May 22, 2023
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels May 24, 2023
@andydotxyz andydotxyz added this to the Fixes (v2.3.x) milestone May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants