Add Icons paramter to window config
@@ -4,6 +4,8 @@ import (
"image/color"
"runtime"
+ "image"
+
"github.com/faiface/glhf"
"github.com/faiface/mainthread"
"github.com/faiface/pixel"
@@ -20,6 +22,16 @@ type WindowConfig struct {
// Title at the top of the Window.
Title string
+ // Icons specifies the icon images used by the window. This is usually displayed
+ // in the top bar of the window or in the task bar of the desktop environment.
+ // If passed one image, it will use that image, if passed an array of images
+ // those of or closest to the sizes desired by the system are selected.
+ // The desired image sizes varies depending on platform and system settings. The selected
+ // images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
+ // NOTE: Setting this value doesn't have an effect on OSX. You'll need to set the icon
+ // when bundling your application for release.
+ Icons []pixel.Picture
+
// Bounds specify the bounds of the Window in pixels.
Bounds pixel.Rect
@@ -118,7 +130,16 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
w.Update()
runtime.SetFinalizer(w, (*Window).Destroy)
-
+ if len(cfg.Icons) > 0 {
+ var imgs []image.Image
+ for _, v := range cfg.Icons {
+ pic := pixel.PictureDataFromPicture(v)
+ imgs = append(imgs, pic.Image())
+ }
+ mainthread.Call(func() {
+ w.window.SetIcon(imgs)
+ })
+ }
return w, nil
}
