Add JNI example.
This commit is contained in:
+17
-29
@@ -3,25 +3,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/text"
|
||||
"gioui.org/text/shape"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget/material"
|
||||
|
||||
"golang.org/x/image/font/gofont/goregular"
|
||||
"golang.org/x/image/font/sfnt"
|
||||
_ "gioui.org/font/gofont"
|
||||
)
|
||||
|
||||
var (
|
||||
face text.Face
|
||||
white = color.RGBA{A: 0xff, R: 0xff, G: 0xff, B: 0xff}
|
||||
gray = color.RGBA{A: 0xff, R: 0xb0, G: 0xb0, B: 0xb0}
|
||||
black = color.RGBA{A: 0xff, R: 0x00, G: 0x00, B: 0x00}
|
||||
|
||||
labchan chan string
|
||||
)
|
||||
|
||||
@@ -33,7 +26,7 @@ func main() {
|
||||
log.Print("App closed")
|
||||
}
|
||||
|
||||
func diffInsets(x, y app.Insets) bool {
|
||||
func diffInsets(x, y system.Insets) bool {
|
||||
return x.Top != y.Top ||
|
||||
x.Bottom != y.Bottom ||
|
||||
x.Left != y.Left ||
|
||||
@@ -42,41 +35,36 @@ func diffInsets(x, y app.Insets) bool {
|
||||
|
||||
func eventloop() {
|
||||
w := app.NewWindow(
|
||||
app.WithWidth(unit.Dp(400)),
|
||||
app.WithHeight(unit.Dp(400)),
|
||||
app.WithTitle("Hello"))
|
||||
app.Size(unit.Dp(400), unit.Dp(400)),
|
||||
app.Title("Hello"))
|
||||
th := material.NewTheme()
|
||||
gtx := &layout.Context{Queue: w.Queue()}
|
||||
var faces shape.Faces
|
||||
|
||||
regular, err := sfnt.Parse(goregular.TTF)
|
||||
if err != nil {
|
||||
log.Fatal("Cannot parse font.")
|
||||
}
|
||||
face = faces.For(regular, unit.Sp(16))
|
||||
|
||||
sysinset := &layout.Inset{}
|
||||
margin := layout.UniformInset(unit.Dp(10))
|
||||
labels := []*text.Label{}
|
||||
labels := []material.Label{}
|
||||
list := &layout.List{Axis: layout.Vertical}
|
||||
|
||||
resetSysinset := func(x app.Insets) {
|
||||
resetSysinset := func(x system.Insets) {
|
||||
sysinset.Top = x.Top
|
||||
sysinset.Bottom = x.Bottom
|
||||
sysinset.Left = x.Left
|
||||
sysinset.Right = x.Right
|
||||
}
|
||||
|
||||
go func() {
|
||||
labchan <- "Starting"
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case x := <-labchan:
|
||||
labels = append(labels, &text.Label{Face: face, Text: x})
|
||||
labels = append(labels, th.Body1(x))
|
||||
case e := <-w.Events():
|
||||
switch e := e.(type) {
|
||||
case app.DestroyEvent:
|
||||
case system.DestroyEvent:
|
||||
return
|
||||
case app.UpdateEvent:
|
||||
gtx.Reset(&e.Config, e.Size)
|
||||
faces.Reset(&e.Config)
|
||||
case system.FrameEvent:
|
||||
gtx.Reset(e.Config, e.Size)
|
||||
resetSysinset(e.Insets)
|
||||
sysinset.Layout(gtx, func() {
|
||||
margin.Layout(gtx, func() {
|
||||
@@ -85,7 +73,7 @@ func eventloop() {
|
||||
})
|
||||
})
|
||||
})
|
||||
w.Update(gtx.Ops)
|
||||
e.Frame(gtx.Ops)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
//+build android
|
||||
|
||||
package main
|
||||
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
Reference in New Issue
Block a user