component selection enhancements

This commit is contained in:
sqshq 2019-04-16 23:55:23 -04:00
parent 8f2cf3ce5a
commit 14aaab240f
2 changed files with 18 additions and 16 deletions

View File

@ -232,37 +232,39 @@ 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) < switch direction {
component.GetDistance(previouslySelectedCornerPoint, newlySelectedCornerPoint) { case console.KeyLeft:
fallthrough
case console.KeyRight:
if ui.AbsInt(currentCornerPoint.X-previouslySelectedCornerPoint.X) <= ui.AbsInt(newlySelectedCornerPoint.X-previouslySelectedCornerPoint.X) {
if ui.AbsInt(currentCornerPoint.Y-previouslySelectedCornerPoint.Y) <= ui.AbsInt(newlySelectedCornerPoint.Y-previouslySelectedCornerPoint.Y) {
newlySelectedIndex = i newlySelectedIndex = i
} }
} }
case console.KeyUp:
fallthrough
case console.KeyDown:
if ui.AbsInt(currentCornerPoint.Y-previouslySelectedCornerPoint.Y) <= ui.AbsInt(newlySelectedCornerPoint.Y-previouslySelectedCornerPoint.Y) {
if ui.AbsInt(currentCornerPoint.X-previouslySelectedCornerPoint.X) <= ui.AbsInt(newlySelectedCornerPoint.X-previouslySelectedCornerPoint.X) {
newlySelectedIndex = i
}
}
}
}
if newlySelectedIndex < len(l.Components) { if newlySelectedIndex < len(l.Components) {
l.selection = newlySelectedIndex l.selection = newlySelectedIndex

View File

@ -122,7 +122,7 @@ func (m *Menu) Draw(buffer *ui.Buffer) {
func (m *Menu) renderHighlight(buffer *ui.Buffer) { func (m *Menu) renderHighlight(buffer *ui.Buffer) {
arrowsText := "Use mouse or arrows for selection" arrowsText := "Use mouse or keyboard for selection"
optionsText := "<ENTER> to view options" optionsText := "<ENTER> to view options"
resumeText := "<ESC> to resume" resumeText := "<ESC> to resume"