From 55b26999db40353dedd0418e850b038d818f0797 Mon Sep 17 00:00:00 2001 From: sqshq Date: Thu, 21 Mar 2019 23:47:28 -0400 Subject: [PATCH] component selection enhancements --- component/layout/layout.go | 20 +++++++++++++++++--- config.yml | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/component/layout/layout.go b/component/layout/layout.go index d5958a6..b4c1065 100644 --- a/component/layout/layout.go +++ b/component/layout/layout.go @@ -199,7 +199,7 @@ func (l *Layout) getSelection() *component.Component { func (l *Layout) moveSelection(direction string) { previouslySelected := l.getSelection() - newlySelectedIndex := l.selection + newlySelectedIndex := l.selection + 1 for i, current := range l.Components { @@ -207,7 +207,7 @@ func (l *Layout) moveSelection(direction string) { continue } - if newlySelectedIndex < 0 { + if newlySelectedIndex >= len(l.Components) { newlySelectedIndex = i } @@ -220,18 +220,30 @@ func (l *Layout) moveSelection(direction string) { previouslySelectedCornerPoint = component.GetRectLeftSideCenter(previouslySelected.GetRect()) newlySelectedCornerPoint = component.GetRectRightSideCenter(l.getComponent(newlySelectedIndex).GetRect()) currentCornerPoint = component.GetRectRightSideCenter(current.GetRect()) + if currentCornerPoint.X > previouslySelectedCornerPoint.X { + continue + } case console.KeyRight: previouslySelectedCornerPoint = component.GetRectRightSideCenter(previouslySelected.GetRect()) newlySelectedCornerPoint = component.GetRectLeftSideCenter(l.getComponent(newlySelectedIndex).GetRect()) currentCornerPoint = component.GetRectLeftSideCenter(current.GetRect()) + if currentCornerPoint.X < previouslySelectedCornerPoint.X { + continue + } case console.KeyUp: previouslySelectedCornerPoint = component.GetRectTopSideCenter(previouslySelected.GetRect()) newlySelectedCornerPoint = component.GetRectBottomSideCenter(l.getComponent(newlySelectedIndex).GetRect()) currentCornerPoint = component.GetRectBottomSideCenter(current.GetRect()) + if currentCornerPoint.Y > previouslySelectedCornerPoint.Y { + continue + } case console.KeyDown: previouslySelectedCornerPoint = component.GetRectBottomSideCenter(previouslySelected.GetRect()) newlySelectedCornerPoint = component.GetRectTopSideCenter(l.getComponent(newlySelectedIndex).GetRect()) currentCornerPoint = component.GetRectTopSideCenter(current.GetRect()) + if currentCornerPoint.Y < previouslySelectedCornerPoint.Y { + continue + } } 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) { diff --git a/config.yml b/config.yml index 1f76807..e1b3fa8 100644 --- a/config.yml +++ b/config.yml @@ -31,7 +31,7 @@ runcharts: barcharts: - title: EVENTS BY STATUS refresh-rate-ms: 1000 - position: [[0, 17], [53, 12]] + position: [[0, 17], [28, 12]] scale: 0 items: - label: NEW