I'm trying to setting up an app layout using Fyne (https://fyne.io/) but I'm having some problems; here is my code:
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Demo")
myWindow.SetMaster()
myWindow.SetPadded(false)
myWindow.Resize(fyne.NewSize(1024, 600))
//myWindow.SetFullScreen(true)
r1 := canvas.NewRectangle(color.RGBA{255, 0, 0, 255})
r1.SetMinSize(fyne.NewSize(1024, 110))
top := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r1)
r2 := canvas.NewRectangle(color.RGBA{0, 255, 0, 255})
r2.SetMinSize(fyne.NewSize(1024, 400))
middle := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r2)
message := widget.NewLabel("message")
messageWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), message)
middle.AddObject(messageWrap)
r3 := canvas.NewRectangle(color.RGBA{255, 0, 255, 255})
r3.SetMinSize(fyne.NewSize(1024, 55))
bottom := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r3)
data := widget.NewLabel("data")
dataWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), data)
ua := widget.NewLabel("ua")
uaWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), ua)
bottomWrap := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, nil, dataWrap, uaWrap), dataWrap, uaWrap)
bottom.AddObject(bottomWrap)
content := fyne.NewContainerWithLayout(layout.NewBorderLayout(top, bottom, nil, nil), top, bottom, middle)
myWindow.SetContent(content)
myWindow.ShowAndRun()
}
and here is the output:
I'm new to this library and I find it really hard to understand how it works; I'd need to remove the "padding" between the top
,middle
, and bottom
blocks in my layout; is there a way to do that?
You are using BorderLayout, this layout (as do most of the built-in ones) adds padding between the elements, there is no layout configuration to turn this off.
You have two options:
Pass in your own layout that moves and resizes elements exactly as you would like
Set up a custom theme where the padding is set to 0 (not advisable).
You'll find that the library is opinionated about how widgets and layouts work. One of the things it imposes is that every standard layout separates every element with padding.