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

Tree widget jumping to top when selecting element the first time #5478

Closed
2 tasks done
sdassow opened this issue Jan 29, 2025 · 2 comments
Closed
2 tasks done

Tree widget jumping to top when selecting element the first time #5478

sdassow opened this issue Jan 29, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@sdassow
Copy link
Contributor

sdassow commented Jan 29, 2025

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

The first click on a tree item makes the tree jump to the top.

How to reproduce

  1. Run example code below
  2. Open first branch of the tree called foo
  3. Scroll to the end of the foo branch
  4. Select last element
  5. Observe the tree widget jumping to the top

Screenshots

Screen.Recording.2025-01-29.at.14.59.31.mov

Example code

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Hello World")

	treeIDs := map[string][]string{
		"": []string{"foo", "yay"},
		"foo": []string{
			"bar", "meh", "baz", "oops", "aaa", "bbb", "ccc", "ddd",
			"eee", "xxx", "zzz", "uuu", "iii", "ggg", "fff", "what",
			"ever", "this", "needs", "to", "be", "a", "long", "list",
		},
		"yay": []string{"lala", "lol", "haha", "ha"},
	}

	tree := widget.NewTree(
		func(id widget.TreeNodeID) []widget.TreeNodeID {
			if id != "" {
				return treeIDs[id]
			}
			r := []string{}
			for _, k := range treeIDs[id] {
				if len(treeIDs[k]) == 0 {
					continue
				}
				r = append(r, k)
			}
			return r
		},
		func(id widget.TreeNodeID) bool {
			return len(treeIDs[id]) != 0
		},
		func(bool) fyne.CanvasObject {
			return widget.NewLabel("")
		},
		func(i widget.TreeNodeID, _ bool, o fyne.CanvasObject) {
			o.(*widget.Label).SetText(i)
		},
	)

	w.SetContent(tree)
	w.Resize(fyne.NewSize(400, 400))
	w.ShowAndRun()
}

Fyne version

develop / fba693b

Go compiler version

go1.23.3

Operating system and version

MacOS Sonoma (14.7.1)

Additional Information

No response

@sdassow sdassow added the unverified A bug that has been reported but not verified label Jan 29, 2025
@Jacalz Jacalz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Jan 30, 2025
@dweymouth
Copy link
Contributor

Fixed by the above PR

@andydotxyz andydotxyz added this to the E fixes (v2.5.x) milestone Feb 1, 2025
@andydotxyz
Copy link
Member

Hage put it in the fixes milestone in case we do 2.5.5

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

4 participants