diff options
author | xengineering <me@xengineering.eu> | 2023-02-20 20:51:56 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-02-20 20:51:56 +0100 |
commit | 2ab06fbc7f5b2ed93ee8668ac6f3ab7c1e15130c (patch) | |
tree | 0146575be8a4bcefc99e43fb887cffae38d81692 /go | |
parent | becf716c4de03d58113017cd135b3c90fd77bcac (diff) | |
download | limox-2ab06fbc7f5b2ed93ee8668ac6f3ab7c1e15130c.tar limox-2ab06fbc7f5b2ed93ee8668ac6f3ab7c1e15130c.tar.zst limox-2ab06fbc7f5b2ed93ee8668ac6f3ab7c1e15130c.zip |
Add Golang-based Gio example code
Golang and Gio should be considered as an alternative to the current C-
and SDL-based setup.
Diffstat (limited to 'go')
-rw-r--r-- | go/go.mod | 17 | ||||
-rw-r--r-- | go/go.sum | 34 | ||||
-rw-r--r-- | go/main.go | 49 |
3 files changed, 100 insertions, 0 deletions
diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..de2e3d7 --- /dev/null +++ b/go/go.mod @@ -0,0 +1,17 @@ +module xengineering.eu/limox + +go 1.20 + +require gioui.org v0.0.0-20230206180804-32c6a9b10d0b + +require ( + gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect + gioui.org/shader v1.0.6 // indirect + github.com/benoitkugler/textlayout v0.3.0 // indirect + github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 // indirect + golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect + golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect + golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect + golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect + golang.org/x/text v0.3.7 // indirect +) diff --git a/go/go.sum b/go/go.sum new file mode 100644 index 0000000..4d42bf4 --- /dev/null +++ b/go/go.sum @@ -0,0 +1,34 @@ +eliasnaur.com/font v0.0.0-20220124212145-832bb8fc08c3 h1:djFprmHZgrSepsHAIRMp5UJn3PzsoTg9drI+BDmif5Q= +gioui.org v0.0.0-20230206180804-32c6a9b10d0b h1:ghRvtb24ItyA7QffjaG38gH5f7bzagcz0OPq3T3FyHI= +gioui.org v0.0.0-20230206180804-32c6a9b10d0b/go.mod h1:3lLo7xMHYnnHTrgKNNctBjEKKH3wQCO2Sn7ti5Jy8mU= +gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= +gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc= +gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ= +gioui.org/shader v1.0.6 h1:cvZmU+eODFR2545X+/8XucgZdTtEjR3QWW6W65b0q5Y= +gioui.org/shader v1.0.6/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM= +github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE= +github.com/benoitkugler/textlayout v0.3.0 h1:2ehWXEkgb6RUokTjXh1LzdGwG4dRP6X3dqhYYDYhUVk= +github.com/benoitkugler/textlayout v0.3.0/go.mod h1:o+1hFV+JSHBC9qNLIuwVoLedERU7sBPgEFcuSgfvi/w= +github.com/benoitkugler/textlayout-testdata v0.1.1 h1:AvFxBxpfrQd8v55qH59mZOJOQjtD6K2SFe9/HvnIbJk= +github.com/benoitkugler/textlayout-testdata v0.1.1/go.mod h1:i/qZl09BbUOtd7Bu/W1CAubRwTWrEXWq6JwMkw8wYxo= +github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 h1:iOA0HmtpANn48hX2nlDNMu0VVaNza35HJG0WeetBVzQ= +github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5/go.mod h1:/cmOXaoTiO+lbCwkTZBgCvevJpbFsZ5reXIpEJVh5MI= +golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg= +golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0= +golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8= +golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 h1:/eM0PCrQI2xd471rI+snWuu251/+/jpBpZqir2mPdnU= +golang.org/x/image v0.0.0-20220722155232-062f8c9fd539/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= +golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM= +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/go/main.go b/go/main.go new file mode 100644 index 0000000..5c4c213 --- /dev/null +++ b/go/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "image/color" + "log" + "os" + + "gioui.org/app" + "gioui.org/font/gofont" + "gioui.org/io/system" + "gioui.org/layout" + "gioui.org/op" + "gioui.org/text" + "gioui.org/widget/material" +) + +func main() { + go func() { + w := app.NewWindow() + err := run(w) + if err != nil { + log.Fatal(err) + } + os.Exit(0) + }() + app.Main() +} + +func run(w *app.Window) error { + th := material.NewTheme(gofont.Collection()) + var ops op.Ops + for { + e := <-w.Events() + switch e := e.(type) { + case system.DestroyEvent: + return e.Err + case system.FrameEvent: + gtx := layout.NewContext(&ops, e) + + title := material.H1(th, "Hello, Gio") + maroon := color.NRGBA{R: 127, G: 0, B: 0, A: 255} + title.Color = maroon + title.Alignment = text.Middle + title.Layout(gtx) + + e.Frame(gtx.Ops) + } + } +} |