Search code examples
user-interfacegofyne

Cutomize grid layout rows size


I'm trying to have a grid layout with rows in which first row is a GroupWithScroller and second row is a ContainerWithLayout and has only two buttons, quit and Ok, so the second row's height must be short, but I don't know how to resize any of those. This is what I've tried:

    a := app.New()
    w := a.NewWindow("Title")
    var (
        quitButton = widget.NewButton("Quit", func() {
            a.Quit()
        })

        okButton = widget.NewButton("Ok", func() {
            confirmed = true
            a.Quit()
        })
    )
    var (
        filesBox = widget.NewGroupWithScroller("Another Title",)
        buttonsBox = fyne.NewContainerWithLayout(layout.NewAdaptiveGridLayout(2), quitButton, okButton)
    )
    for _, file := range files {
        var fileCheck = check{
            checked: false,
            label: filepath.Base(file),
        }
        storeChecks = append(storeChecks, &fileCheck)
        filesBox.Append(widget.NewCheck(fileCheck.label, fileCheck.toggle))
    }
    w.SetContent(
        fyne.NewContainerWithLayout(
            layout.NewGridLayoutWithRows(2),
            filesBox,
            buttonsBox,
            ),
        )

    w.Resize(fyne.Size{
        Width:  320,
        Height: 480,
    })
    w.ShowAndRun()

But the result window seems to halve the height for each row:

result window

How to change second row's height?


Solution

  • The GridLayout is designed to keep all elements the same size. If you want the buttons to be minimum height at the bottom you probably want BorderLayout instead - setting the buttons to be in the bottom space should do what you describe.