summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-04-10 21:39:50 +0200
committerxengineering <me@xengineering.eu>2023-04-11 19:17:20 +0200
commit42c4332e628bc1380ac2559fca69ed0c949db730 (patch)
tree4de709fc0018214a265ea9dc954ecbe95710a156
parentf5856f6ae2ee6dac937836fddf937d899328f40e (diff)
downloadlimox-42c4332e628bc1380ac2559fca69ed0c949db730.tar
limox-42c4332e628bc1380ac2559fca69ed0c949db730.tar.zst
limox-42c4332e628bc1380ac2559fca69ed0c949db730.zip
Further refactoring
-rw-r--r--go/main.go54
1 files 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)
+}