Skip to content

Commit 631df28

Browse files
committed
update
1 parent 5457e2a commit 631df28

File tree

9 files changed

+329
-336
lines changed

9 files changed

+329
-336
lines changed

gioui/01-twoRectangles/main.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

gioui/test/main.go renamed to gioui/01/main.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
// SPDX-License-Identifier: Unlicense OR MIT
2-
31
package main
42

5-
// A simple Gio program. See https://gioui.org for more information.
6-
73
import (
84
"image/color"
95
"log"
6+
"os"
107

118
"gioui.org/app"
9+
"gioui.org/font/gofont"
1210
"gioui.org/io/system"
1311
"gioui.org/layout"
1412
"gioui.org/op"
1513
"gioui.org/text"
1614
"gioui.org/widget/material"
17-
18-
"gioui.org/font/gofont"
1915
)
2016

2117
func main() {
2218
go func() {
2319
w := app.NewWindow()
24-
if err := loop(w); err != nil {
20+
err := run(w)
21+
if err != nil {
2522
log.Fatal(err)
2623
}
24+
os.Exit(0)
2725
}()
2826
app.Main()
2927
}
3028

31-
func loop(w *app.Window) error {
32-
gofont.Register()
33-
th := material.NewTheme()
29+
func run(w *app.Window) error {
30+
th := material.NewTheme(gofont.Collection())
3431
var ops op.Ops
3532
for {
3633
e := <-w.Events()
3734
switch e := e.(type) {
3835
case system.DestroyEvent:
3936
return e.Err
4037
case system.FrameEvent:
41-
gtx := layout.NewContext(&ops, e.Queue, e.Config, e.Size)
42-
l := material.H1(th, "Hello, Gio")
43-
maroon := color.RGBA{127, 0, 0, 255}
44-
l.Color = maroon
45-
l.Alignment = text.Middle
46-
l.Layout(gtx)
38+
gtx := layout.NewContext(&ops, e)
39+
40+
title := material.H1(th, "Hello, Gio")
41+
maroon := color.NRGBA{R: 127, G: 0, B: 0, A: 255}
42+
title.Color = maroon
43+
title.Alignment = text.Middle
44+
title.Layout(gtx)
45+
4746
e.Frame(gtx.Ops)
4847
}
4948
}

gioui/02/main.go

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,24 @@
11
package main
22

33
import (
4-
"fmt"
5-
"image/color"
4+
"os"
65

76
"gioui.org/app"
8-
"gioui.org/f32"
9-
"gioui.org/io/key"
10-
"gioui.org/io/system"
11-
"gioui.org/op"
12-
"gioui.org/op/paint"
137
"gioui.org/unit"
148
)
159

1610
func main() {
17-
1811
go func() {
19-
// Overall description:
20-
// 1. Create a window
21-
// 2. create an operations buffer.
22-
// 3. assign an operation (for example draw a rectangle) to the buffer.
23-
// 4. Then call frame event to redraw the window.
24-
window := app.NewWindow(app.Size(unit.Dp(400), unit.Dp(400)))
25-
26-
// Set the initial position of the rectangle
27-
var x0, y0, x1, y1 float32 = 100, 100, 150, 150
28-
29-
// Start an event loop to read all the events happening
30-
// in window, and maybe do something upon an event.
31-
for e := range window.Events() {
32-
if e, ok := e.(system.FrameEvent); ok {
33-
ops := &op.Ops{}
34-
35-
paint.ColorOp{Color: color.RGBA{R: 0x80, A: 0xFF}}.Add(ops)
36-
paint.PaintOp{Rect: f32.Rect(x0, y0, x1, y1)}.Add(ops)
37-
fmt.Printf("%v %v %v %v", x0, y0, x1, y1)
38-
e.Frame(ops)
39-
}
40-
41-
if k, ok := e.(key.Event); ok {
42-
fmt.Printf("k=%#v\n", k)
43-
switch k {
44-
case key.Event{Name: "↑"}:
45-
y0--
46-
y1--
47-
case key.Event{Name: "↓"}:
48-
y0++
49-
y1++
50-
case key.Event{Name: "←"}:
51-
x0--
52-
x1--
53-
case key.Event{Name: "→"}:
54-
x0++
55-
x1++
56-
}
57-
}
12+
// create new window
13+
w := app.NewWindow(
14+
app.Title("Egg timer"),
15+
app.Size(unit.Dp(400), unit.Dp(600)),
16+
)
17+
18+
// listen for events in the window.
19+
for range w.Events() {
5820
}
59-
21+
os.Exit(0)
6022
}()
61-
62-
// app deals with the low level parts towards the platform.
63-
// App also forces us to give up the main() go routine, and
64-
// that is also why we have to start all work in it's own go
65-
// routine's before starting app.Main()
6623
app.Main()
6724
}

gioui/03-button/main.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"gioui.org/app"
7+
"gioui.org/font/gofont"
8+
"gioui.org/io/system"
9+
"gioui.org/layout"
10+
"gioui.org/op"
11+
"gioui.org/unit"
12+
"gioui.org/widget"
13+
"gioui.org/widget/material"
14+
)
15+
16+
func main() {
17+
go func() {
18+
// create new window
19+
w := app.NewWindow(
20+
app.Title("Egg timer"),
21+
app.Size(unit.Dp(400), unit.Dp(600)),
22+
)
23+
24+
// ops are the operations from the UI
25+
var ops op.Ops
26+
27+
// startButton is a clickable widget
28+
var startButton widget.Clickable
29+
30+
// th defnes the material design style
31+
th := material.NewTheme(gofont.Collection())
32+
33+
// listen for events in the window.
34+
for e := range w.Events() {
35+
36+
// detect what type of event
37+
switch e := e.(type) {
38+
39+
// this is sent when the application should re-render.
40+
case system.FrameEvent:
41+
gtx := layout.NewContext(&ops, e)
42+
btn := material.Button(th, &startButton, "Start")
43+
btn.Layout(gtx)
44+
e.Frame(gtx.Ops)
45+
}
46+
}
47+
os.Exit(0)
48+
}()
49+
app.Main()
50+
}

gioui/simple-example/main.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
fyne.io/fyne v1.2.4
7-
gioui.org v0.0.0-20200523211446-d8000880c3b4
7+
gioui.org v0.0.0-20220623114134-e31aa356224e
88
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca
99
github.com/boltdb/bolt v1.3.1
1010
github.com/cavaliercoder/grab v2.0.0+incompatible
@@ -19,6 +19,7 @@ require (
1919
github.com/fsnotify/fsnotify v1.4.9
2020
github.com/fxamacker/cbor/v2 v2.3.0
2121
github.com/gdamore/tcell/v2 v2.5.1
22+
github.com/go-playground/validator/v10 v10.10.1
2223
github.com/goburrow/serial v0.1.0
2324
github.com/golang/protobuf v1.5.2
2425
github.com/google/goexpect v0.0.0-20191001010744-5b6988669ffa
@@ -54,7 +55,7 @@ require (
5455
github.com/vmihailenco/msgpack/v5 v5.3.5
5556
go.bug.st/serial v1.3.3
5657
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
57-
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a
58+
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
5859
golang.org/x/net v0.0.0-20220526153639-5463443f8c37
5960
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
6061
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
@@ -66,19 +67,21 @@ require (
6667

6768
require (
6869
cloud.google.com/go v0.65.0 // indirect
70+
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
71+
gioui.org/shader v1.0.6 // indirect
6972
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 // indirect
7073
github.com/DataDog/zstd v1.4.5 // indirect
7174
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
7275
github.com/Microsoft/go-winio v0.5.1 // indirect
7376
github.com/Microsoft/hcsshim v0.9.2 // indirect
77+
github.com/benoitkugler/textlayout v0.1.1 // indirect
7478
github.com/beorn7/perks v1.0.1 // indirect
7579
github.com/cespare/xxhash v1.1.0 // indirect
7680
github.com/cespare/xxhash/v2 v2.1.2 // indirect
7781
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
7882
github.com/cockroachdb/errors v1.9.0 // indirect
7983
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
8084
github.com/cockroachdb/redact v1.1.3 // indirect
81-
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
8285
github.com/containerd/cgroups v1.0.3 // indirect
8386
github.com/containerd/continuity v0.2.2 // indirect
8487
github.com/containerd/fifo v1.0.0 // indirect
@@ -94,12 +97,13 @@ require (
9497
github.com/fyne-io/mobile v0.0.1 // indirect
9598
github.com/gdamore/encoding v1.0.0 // indirect
9699
github.com/getsentry/sentry-go v0.12.0 // indirect
100+
github.com/gioui/uax v0.2.1-0.20220325163150-e3d987515a12 // indirect
97101
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 // indirect
98102
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 // indirect
99103
github.com/go-gl/mathgl v0.0.0-20190416160123-c4601bc793c7 // indirect
100104
github.com/go-playground/locales v0.14.0 // indirect
101105
github.com/go-playground/universal-translator v0.18.0 // indirect
102-
github.com/go-playground/validator/v10 v10.10.1 // indirect
106+
github.com/go-text/typesetting v0.0.0-20220411150340-35994bc27a7b // indirect
103107
github.com/gogo/googleapis v1.4.1 // indirect
104108
github.com/gogo/protobuf v1.3.2 // indirect
105109
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
@@ -138,10 +142,9 @@ require (
138142
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
139143
github.com/srwiley/rasterx v0.0.0-20181219215540-696f7edb7a7e // indirect
140144
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
141-
github.com/willf/bitset v1.1.11 // indirect
142145
github.com/x448/float16 v0.8.4 // indirect
143146
go.opencensus.io v0.23.0 // indirect
144-
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
147+
golang.org/x/exp v0.0.0-20210722180016-6781d3edade3 // indirect
145148
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
146149
golang.org/x/text v0.3.7 // indirect
147150
google.golang.org/appengine v1.6.7 // indirect

0 commit comments

Comments
 (0)