Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
D2 menu using gui/gfx
This file has been truncated, but you can view the full file.
package main
import (
"bytes"
"image"
"image/draw"
"github.com/peterhellberg/gfx"
"github.com/peterhellberg/gui"
)
func main() {
gui.Run(func() {
win, err := gui.Open(gui.Size(800, 600), gui.Decorated(false))
if err != nil {
return
}
for event := range win.Events() {
switch event.(type) {
case gui.EventClose, gui.EventMouseLeftDown:
win.Close()
case gui.EventResize:
win.Draw(drawBytesFunc(d2))
}
}
})
}
func drawBytesFunc(b []byte) func(draw.Image) image.Rectangle {
return func(dst draw.Image) image.Rectangle {
src, err := gfx.DecodePNG(bytes.NewReader(b))
if err != nil {
return image.ZR
}
gfx.Draw(dst, src.Bounds(), src)
return dst.Bounds()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.