List

 1#include <ItemWidget.h>
 2#include <LcdMenu.h>
 3#include <MenuScreen.h>
 4#include <display/LiquidCrystal_I2CAdapter.h>
 5#include <input/KeyboardAdapter.h>
 6#include <renderer/CharacterDisplayRenderer.h>
 7#include <widget/WidgetList.h>
 8
 9#define LCD_ROWS 2
10#define LCD_COLS 16
11
12static const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
13static const uint8_t nums[] = {5, 7, 9, 12, 32};
14
15static const uint8_t NUMS_COUNT = sizeof(nums) / sizeof(nums[0]);
16static const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]);
17
18// Initialize the main menu items
19// clang-format off
20MENU_SCREEN(mainScreen, mainItems,
21    ITEM_BASIC("List demo"),
22    ITEM_WIDGET(
23        "Color",
24        [](const char* color) { Serial.println(color); },
25        WIDGET_LIST(colors, COLORS_COUNT, 0, "%s", 0, true)),
26    ITEM_WIDGET(
27        "Num",
28        [](const uint8_t num) { Serial.println(num); },
29        WIDGET_LIST(nums, NUMS_COUNT, 0, "%d", 0, true)),
30    ITEM_BASIC("Example"));
31// clang-format on
32
33// Construct the LcdMenu
34LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
35CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS);
36LcdMenu menu(renderer);
37KeyboardAdapter keyboard(&menu, &Serial);
38
39void setup() {
40    Serial.begin(9600);
41    renderer.begin();
42    menu.setScreen(mainScreen);
43}
44
45void loop() {
46    keyboard.observe();
47}