英文:
Is it cause performance issue to use multiple Window.SetContent in go with fyne api
问题
我正在开发一个应用程序,但我需要使用 fyne API 的多个 Window.SetContent 方法,但我担心这会降低我的应用程序的性能。最旧的 Window.SetContent 方法是否仍在后台运行?还是在我调用第二个 Window.SetContent 方法后停止工作?以下是测试代码,在我的实际应用程序中,我需要使用比测试代码中更多的 Window.SetContent 方法。我仍然没有找到一个解决方案,使我的应用程序在不使用第二个 Window.SetContent 方法的情况下可用。
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("testing")
w.Resize(fyne.NewSize(400, 400))
testButton1 := widget.NewButton("test1", func(){})
testButton2 := widget.NewButton("go to test1 button", func(){
w.SetContent(testButton1)
})
w.SetContent(testButton2)
w.ShowAndRun()
}
英文:
I am developing an application but i need use multiple Window.SetContent method of fyne api but i am worry about is it will decrease performance of my application. Is the oldest Window.SetContent still running in background ? Or is it stopped working after i call second Window.SetContent method.Here is test code, in my real application i need use more Window.SetContent method than test code. I still did not find a solution making my app usable without using second Window.SetContent method as in the test code.
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("testing")
w.Resize(fyne.NewSize(400, 400))
testButton1 := widget.NewButton("test1", func(){})
testButton2 := widget.NewButton("go to test1 button", func(){
w.SetContent(testButton1)
})
w.SetContent(testButton2)
w.ShowAndRun()
}
答案1
得分: 2
设置窗口内容时,必须检查其是否适合以及其他可能导致速度变慢的因素。
使用容器并替换其内容可能更高效。
这样做还可以更容易地创建可重用的组件,因为小部件不需要使用整个窗口。
英文:
Setting the window content must check it fits and other things that may be slow.
Using a container and replacing its content is likely more efficient.
This is also easier to make reusable components as widgets should not require they are using the whole window.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论