在使用Go语言和Fyne API中多次调用`Window.SetContent`是否会导致性能问题?

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

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.

huangapple
  • 本文由 发表于 2022年11月23日 01:22:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/74536725.html
匿名

发表评论

匿名网友

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

确定