I tryied many different way to streatch up my table to the rest of free application space.
The simplies way to reproduce my problem is:
package main
import (
"fmt"
"strconv"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type Reminders struct {
ID int64
EventName string
EventDay time.Time
}
func getReminderSlice() [][]any {
var slice [][]any
reminders := []Reminders{{ID: 0, EventName: "First Event Name", EventDay: time.Now()},
{ID: 1, EventName: "Second Name", EventDay: time.Now()}}
slice = append(slice, []any{
"ID",
"Event Name",
"Event Day",
// "Start At",
// "End At",
// "Event Duration",
// "Event Place",
// "Priority",
// "Description",
"Delete?",
})
for _, r := range reminders {
var currentRow []any
currentRow = append(currentRow, strconv.FormatInt(r.ID, 10))
currentRow = append(currentRow, r.EventName)
currentRow = append(currentRow, r.EventDay.Format("2006-01-02"))
// currentRow = append(currentRow, r.EventStartHour.Format("15:04"))
// currentRow = append(currentRow, r.EventEndHour.Format("15:04"))
// currentRow = append(currentRow, strconv.FormatFloat(r.EventDuration, 'f', -1, 64))
// currentRow = append(currentRow, r.EventPlace)
// currentRow = append(currentRow, strconv.Itoa(int(r.Priority)))
// currentRow = append(currentRow, r.Description)
// currentRow = append(currentRow, widget.NewButton("Delete", func() {}))
slice = append(slice, currentRow)
}
return slice
}
func main() {
data := getReminderSlice()
myApp := app.New()
myWindow := myApp.NewWindow("Table Widget")
myWindow.Resize(fyne.NewSize(850, 530))
// Create a table
list := widget.NewTable(
func() (int, int) {
return len(data), len(data[0])
},
func() fyne.CanvasObject {
container := container.NewVBox(widget.NewLabel(""))
return container
},
func(i widget.TableCellID, o fyne.CanvasObject) {
if i.Col == (len(data[0])-1) && i.Row != 0 {
// last cell, put in a button
w := widget.NewButtonWithIcon("Delete", theme.DeleteIcon(),
func() {
dialog.ShowConfirm("Delete?", "This will delete Event",
func(delete bool) {
if delete {
fmt.Println("Deleted")
}
// refresh the reminders table
// refreshRemindersTable(db, uimanager)
}, myWindow)
})
w.Importance = widget.HighImportance
o.(*fyne.Container).Objects = []fyne.CanvasObject{
w,
}
} else {
o.(*fyne.Container).Objects = []fyne.CanvasObject{
widget.NewLabel(data[i.Row][i.Col].(string)),
}
}
})
// trying to streach up table
remindersContainer := container.NewBorder(
nil,
nil,
nil,
nil,
container.NewAdaptiveGrid(1, list))
colWidths := []float32{50, 150, 150, 150, 150, 150, 150, 150, 150}
for i := range colWidths {
list.SetColumnWidth(i, colWidths[i])
}
// tabs
tabs := container.NewAppTabs(
container.NewTabItemWithIcon("Reminders", theme.HomeIcon(), remindersContainer),
// here will be the second tab
// container.NewTabItemWithIcon("ToDo!", theme.ListIcon(), remindersContainer),
)
tabs.SetTabLocation(container.TabLocationLeading)
// create toolbar
toolbar := widget.NewToolbar(
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.DocumentCreateIcon(), func() {
}),
widget.NewToolbarAction(theme.ViewRefreshIcon(), func() {}),
widget.NewToolbarAction(theme.SettingsIcon(), func() {}),
)
// Creating finaly looking container
finalContent := container.NewVBox(toolbar, tabs)
myWindow.SetContent(finalContent)
myWindow.ShowAndRun()
}
After assembled parts of the final container to NewVBox(toolbar, tabs, table of a content) the table will be small. In horizontal posistion can't streach well. In case of using only tabs with table everything looks good.
I tried so many different way to fix this but can't figure out what is wrong. I want to the finalContent will took up all the free space bellow.
Hope I spell my thoughts in the clear way.
All widgets fill the space available, but your use of VBox is instructing the child items to be minimum height. Use Border container instead where the toolbar is in the top and tabs is the middle.