fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.29k stars 1.41k forks source link

Window freezes when clicking any TableWithHeaders element #4290

Closed Agustincou closed 1 year ago

Agustincou commented 1 year ago

Checklist

Describe the bug

The error occurs every time I click anywhere on a TableWithHeaders element.

The application stops responding for a period of time.

If I do multiple clicks it's worse, the app definitely stops working.

I just check the system resources and I don't see any noticeable difference in Memory, but the processor seems to start running at its maximum frequency.

How to reproduce

  1. Run the code I put here.
  2. Move the slider
  3. Click on any place of TableWithHeaders
  4. (bug) Try to move the slider again
  5. (worst) Click multiple times

Screenshots

image

Example code

package main

import (
    "fmt"
    "time"

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

type Movements struct {
    Value float64
    Date  time.Time
}

func main() {
    fyneApp := app.New()
    fyneWin := fyneApp.NewWindow("Test")

    fyneWin.Resize(fyne.NewSize(640, 720))
    fyneWin.CenterOnScreen()

    fyneWin.SetContent(makeContent(fyneWin))

    fyneWin.ShowAndRun()
}

func makeContent(thisWin fyne.Window) fyne.CanvasObject {
    splitContainer := container.NewVSplit(widget.NewLabel("Random things"), movementsContent(thisWin))

    return splitContainer
}

func movementsContent(thisWin fyne.Window) fyne.CanvasObject {
    movements := []Movements{
        {
            Value: 12.32,
            Date:  time.Now(),
        }, {
            Value: 123.12,
            Date:  time.Now(),
        },
    }

    tableWithHeaders := widget.NewTableWithHeaders(
        func() (int, int) {
            return len(movements), 2 //2 Columns
        },
        func() fyne.CanvasObject {
            return container.NewStack(widget.NewLabel(""))
        },
        func(tci widget.TableCellID, co fyne.CanvasObject) {
            if tci.Col == 0 {
                co.(*fyne.Container).Objects[0].(*widget.Label).SetText(movements[tci.Row].Date.Format("02/01/2006 15:04:05 -07"))
            } else if tci.Col == 1 {
                co.(*fyne.Container).Objects[0].(*widget.Label).SetText(fmt.Sprintf("%.2f", movements[tci.Row].Value))
            }
        },
    )

    tableWithHeaders.CreateHeader = func() fyne.CanvasObject {
        return widget.NewLabel("")
    }
    tableWithHeaders.UpdateHeader = func(id widget.TableCellID, template fyne.CanvasObject) {
        if id.Row < 0 {
            if id.Col == 0 {
                template.(*widget.Label).SetText("DATE")
                template.(*widget.Label).TextStyle = fyne.TextStyle{Bold: true}
            } else if id.Col == 1 {
                template.(*widget.Label).SetText("VALUE")
                template.(*widget.Label).TextStyle = fyne.TextStyle{Bold: true}
            }
        } else {
            template.(*widget.Label).SetText(fmt.Sprintf("%d", id.Row))
            template.(*widget.Label).TextStyle = fyne.TextStyle{Bold: true}
        }
    }

    return tableWithHeaders
}

Fyne version

2.4.0

Go compiler version

1.20.2

Operating system and version

Windows 11

Additional Information

No response

andydotxyz commented 1 year ago

This has already been fixed on develop and will be in v2.4.1 so this is a duplicate of #4264