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

problem with table.ScrollToBottom #2918

Closed
dimitrove opened this issue Apr 12, 2022 · 11 comments
Closed

problem with table.ScrollToBottom #2918

dimitrove opened this issue Apr 12, 2022 · 11 comments

Comments

@dimitrove
Copy link

dimitrove commented Apr 12, 2022

When the table is long and only part of it is displayed, then ScrollToBottom works fine.
When the table is short and is displayed in full, then ScrollToBottom fails.

The test bellow works with "go run . 12" and fails with "go run . 4"

package main

import (
	"os"
	"strconv"

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

var tableTest *widget.Table
var theApp fyne.App
var theWindow fyne.Window

// -----
func onSomeCellSelected(id widget.TableCellID) {
	tableTest.ScrollToBottom()
}


// ----- main
func main() {
	arg := os.Args[1]
	len, _ := strconv.Atoi(arg)

	theApp = app.New()
	theWindow = theApp.NewWindow("test")
	theWindow.Resize(fyne.NewSize(200, 300))

	data := []string{"00", "01", "02", "03", "04", "05", "06", "07",
		"08", "09", "10", "11", "012", "013", "14", "15"}

	tableTest = widget.NewTable(
		func() (int, int) { return len, 1 },
		func() fyne.CanvasObject {
			return widget.NewLabel("****")
		},
		func(i widget.TableCellID, obj fyne.CanvasObject) {
			// i is index with i.Col and i.Row
			obj.(*widget.Label).SetText(data[i.Row])
		},
	)
	tableTest.OnSelected = onSomeCellSelected

	theWindow.SetContent(container.NewBorder(
		nil, nil, nil, nil, tableTest))
	theWindow.ShowAndRun()
}
@Jacalz
Copy link
Member

Jacalz commented Apr 13, 2022

Sorry, this is the wrong issue tracker. This one is only for the developer site and not for bugs related to Fyne.

@Jacalz Jacalz transferred this issue from fyne-io/developer.fyne.io Apr 13, 2022
@andydotxyz
Copy link
Member

I don't understand this part:

When the table is short and is displayed in full, then ScrollToBottom fails.

What would the expected outcome be if there is nothing to scroll? In what way is it failing?

@dimitrove
Copy link
Author

I don't understand this part:

When the table is short and is displayed in full, then ScrollToBottom fails.

What would the expected outcome be if there is nothing to scroll? In what way is it failing?

It crashes. It panics.

@dimitrove
Copy link
Author

Actually, it (the table) asks the provided function for value for a cell with negative row number. Which causes the provided function to crash because of using a negative array index.

@andydotxyz
Copy link
Member

Ah I see thanks. This is jogging something of my memory but I cannot find an issue.
Can you please confirm that you are on v2.1.4 so we're not missing any fixes?

@dimitrove
Copy link
Author

Ah I see thanks. This is jogging something of my memory but I cannot find an issue. Can you please confirm that you are on v2.1.4 so we're not missing any fixes?

Yes, I am on v2.1.4. It looks like the ScrollToBottom tries to place the bottom row at the last visible line. And it calculates the row number for the first visible line. Because the number of rows is less than the number of visible lines, the row number for the first visible line becomes negative.

@andydotxyz
Copy link
Member

Ah I see, this is a crash from -1? That was not clear from the description.
Can you please include the stack trace from the panic? It will be a lot easier to confirm and fix with that info @dimitrove

@dimitrove
Copy link
Author

This is it.
trace.txt

@andydotxyz
Copy link
Member

There were some fixes in v2.2.0, please check against that. Otherwise it might be resolved with the linked PR.

@dimitrove
Copy link
Author

dimitrove commented Jun 23, 2022 via email

@andydotxyz
Copy link
Member

Excellent thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants