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

Make lilka::Menu component avaliable for reuse #51

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 23 additions & 1 deletion sdk/lib/lilka/src/lilka/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,29 @@ bool Menu::isFinished() {
int16_t Menu::getCursor() {
return cursor;
}

bool Menu::setItem(int16_t index, String title, const menu_icon_t* icon, uint16_t color, String postfix) {
if (index > items.size() - 1) {
return false;
} else {
items[index].title = title;
items[index].icon = icon;
items[index].color = color;
items[index].postfix = postfix;
return true;
}
}
bool Menu::getItem(int16_t index, MenuItem* menuItem) {
if ((menuItem == NULL) || index > items.size() - 1) {
return false;
} else {
memcpy(menuItem, &(items[index]), sizeof(MenuItem));
return true;
}
}
void Menu::clearItems() {
setCursor(0);
items.clear();
}
void Menu::addActivationButton(Button activationButton) {
activationButtons.push_back(activationButton);
}
Expand Down
16 changes: 16 additions & 0 deletions sdk/lib/lilka/src/lilka/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,24 @@ class Menu {
///
/// Якщо пункт обрано (користувач натиснув кнопку "A"), повертається ``true``, інакше ``false``. Після виклику цієї функції пункт перестає бути обраним.
bool isFinished();
/// Змінити пункт меню
/// @param index Індекс пункту.
/// @param title Заголовок пункту.
/// @param icon Іконка пункту (масив з ``uint16_t`` розміром 576 елементів, який представляє 24x24px зображення). За замовчуванням ``0`` (відсутня іконка).
/// @param color Колір пункту. За замовчуванням ``0`` (стандартний колір).
/// @param postfix Текст, який додається після заголовка пункту і вирівнюється до правого краю меню.
///
/// Повертає значення true, якщо пункт було змінено
bool setItem(int16_t index, String title, const menu_icon_t* icon = 0, uint16_t color = 0, String postfix = "");
/// Отримати пункт меню
/// @param index Індекс пункту.
/// @param menuItem Вказівник на lilka::MenuItem куди буде скопійовано пункт
/// Повертає true у разі успіху
bool getItem(int16_t index, MenuItem* menuItem);
/// Отримати індекс обраного пункту меню.
int16_t getCursor();
/// Очистити меню і зробити його доступним для повторного використання
void clearItems();
/// Дозволити вибір пункту меню за допомогою інших кнопок.
///
/// За замовчуванням вибір пункту можливий тільки за допомогою кнопки "A". Після виклику цієї функції можна вибирати пункт за допомогою додаткових кнопок.
Expand Down
Loading