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

list.ScrollToBottom not scrolling to show the totality of the last Item #3829

Closed
2 tasks done
matwachich opened this issue Apr 16, 2023 · 4 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@matwachich
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

When calling .ScrollToBottom, the last list item should be entirely displayed, not only it's top part.

It works well if the last item height is the same as when createItem() function is called.

How to reproduce

Run the code and tap the button

Screenshots

Bad
test_wmfQqVhywX
Good
test_8iQtxyKCrn

Example code

package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

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

	var data []string
	for i := 1; i < 100; i++ {
		data = append(data, fmt.Sprintf("This is item N°%02d\nSpaning on 3 lines\nHere the last one", i))
	}

	var list *widget.List
	list = widget.NewList(
		func() int { return len(data) },
		func() fyne.CanvasObject { return widget.NewLabel("") }, // <=== change this line to .NewLabel("\n\n") to correct scrolling
		func(lii widget.ListItemID, co fyne.CanvasObject) {
			co.(*widget.Label).SetText(data[lii])
			list.SetItemHeight(lii, co.MinSize().Height)
		},
	)

	w.SetContent(container.NewBorder(nil, widget.NewButton("ScrollToBottom", func() { list.ScrollToBottom() }), nil, nil, list))

	w.ShowAndRun()
}

Fyne version

2.3.2

Go compiler version

1.20

Operating system and version

Windows 10

Additional Information

No response

@matwachich matwachich added the unverified A bug that has been reported but not verified label Apr 16, 2023
@Jacalz
Copy link
Member

Jacalz commented Apr 22, 2023

I think this might be a duplicate of #2917. The list is using the scroll container internally as far as I know.

@matwachich
Copy link
Contributor Author

As mentioned in slack (but it should have been done here), I think this has somerhing to do with item heights.

I mean it's like the scrolling considers the initial item height, as when calling CreateItem callback.

If I return a 3 lines label in this example, the scrolling is done correctly.

@andydotxyz
Copy link
Member

andydotxyz commented Apr 30, 2023

Yes, not scrolling and not scrolling far enough are likely different.

andydotxyz added a commit to andydotxyz/fyne that referenced this issue Jun 3, 2023
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Aug 12, 2023
@andydotxyz
Copy link
Member

This issue was resolved. But I see it is possible still to reproduce it.
If the bottom row has never been shown we do not know how long it is. We scroll as far as we think we need to given the template * rows & any known unusually sized rows.
It isn't until after scrolling that the item is shown and the SetItemHeight call is made - so we are doing the best we can.

I don't see a way to "fully resolve" this without adding a "read all lines and lay out my whole table" call, which may be useful for small tables where people just don't care about the performance it was built for.

The solution is to either a) correct the template size to be representative, or b) to load your data and set the sizes before each item is shown.
I guess this is why apps like iMessage or Slack sometimes don't get scrolling right too?

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