component selection enhancements

This commit is contained in:
sqshq 2019-03-21 23:47:28 -04:00
parent 59f6cda4d6
commit 55b26999db
2 changed files with 18 additions and 4 deletions

View File

@ -199,7 +199,7 @@ func (l *Layout) getSelection() *component.Component {
func (l *Layout) moveSelection(direction string) { func (l *Layout) moveSelection(direction string) {
previouslySelected := l.getSelection() previouslySelected := l.getSelection()
newlySelectedIndex := l.selection newlySelectedIndex := l.selection + 1
for i, current := range l.Components { for i, current := range l.Components {
@ -207,7 +207,7 @@ func (l *Layout) moveSelection(direction string) {
continue continue
} }
if newlySelectedIndex < 0 { if newlySelectedIndex >= len(l.Components) {
newlySelectedIndex = i newlySelectedIndex = i
} }
@ -220,18 +220,30 @@ func (l *Layout) moveSelection(direction string) {
previouslySelectedCornerPoint = component.GetRectLeftSideCenter(previouslySelected.GetRect()) previouslySelectedCornerPoint = component.GetRectLeftSideCenter(previouslySelected.GetRect())
newlySelectedCornerPoint = component.GetRectRightSideCenter(l.getComponent(newlySelectedIndex).GetRect()) newlySelectedCornerPoint = component.GetRectRightSideCenter(l.getComponent(newlySelectedIndex).GetRect())
currentCornerPoint = component.GetRectRightSideCenter(current.GetRect()) currentCornerPoint = component.GetRectRightSideCenter(current.GetRect())
if currentCornerPoint.X > previouslySelectedCornerPoint.X {
continue
}
case console.KeyRight: case console.KeyRight:
previouslySelectedCornerPoint = component.GetRectRightSideCenter(previouslySelected.GetRect()) previouslySelectedCornerPoint = component.GetRectRightSideCenter(previouslySelected.GetRect())
newlySelectedCornerPoint = component.GetRectLeftSideCenter(l.getComponent(newlySelectedIndex).GetRect()) newlySelectedCornerPoint = component.GetRectLeftSideCenter(l.getComponent(newlySelectedIndex).GetRect())
currentCornerPoint = component.GetRectLeftSideCenter(current.GetRect()) currentCornerPoint = component.GetRectLeftSideCenter(current.GetRect())
if currentCornerPoint.X < previouslySelectedCornerPoint.X {
continue
}
case console.KeyUp: case console.KeyUp:
previouslySelectedCornerPoint = component.GetRectTopSideCenter(previouslySelected.GetRect()) previouslySelectedCornerPoint = component.GetRectTopSideCenter(previouslySelected.GetRect())
newlySelectedCornerPoint = component.GetRectBottomSideCenter(l.getComponent(newlySelectedIndex).GetRect()) newlySelectedCornerPoint = component.GetRectBottomSideCenter(l.getComponent(newlySelectedIndex).GetRect())
currentCornerPoint = component.GetRectBottomSideCenter(current.GetRect()) currentCornerPoint = component.GetRectBottomSideCenter(current.GetRect())
if currentCornerPoint.Y > previouslySelectedCornerPoint.Y {
continue
}
case console.KeyDown: case console.KeyDown:
previouslySelectedCornerPoint = component.GetRectBottomSideCenter(previouslySelected.GetRect()) previouslySelectedCornerPoint = component.GetRectBottomSideCenter(previouslySelected.GetRect())
newlySelectedCornerPoint = component.GetRectTopSideCenter(l.getComponent(newlySelectedIndex).GetRect()) newlySelectedCornerPoint = component.GetRectTopSideCenter(l.getComponent(newlySelectedIndex).GetRect())
currentCornerPoint = component.GetRectTopSideCenter(current.GetRect()) currentCornerPoint = component.GetRectTopSideCenter(current.GetRect())
if currentCornerPoint.Y < previouslySelectedCornerPoint.Y {
continue
}
} }
if component.GetDistance(previouslySelectedCornerPoint, currentCornerPoint) < if component.GetDistance(previouslySelectedCornerPoint, currentCornerPoint) <
@ -240,7 +252,9 @@ func (l *Layout) moveSelection(direction string) {
} }
} }
l.selection = newlySelectedIndex if newlySelectedIndex < len(l.Components) {
l.selection = newlySelectedIndex
}
} }
func (l *Layout) Draw(buffer *ui.Buffer) { func (l *Layout) Draw(buffer *ui.Buffer) {

View File

@ -31,7 +31,7 @@ runcharts:
barcharts: barcharts:
- title: EVENTS BY STATUS - title: EVENTS BY STATUS
refresh-rate-ms: 1000 refresh-rate-ms: 1000
position: [[0, 17], [53, 12]] position: [[0, 17], [28, 12]]
scale: 0 scale: 0
items: items:
- label: NEW - label: NEW