如何在 Go/Fyne 中向 container.NewGridWithColumns 添加额外的列?
我在 ColumnGrid 中呈现了许多项目(容器)。然后通过一个对话框我想添加一个项目。问题是我找不到扩展原始 ColumnGrid 的方法。
我的代码:
func main() {
a := app.New()
w = a.NewWindow("myApp")
window = container.NewBorder(toolbar(), footer(), nil, nil, content())
w.SetContent(window)
w.ShowAndRun()
}
func content() *fyne.Container {
top := topRow()
bottom := bottomRow()
return container.NewGridWithRows(2, top, bottom)
}
var items []*fyne.Container
func bottomRow() *fyne.Container {
items = nil
db := sql.NewDB()
list, err := db.List()
if err != nil {
//handle error
}
for _, l := range list {
items = append(items, renderChart(l))
}
ct = container.NewGridWithColumns(len(items))
for _, item := range items {
ct.Add(item)
}
return ct
}
func dlgAdd() {
entry := widget.NewEntry()
entry.PlaceHolder = "name"
e := container.NewGridWithRows(2, entry)
d := dialog.NewCustomConfirm(
"Add Item",
"Add",
"Cancel",
e,
func(v bool) {
if !v {
//Cancelled
return
}
if entry.Text == "" {
//without input
return
}
//write entry.Text to db
db := sql.NewDB()
err := db.AddItem(entry.Text)
if err != nil {
return
}
//report succes
i := dialog.NewInformation("Succes", fmt.Sprintf("Item %s added", entry.Text), w)
i.Show()
i.SetOnClosed(func() {
这是问题,如何向容器 ct 添加额外的列,然后将对话框中的项目添加到新列这将不起作用
ct = container.NewGridWithColumns(len(ct.Objects) + 1)
items = append(items, renderChart(entry.Text))
for _, item := range items {
ct.Add(item)
}
这也行不通
bottomRow()
w.Canvas().Refresh(window)
})
}, w)
d.Show()
I am really stuck here.