Starter select - Implement up and down offset navigation (#1480)

* Handle offset up and down navigation

* add comments
This commit is contained in:
Ronn 2024-05-31 00:27:53 +02:00 committed by GitHub
parent 7ac6016df3
commit 3f6e43a12d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1339,11 +1339,27 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
case Button.UP:
if (row) {
success = this.setCursor(this.cursor - 9);
} else {
// when strictly opposite starter based on rows length
// does not exits, set cursor on the second to last row
if (this.cursor + (rows - 1) * 9 > genStarters - 1) {
success = this.setCursor(this.cursor + (rows - 2) * 9);
} else {
success = this.setCursor(this.cursor + (rows - 1) * 9);
}
}
break;
case Button.DOWN:
if (row < rows - 2 || (row < rows - 1 && this.cursor % 9 <= (genStarters - 1) % 9)) {
success = this.setCursor(this.cursor + 9);
} else {
// if there is no starter below while being on the second to
// last row, adjust cursor position with one line less
if (row === rows - 2 && this.cursor + 9 > genStarters - 1) {
success = this.setCursor(this.cursor - (rows - 2) * 9);
} else {
success = this.setCursor(this.cursor - (rows - 1) * 9);
}
}
break;
case Button.LEFT: