diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-02-08 01:21:30 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-02-08 01:21:30 -0500 |
| commit | d0808b329d7f2b5e723fb3e1289d80e166ea342f (patch) | |
| tree | cbfb8793fc4e55c0531bc2bd38b2439ce48e1fdd /focus.go | |
| parent | aa5ad436d2aeb962723506ec4ca137fd095af169 (diff) | |
| download | volute-d0808b329d7f2b5e723fb3e1289d80e166ea342f.zip | |
add Focus() method; replace Point with image.Point
Diffstat (limited to 'focus.go')
| -rw-r--r-- | focus.go | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -1,14 +1,16 @@ package main +import "image" + type Focus struct { widgets [][]chan bool - p Point // currently focused widget + p image.Point // currently focused widget } func NewFocus(rows []int) Focus { f := Focus{ make([][]chan bool, len(rows)), - Point{}, + image.Point{}, } for i := range f.widgets { f.widgets[i] = make([]chan bool, rows[i]) @@ -27,40 +29,40 @@ func (f *Focus) Close() { } } +func (f *Focus) Focus(focus bool) { + f.widgets[f.p.Y][f.p.X] <- focus +} + func (f *Focus) Left() { - f.widgets[f.p.Y][f.p.X] <- false + f.Focus(false) if f.p.X <= 0 { f.p.X = len(f.widgets[f.p.Y]) - 1 } else { f.p.X-- } - f.widgets[f.p.Y][f.p.X] <- true + f.Focus(true) } func (f *Focus) Right() { - f.widgets[f.p.Y][f.p.X] <- false + f.Focus(false) f.p.X = (f.p.X + 1) % len(f.widgets[f.p.Y]) - f.widgets[f.p.Y][f.p.X] <- true + f.Focus(true) } func (f *Focus) Up() { - f.widgets[f.p.Y][f.p.X] <- false + f.Focus(false) if f.p.Y <= 0 { f.p.Y = len(f.widgets) - 1 } else { f.p.Y-- } f.p.X = min(f.p.X, len(f.widgets[f.p.Y])-1) - f.widgets[f.p.Y][f.p.X] <- true + f.Focus(true) } func (f *Focus) Down() { - f.widgets[f.p.Y][f.p.X] <- false + f.Focus(false) f.p.Y = (f.p.Y + 1) % len(f.widgets) f.p.X = min(f.p.X, len(f.widgets[f.p.Y])-1) - f.widgets[f.p.Y][f.p.X] <- true -} - -type Point struct { - X, Y int + f.Focus(true) } |