Fyne Golang:调整大小/移动不起作用

huangapple go评论84阅读模式
英文:

Fyne Golang: Resize/Move doesn't do anything

问题

在某些情况下,Resize()或Move()函数无法正常工作。

例如:

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)
}

这里的rect.Resize(fyne.NewSize(500, 500))无法正常工作。

英文:

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.
Fyne Golang:调整大小/移动不起作用

答案1

得分: 2

你已经将矩形放入一个带有布局的容器中 - 它将控制大小和位置。
如果你想手动定位,你应该使用 container.NewContainerWithoutLayout
或者你可以构建一个自定义布局来定位元素。正如你在文档中可能看到的,MoveResize 是布局管理小部件的方式,所以你的代码被覆盖了。

英文:

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.

huangapple
  • 本文由 发表于 2022年7月7日 20:33:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/72897901.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定