2
0
mirror of synced 2025-02-23 23:08:14 +00:00
mobile/app/shiny.go
Russ Cox bdb1ca9a1e all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I30822eb504168b037ed3ec0f7759da1f41251f52
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/294374
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2021-02-20 03:30:13 +00:00

72 lines
1.3 KiB
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build windows
// +build windows
package app
import (
"log"
"golang.org/x/exp/shiny/driver/gldriver"
"golang.org/x/exp/shiny/screen"
"golang.org/x/mobile/event/lifecycle"
"golang.org/x/mobile/event/mouse"
"golang.org/x/mobile/event/touch"
"golang.org/x/mobile/gl"
)
func main(f func(a App)) {
gldriver.Main(func(s screen.Screen) {
w, err := s.NewWindow(nil)
if err != nil {
log.Fatal(err)
}
defer w.Release()
theApp.glctx = nil
theApp.worker = nil // handled by shiny
go func() {
for range theApp.publish {
res := w.Publish()
theApp.publishResult <- PublishResult{
BackBufferPreserved: res.BackBufferPreserved,
}
}
}()
go f(theApp)
for {
theApp.Send(convertEvent(w.NextEvent()))
}
})
}
func convertEvent(e interface{}) interface{} {
switch e := e.(type) {
case lifecycle.Event:
if theApp.glctx == nil {
theApp.glctx = e.DrawContext.(gl.Context)
}
case mouse.Event:
te := touch.Event{
X: e.X,
Y: e.Y,
}
switch e.Direction {
case mouse.DirNone:
te.Type = touch.TypeMove
case mouse.DirPress:
te.Type = touch.TypeBegin
case mouse.DirRelease:
te.Type = touch.TypeEnd
}
return te
}
return e
}