Is it cause performance issue to use multiple Window.SetContent in go with fyne api

Issue

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

Solution

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.

Answered By – andy.xyz

Answer Checked By – Mildred Charles (GoLangFix Admin)

Leave a Reply

Your email address will not be published.