-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
playground.go
41 lines (34 loc) · 1.06 KB
/
playground.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
32
33
34
35
36
37
38
39
40
41
// Package playground provides tooling for running fyne applications inside the Go playground.
package playground
import (
"bytes"
"encoding/base64"
"fmt"
"image"
"image/png"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/driver/software"
"fyne.io/fyne/v2/theme"
)
func imageToPlayground(img image.Image) {
var buf bytes.Buffer
err := png.Encode(&buf, img)
if err != nil {
fyne.LogError("Failed to encode image", err)
return
}
enc := base64.StdEncoding.EncodeToString(buf.Bytes())
fmt.Println("IMAGE:" + enc)
}
// RenderCanvas takes a canvas and converts it into an inline image for showing in the playground
func RenderCanvas(c fyne.Canvas) {
imageToPlayground(software.RenderCanvas(c, theme.DarkTheme()))
}
// RenderWindow takes a window and converts it's canvas into an inline image for showing in the playground
func RenderWindow(w fyne.Window) {
RenderCanvas(w.Canvas())
}
// Render takes a canvasobject and converts it into an inline image for showing in the playground
func Render(obj fyne.CanvasObject) {
imageToPlayground(software.Render(obj, theme.DarkTheme()))
}