aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
blob: eb2e094ff42f735668a50732b36fa942e720aae2 (plain) (blame)
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
package main

import (
	"image"

	"github.com/faiface/mainthread"
	"volute/gui"
	"volute/gui/widget"
	"volute/gui/win"
)

func run() {
	w, err := win.New(win.Title("volute"), win.Size(800, 600))
	if err != nil {
		panic(err)
	}

	mux, env := gui.NewMux(w)

	var (
		displacementChan = make(chan float64)
	)

	pad := 10
	r := image.Rect(pad, pad, pad+widget.TextWidth(6), pad+widget.TextHeight())
	go widget.Input(
		displacementChan,
		r,
		mux.MakeEnv(),
	)
	r = image.Rect(
		r.Max.X+pad,
		r.Min.Y,
		r.Max.X+pad+widget.TextWidth(len("cc")),
		r.Max.Y,
	)
	go widget.Label("cc", r, mux.MakeEnv())

Loop:
	for event := range env.Events() {
		switch event := event.(type) {
		case win.WiClose:
			break Loop
		case win.KbType:
			if event.Rune == 'q' {
				break Loop
			}
		}
		select {
		case _ = <-displacementChan:
		default:
		}
	}
	close(env.Draw())
	close(displacementChan)
}

func main() {
	mainthread.Run(run)
}