Merge pull request #14 from otraore/set-icon
Add support for setting an icon of a window
This commit is contained in:
commit
51a9702fc8
|
@ -1,6 +1,7 @@
|
|||
package pixelgl
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"runtime"
|
||||
|
||||
|
@ -20,6 +21,18 @@ type WindowConfig struct {
|
|||
// Title at the top of the Window.
|
||||
Title string
|
||||
|
||||
// Icon specifies the icon images available to be 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.
|
||||
Icon []pixel.Picture
|
||||
|
||||
// Bounds specify the bounds of the Window in pixels.
|
||||
Bounds pixel.Rect
|
||||
|
||||
|
@ -118,7 +131,14 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
|
|||
w.Update()
|
||||
|
||||
runtime.SetFinalizer(w, (*Window).Destroy)
|
||||
|
||||
imgs := make([]image.Image, len(cfg.Icon))
|
||||
for i, v := range cfg.Icon {
|
||||
pic := pixel.PictureDataFromPicture(v)
|
||||
imgs[i] = pic.Image()
|
||||
}
|
||||
mainthread.Call(func() {
|
||||
w.window.SetIcon(imgs)
|
||||
})
|
||||
return w, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue