Home > Enterprise >  Fyne Golang: Resize/Move doesn't do anything
Fyne Golang: Resize/Move doesn't do anything

Time:07-09

In some cases Resize() or Move() functions doesn't working.

For example

func createUI(application fyne.App) *fyne.Container {
exitBtn := widget.NewButton("Exit", func() { application.Quit() })
rect := canvas.NewRectangle(color.NRGBA{255, 0, 0, 255})

rect.Resize(fyne.NewSize(500, 500))

header := container.NewMax(rect)
nav := container.NewBorder(canvas.NewText("Navigate", color.Black), exitBtn, nil, nil)
body := container.NewCenter(canvas.NewText("Content", color.Black))

return container.NewBorder(header, nil, nav, body)

}

There rect.Resize(fyne.NewSize(500, 500)) is not working properly. enter image description here

CodePudding user response:

You have put the Rectangle into a container with a layout - it will control the size and position. If you want to do manual positioning you should use container.NewContainerWithoutLayout. Alternatively you can build a custom layout to position items. As you might see in the docs the Move and Resize are how layouts manage widgets, so your code is being overridden.

  • Related