diff options
| author | xengineering <me@xengineering.eu> | 2023-04-10 20:54:42 +0200 | 
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2023-04-10 20:54:42 +0200 | 
| commit | f5856f6ae2ee6dac937836fddf937d899328f40e (patch) | |
| tree | cb51b85b5cbe33d9e2a7f1c1c8361938bbe85d16 /go | |
| parent | cb357b16765793b4d4c1d8b0b96411f2a7db9e21 (diff) | |
| download | limox-f5856f6ae2ee6dac937836fddf937d899328f40e.tar limox-f5856f6ae2ee6dac937836fddf937d899328f40e.tar.zst limox-f5856f6ae2ee6dac937836fddf937d899328f40e.zip | |
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.
Diffstat (limited to 'go')
| -rw-r--r-- | go/main.go | 37 | 
1 files changed, 29 insertions, 8 deletions
| @@ -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 | 
