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())
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) <
component.GetDistance(previouslySelectedCornerPoint, newlySelectedCornerPoint) {
switch direction {
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
}
}
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) {
l.selection = newlySelectedIndex

View File

@ -122,7 +122,7 @@ func (m *Menu) Draw(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"
resumeText := "<ESC> to resume"