Skip to content

Commit

Permalink
Added Page Based scroll through menu
Browse files Browse the repository at this point in the history
  • Loading branch information
frostmorn committed Mar 22, 2024
1 parent 97b0683 commit 95938e8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions sdk/lib/lilka/src/lilka/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,45 @@ void Menu::setCursor(int16_t cursor) {
}

void Menu::update() {
// TODO: Value here depends on a screen size
#define PAGE_LEN 3
State state = controller.getState();

lastCursorMove = millis();
if (state.up.justPressed) {
// Move cursor up
if (cursor == 0) {
cursor = items.size() - 1;
} else {
cursor--;
}
lastCursorMove = millis();
} else if (state.down.justPressed) {
// Move cursor down
cursor++;
if (cursor >= items.size()) {
cursor = 0;
}
lastCursorMove = millis();
} else if (state.left.justPressed) {
// Scroll PageUp
if (cursor == 0) {
cursor = items.size - 1;
} else {
cursor = cursor - PAGE_LEN;
if (cursor <= 0) {
cursor = 0;
}
}
} else if (state.right.justPressed) {
// Scroll PageDown
if (cursor == items.size - 1) {
cursor = 0;
} else {
cursor = cursor + PAGE_LEN;
if (cursor > items.size()) {
cursor = items.size();
}
}
}

#undef PAGE_LEN
if (cursor < scroll) {
scroll = cursor;
// cursorY = cursor * 24 + 96 - 20;
Expand Down

0 comments on commit 95938e8

Please sign in to comment.