Skip to content

Commit

Permalink
sdk: add menu item postfix arg (closes #36) (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson authored Mar 22, 2024
1 parent 2dd5e19 commit 05f8747
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion sdk/lib/lilka/src/lilka/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ Menu::~Menu() {
delete iconCanvas;
}

void Menu::addItem(String title, const menu_icon_t* icon, uint16_t color) {
void Menu::addItem(String title, const menu_icon_t* icon, uint16_t color, String postfix) {
items.push_back({
.title = title,
.icon = icon,
.color = color,
.postfix = postfix,
});
}

Expand Down Expand Up @@ -146,6 +147,18 @@ void Menu::draw(Arduino_GFX* canvas) {
}
// gfx->print(i == cursor ? "> " : " ");
canvas->println(items[i].title);

if (items[i].postfix.length()) {
// Calculate postfix width
int16_t x1, y1;
uint16_t w, h;
canvas->getTextBounds(items[i].postfix, 0, 0, &x1, &y1, &w, &h);
(void)x1;
(void)y1;
(void)h;
canvas->setCursor(canvas->width() - w - 8, 80 + screenI * 24);
canvas->println(items[i].postfix);
}
}

// Draw scrollbar
Expand Down
4 changes: 3 additions & 1 deletion sdk/lib/lilka/src/lilka/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
String title;
const menu_icon_t* icon;
uint16_t color;
String postfix;
} MenuItem;

/// Клас для відображення меню.
Expand Down Expand Up @@ -55,7 +56,8 @@ class Menu {
/// @param title Заголовок пункту.
/// @param icon Іконка пункту (масив з ``uint16_t`` розміром 576 елементів, який представляє 24x24px зображення). За замовчуванням ``0`` (відсутня іконка).
/// @param color Колір пункту. За замовчуванням ``0`` (стандартний колір).
void addItem(String title, const menu_icon_t* icon = 0, uint16_t color = 0);
/// @param postfix Текст, який додається після заголовка пункту і вирівнюється до правого краю меню.
void addItem(String title, const menu_icon_t* icon = 0, uint16_t color = 0, String postfix = "");
/// Встановити курсор на пункт меню.
/// @param cursor Індекс пункту меню.
void setCursor(int16_t cursor);
Expand Down

0 comments on commit 05f8747

Please sign in to comment.