Skip to content

Instantly share code, notes, and snippets.

@atsushi-kitazawa
Last active June 12, 2022 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atsushi-kitazawa/3be15c92e229f5b793d3d4ac8c2ef668 to your computer and use it in GitHub Desktop.
Save atsushi-kitazawa/3be15c92e229f5b793d3d4ac8c2ef668 to your computer and use it in GitHub Desktop.
fyne table cell update sample.
func RunTest() {
a := app.New()
e := a.NewWindow("test app")
tables(e, fetch("ABC"))
go func() {
fmt.Println("go routine")
time.Sleep(10 * time.Second)
fmt.Println("end sleep")
tables(e, fetch("QAZ"))
}()
e.Resize(fyne.NewSize(600, 600))
e.ShowAndRun()
}
func tables(w fyne.Window, data [][]string) {
lable1 := widget.NewLabel("")
table1 := widget.NewTable(nil, nil, nil)
table1.Length = func() (int, int) {
return len(data), len(data[0])
}
table1.CreateCell = func() fyne.CanvasObject {
return widget.NewLabel("table")
}
table1.UpdateCell = func(id widget.TableCellID, template fyne.CanvasObject) {
label1 := template.(*widget.Label)
label1.SetText(data[id.Row][id.Col])
}
table1.OnSelected = func(id widget.TableCellID) {
lable1.SetText(data[id.Row][id.Col])
}
table1.SetColumnWidth(0, 200)
table1.SetColumnWidth(1, 200)
table1.SetColumnWidth(2, 200)
c := container.NewBorder(lable1, nil, nil, nil, table1)
w.SetContent(c)
}
func fetch(suffix string) [][]string {
data := [][]string{
{"name1_" + suffix, "age1", "sex1"},
{"name1_" + suffix, "age1", "sex1"},
{"name1_" + suffix, "age1", "sex1"},
}
return data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment