aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-01-19 22:07:42 -0500
committerSam Anthony <sam@samanthony.xyz>2024-01-19 22:07:42 -0500
commit54d71a24b6eaa191b2777f6070de252fc26801a3 (patch)
tree1d26f49dfcacc5578b4e6c91e8ffb31b09a9f662 /main.go
parent39a3b948e525fe2b22b90e07df323ab77f6a81f6 (diff)
downloadvolute-54d71a24b6eaa191b2777f6070de252fc26801a3.zip
add layout from Keitio
Diffstat (limited to 'main.go')
-rw-r--r--main.go82
1 files changed, 43 insertions, 39 deletions
diff --git a/main.go b/main.go
index 0161a26..8fe4548 100644
--- a/main.go
+++ b/main.go
@@ -2,73 +2,75 @@ package main
import (
"image"
+ "image/color"
"github.com/faiface/mainthread"
"volute/gui"
+ "volute/gui/layout"
"volute/gui/widget"
"volute/gui/win"
)
+const (
+ WIDTH = 800
+ HEIGHT = 600
+
+ POINTS = 6
+)
+
func run() {
- w, err := win.New(win.Title("volute"), win.Size(800, 600))
+ w, err := win.New(win.Title("volute"), win.Size(WIDTH, HEIGHT))
if err != nil {
panic(err)
}
-
mux, env := gui.NewMux(w)
var (
displacementChan = make(chan uint)
- output = make(chan uint)
- focus = NewFocus(2)
-
- displacement uint = 0
+ rpmChan = make([]chan uint, POINTS)
+ focus = NewFocus(1 + POINTS)
)
+ for i := 0; i < POINTS; i++ {
+ rpmChan[i] = make(chan uint)
+ }
- pad := 10
- r := image.Rect(pad, pad, pad+widget.TextWidth(6), pad+widget.TextHeight())
- go widget.Input(
- displacementChan,
- r,
- focus.widgets[0],
- 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())
+ bounds := layout.Grid{
+ Rows: []int{2, 8, 8},
+ Background: color.Gray{255},
+ Gap: 1,
+ Split: layout.EvenSplit,
+ SplitRows: layout.EvenSplit,
+ Margin: 0,
+ Border: 0,
+ BorderColor: color.Gray{16},
+ Flip: false,
+ }.Lay(image.Rect(0, 0, WIDTH, HEIGHT))
- r = image.Rect(
- r.Max.X+pad,
- r.Min.Y,
- r.Max.X+pad+widget.TextWidth(6),
- r.Max.Y,
- )
+ go widget.Label("displacement (cc)", bounds[0], mux.MakeEnv())
go widget.Input(
displacementChan,
- r,
- focus.widgets[1],
+ bounds[1],
+ focus.widgets[0],
mux.MakeEnv(),
)
- r = image.Rect(
- pad,
- r.Max.Y+pad,
- pad+widget.TextWidth(6),
- r.Max.Y+pad+widget.TextHeight(),
- )
- go widget.Output(output, r, mux.MakeEnv())
+ go widget.Label("Speed (rpm)", bounds[2], mux.MakeEnv())
+ for i := 0; i < len(rpmChan); i++ {
+ go widget.Input(
+ rpmChan[i],
+ bounds[i+3],
+ focus.widgets[i+1],
+ mux.MakeEnv(),
+ )
+ }
focus.widgets[focus.i] <- true
Loop:
for {
select {
- case displacement = <-displacementChan:
- output <- displacement
+ case _ = <-displacementChan:
+ case _ = <-rpmChan[0]:
case event, ok := <-env.Events():
if !ok { // channel closed
break Loop
@@ -90,7 +92,9 @@ Loop:
}
close(env.Draw())
close(displacementChan)
- close(output)
+ for i := range rpmChan {
+ close(rpmChan[i])
+ }
}
func main() {