fyne bundle

The previous tools will work with any of the Go GUI frameworks, but if you are using the Fyne toolkit, you can make use of its own bundling utility (within the fyne command that is part of the Fyne project). The benefit of using this specific tool when working with a Fyne-based application is that it generates fyne.Resource definitions for each of the embedded resources. This makes it easier to pass an asset into various Fyne APIs. The process for fyne bundle is similar to go-bindata—running the utility converts assets from the filesystem into the Go source code, which can then be compiled into applications. The biggest difference is how we then reference the assets, that is, through declared variables instead of a lookup system.

The bundle command is part of the fyne executable and takes the file to embed as its main parameter. It prints the result to the system output so we use console redirection (>) to send the generated Go source code to a suitable file:

The Fyne bundle command outputs to stdout so we redirect output to a Go file

Once the file is generated (or appended to an existing file), we can reference it using the created symbol (of the *fyne.StaticResource type, which implements fyne.Resource). This can be used like any other resource, so we can load it as an image in the following way:

image := canvas.NewImageFromResource(resourceShinyHallJpg)

The generated variable name may not be ideal for your usage, but it can be changed using an additional command parameter. For example, if you wanted to export this new symbol, you could uppercase the name using -name ShinyHall. To bundle a directory, you can either pass the directory name instead of a filename or run the command repeatedly for individual files with an additional -append parameter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.79.65