From 2ab06fbc7f5b2ed93ee8668ac6f3ab7c1e15130c Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 20 Feb 2023 20:51:56 +0100 Subject: Add Golang-based Gio example code Golang and Gio should be considered as an alternative to the current C- and SDL-based setup. --- go/main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 go/main.go (limited to 'go/main.go') 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) + } + } +} -- cgit v1.2.3-70-g09d2