forked from fyne-io/fyne
/
render.go
31 lines (24 loc) · 886 Bytes
/
render.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package software
import (
"image"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/app"
)
// RenderCanvas takes a canvas and renders it to a regular Go image using the provided Theme.
// This is the same as setting the application theme and then calling Canvas.Capture().
func RenderCanvas(c fyne.Canvas, t fyne.Theme) image.Image {
fyne.CurrentApp().Settings().SetTheme(t)
app.ApplyThemeTo(c.Content(), c)
return c.Capture()
}
// Render takes a canvas object and renders it to a regular Go image using the provided Theme.
// The returned image will be set to the object's minimum size.
// Use the theme.LightTheme() or theme.DarkTheme() to access the builtin themes.
func Render(obj fyne.CanvasObject, t fyne.Theme) image.Image {
fyne.CurrentApp().Settings().SetTheme(t)
c := NewCanvas()
c.SetPadded(false)
c.SetContent(obj)
app.ApplyThemeTo(obj, c)
return c.Capture()
}