Image view
To complete the image viewer layout, we need to look at the main image view. The default behavior for images in Fyne is that they'll expand to fill the available space (this is the canvas.ImageFillStretch mode). However, we want the image to maintain its aspect ratio, as well as remain within the bounds of the viewing area. We will also add a background pattern as we did in the Shiny example in Chapter 8, Shiny – Experimental Go GUI API.
Firstly, we create a new image for the background pattern. Fyne provides a helper method to create an image that's drawn dynamically called canvas.NewRasterWithPixels(). It takes a single parameter, which is the pixel calculation function that returns color.Color for the pixel requested. Its parameters ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access