Files
gio/cmd/gogio/testdata/red.go
T
Elias Naur dc7af8fba3 cmd/gogio: use a more difficult color for end-to-end tests
RGB 0xff0000 is too easy to get right by accident.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:56:37 +01:00

46 lines
817 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/io/system"
"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{R: 0xde, G: 0xad, B: 0xbe, A: 0xff}
ops := new(op.Ops)
for {
e := <-w.Events()
switch e := e.(type) {
case system.DestroyEvent:
return e.Err
case system.FrameEvent:
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)
e.Frame(ops)
}
}
}