Files
gio/cmd/gogio/testdata/red.go
T
2019-09-30 16:55:47 +02:00

45 lines
770 B
Go

// SPDX-License-Identifier: Unlicense OR MIT
// A dead simple app that just paints the background red.
package main
import (
"image/color"
"log"
"gioui.org/app"
"gioui.org/f32"
"gioui.org/op"
"gioui.org/op/paint"
)
func main() {
go func() {
w := app.NewWindow()
if err := loop(w); err != nil {
log.Fatal(err)
}
}()
app.Main()
}
func loop(w *app.Window) error {
background := color.RGBA{255, 0, 0, 255}
ops := new(op.Ops)
for {
e := <-w.Events()
switch e := e.(type) {
case app.DestroyEvent:
return e.Err
case app.UpdateEvent:
ops.Reset()
paint.ColorOp{Color: background}.Add(ops)
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{
X: float32(e.Size.X),
Y: float32(e.Size.Y),
}}}.Add(ops)
w.Update(ops)
}
}
}