From 42c4332e628bc1380ac2559fca69ed0c949db730 Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 10 Apr 2023 21:39:50 +0200 Subject: Further refactoring --- go/main.go | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/go/main.go b/go/main.go index 5dd6105..d480d17 100644 --- a/go/main.go +++ b/go/main.go @@ -16,10 +16,10 @@ import ( ) type Limox struct { - ConnState string - Ui struct { - Window *app.Window - } + ConnState string + Window *app.Window + Operations op.Ops + Theme *material.Theme } func main() { @@ -37,38 +37,36 @@ func main() { } 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 + return Limox{ + ConnState: "disconnected", + Window: app.NewWindow( + app.Title("LimoX"), + app.Size(unit.Dp(400), unit.Dp(600)), + ), + Operations: op.Ops{}, + Theme: material.NewTheme(gofont.Collection()), + } } func (l *Limox) run() error { - - th := material.NewTheme(gofont.Collection()) - var ops op.Ops - for { - e := <-l.Ui.Window.Events() + e := <-l.Window.Events() switch e := e.(type) { case system.DestroyEvent: return e.Err case system.FrameEvent: - gtx := layout.NewContext(&ops, e) - - title := material.H3(th, l.ConnState) - maroon := color.NRGBA{R: 0, G: 212, B: 0, A: 255} - title.Color = maroon - title.Alignment = text.Middle - title.Layout(gtx) - - e.Frame(gtx.Ops) + l.draw(e) } } } + +func (l *Limox) draw(e system.FrameEvent) { + gtx := layout.NewContext(&l.Operations, e) + + stateLabel := material.H3(l.Theme, l.ConnState) + stateLabel.Color = color.NRGBA{R: 0, G: 212, B: 0, A: 255} + stateLabel.Alignment = text.Middle + stateLabel.Layout(gtx) + + e.Frame(gtx.Ops) +} -- cgit v1.2.3-70-g09d2