From f5856f6ae2ee6dac937836fddf937d899328f40e Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 10 Apr 2023 20:54:42 +0200 Subject: go: Refactor with Limox struct The central Limox struct allows to structure the whole application in one struct and pass it around to different functions. --- go/main.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/go/main.go b/go/main.go index 440d74b..5dd6105 100644 --- a/go/main.go +++ b/go/main.go @@ -15,33 +15,54 @@ import ( "gioui.org/widget/material" ) +type Limox struct { + ConnState string + Ui struct { + Window *app.Window + } +} + func main() { + limox := NewLimox() + go func() { - w := app.NewWindow( - app.Title("LimoX"), - app.Size(unit.Dp(400), unit.Dp(600)), - ) - err := run(w) + err := limox.run() if err != nil { log.Fatal(err) } os.Exit(0) }() + app.Main() } -func run(w *app.Window) error { +func NewLimox() Limox { + limox := Limox{} + + limox.Ui.Window = app.NewWindow( + app.Title("LimoX"), + app.Size(unit.Dp(400), unit.Dp(600)), + ) + + limox.ConnState = "disconnected" + + return limox +} + +func (l *Limox) run() error { + th := material.NewTheme(gofont.Collection()) var ops op.Ops + for { - e := <-w.Events() + e := <-l.Ui.Window.Events() switch e := e.(type) { case system.DestroyEvent: return e.Err case system.FrameEvent: gtx := layout.NewContext(&ops, e) - title := material.H3(th, "disconnected") + title := material.H3(th, l.ConnState) maroon := color.NRGBA{R: 0, G: 212, B: 0, A: 255} title.Color = maroon title.Alignment = text.Middle -- cgit v1.2.3-70-g09d2