From 39a3b948e525fe2b22b90e07df323ab77f6a81f6 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 19 Jan 2024 21:26:16 -0500 Subject: keep track of focused widget --- main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index a173fd4..0161a26 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ func run() { var ( displacementChan = make(chan uint) output = make(chan uint) + focus = NewFocus(2) displacement uint = 0 ) @@ -29,6 +30,7 @@ func run() { go widget.Input( displacementChan, r, + focus.widgets[0], mux.MakeEnv(), ) r = image.Rect( @@ -39,6 +41,19 @@ func run() { ) go widget.Label("cc", r, mux.MakeEnv()) + r = image.Rect( + r.Max.X+pad, + r.Min.Y, + r.Max.X+pad+widget.TextWidth(6), + r.Max.Y, + ) + go widget.Input( + displacementChan, + r, + focus.widgets[1], + mux.MakeEnv(), + ) + r = image.Rect( pad, r.Max.Y+pad, @@ -47,6 +62,8 @@ func run() { ) go widget.Output(output, r, mux.MakeEnv()) + focus.widgets[focus.i] <- true + Loop: for { select { @@ -60,8 +77,13 @@ Loop: case win.WiClose: break Loop case win.KbType: - if event.Rune == 'q' { + switch event.Rune { + case 'q': break Loop + case 'j', 'l': + focus.Next() + case 'k', 'h': + focus.Prev() } } } -- cgit v1.2.3