Skip to content

Clicking table headers causes high CPU consumption #4264

Closed
@3a9LL

Description

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 I click on table headers a few times I get the app hagned. CPU usage above 12%

How to reproduce

  1. Run Fyne Demo
  2. Go to Collections -> Table
  3. Click once on table headers
  4. In a moment the app doesn't respond

or run the sample app below and do the steps since the 3rd

Screenshots

image
image

Example code

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
	"os"
)

func main() {
	os.Setenv("FYNE_THEME", "light")

	myApp := app.New()
	w := myApp.NewWindow("Table with headers")

	tab := makeTableTab()

	tabs := container.NewAppTabs(
		container.NewTabItem("Table", tab),
	)
	tabs.SetTabLocation(container.TabLocationLeading)
	content := container.NewBorder(nil, nil, nil, nil, tabs)
	w.SetContent(content)
	w.Resize(fyne.NewSize(500, 300))

	w.ShowAndRun()

}

type TestStruct struct {
	Name        string
	Path        string
	Description string
}

func makeTableTab() fyne.CanvasObject {
	list := binding.NewUntypedList()
	table := widget.NewTableWithHeaders(
		func() (int, int) {
			return list.Length(), 3
		},
		func() fyne.CanvasObject {
			return widget.NewLabel("template")
		},
		func(id widget.TableCellID, o fyne.CanvasObject) {
			label := o.(*widget.Label)
			ti, _ := list.GetValue(id.Row)
			t := ti.(TestStruct)
			switch id.Col {
			case 0:
				label.SetText(t.Name)
			case 1:
				label.SetText(t.Path)
			case 2:
				label.SetText(t.Description)
			}
		})
	table.CreateHeader = func() fyne.CanvasObject {
		return widget.NewLabel("template")
	}
	colNames := []string{"Name", "Path", "Description"}
	table.UpdateHeader = func(i widget.TableCellID, t fyne.CanvasObject) {
		l := t.(*widget.Label)
		if i.Row == -1 {
			l.SetText(colNames[i.Col])
		}
	}
	table.SetColumnWidth(0, 100)
	table.SetColumnWidth(1, 100)
	table.SetColumnWidth(2, 300)
	table.ShowHeaderColumn = false

	return table
}

Fyne version

2.4.0

Go compiler version

1.21.0

Operating system and version

Microsoft Windows [Version 10.0.19044.3086]

Additional Information

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    blockerItems that would block a forthcoming releasebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions