Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page_Up Page_Down for lilka::menu #64

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions sdk/lib/lilka/src/lilka/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,31 @@ void Menu::setCursor(int16_t cursor) {

void Menu::update() {
State state = controller.getState();

auto cursorLastPos = cursor;
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 - MENU_HEIGHT) <= 0 ? cursor = 0 : (cursor - MENU_HEIGHT);

} else if (state.right.justPressed) {
// Scroll PageDown
if (cursor == items.size() - 1) cursor = 0;
else cursor = (cursor + MENU_HEIGHT) >= items.size() - 1 ? items.size() - 1 : (cursor + MENU_HEIGHT);
}

if (cursorLastPos != cursor) lastCursorMove = millis();
if (cursor < scroll) {
scroll = cursor;
// cursorY = cursor * 24 + 96 - 20;
Expand Down
Loading