英文:
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.
答案1
得分: 2
你已经将矩形放入一个带有布局的容器中 - 它将控制大小和位置。
如果你想手动定位,你应该使用 container.NewContainerWithoutLayout
。
或者你可以构建一个自定义布局来定位元素。正如你在文档中可能看到的,Move
和 Resize
是布局管理小部件的方式,所以你的代码被覆盖了。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论