summaryrefslogtreecommitdiff
path: root/go/main.go
blob: d480d174c0ea7b1c7197ab175719e997f4e60ae8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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/unit"
	"gioui.org/widget/material"
)

type Limox struct {
	ConnState  string
	Window     *app.Window
	Operations op.Ops
	Theme      *material.Theme
}

func main() {
	limox := NewLimox()

	go func() {
		err := limox.run()
		if err != nil {
			log.Fatal(err)
		}
		os.Exit(0)
	}()

	app.Main()
}

func NewLimox() 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 {
	for {
		e := <-l.Window.Events()
		switch e := e.(type) {
		case system.DestroyEvent:
			return e.Err
		case system.FrameEvent:
			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)
}