fyne icon indicating copy to clipboard operation
fyne copied to clipboard

`test.AbsolutePositionForObject` not finding some widgets

Open AlbinoGeek opened this issue 4 years ago • 5 comments

Describe the bug:

test.AbsolutePositionForObject always returns 0,0 for a custom widget

To Reproduce:

Steps to reproduce the behaviour:

  1. Extend a widget (such as *cell does below)
  2. Write a test that renders the widget in the UI
  3. Attempt to get the AbsolutePositionForObject

Example code:

main_test.go

func TestUICells(t *testing.T) {
	var (
		a        = test.NewApp()
		board, w = start(a)
	)
	a.Run()

	assert.NoError(t, board.load(wikipedia), "failed loading valid classic sudoku")
	test.AssertImageMatches(t, "start.png", w.Canvas().Capture())

	drv := a.Driver() // also tried: test.NewDriver()
	pos := drv.AbsolutePositionForObject(board.cells[80])
	test.MoveMouse(w.Canvas(), pos)
	test.TapCanvas(w.Canvas(), pos)
	t.Logf("%#v", pos) // fyne.Position{X:0, Y:0}
	t.Fail()           // forces log to show
}

cell.go

var _ fyne.Widget = (*cell)(nil)
var _ fyne.Disableable = (*cell)(nil)
var _ desktop.Hoverable = (*cell)(nil)
var _ desktop.Mouseable = (*cell)(nil)
var _ mobile.Touchable = (*cell)(nil)

type cell struct {
	widget.BaseWidget `json:"-"`
	// ...
}

func newCell(id int) *cell {
	c := &cell{}
	c.ExtendBaseWidget(c)

	return c
}

Device (please complete the following information):

  • OS: Fedora Workstation
  • Version: 33
  • Go version: 1.15.6 linux/amd64
  • Fyne version: 2.0.0-rc5

AlbinoGeek avatar Jan 21 '21 00:01 AlbinoGeek