diff options
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) } |