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

Update Examples to use Widgets #260

Merged
merged 17 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
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
39 changes: 12 additions & 27 deletions examples/List/List.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
#include <ItemList.h>
#include <ItemWidget.h>
#include <LcdMenu.h>
#include <MenuScreen.h>
#include <display/LiquidCrystal_I2CAdapter.h>
#include <input/KeyboardAdapter.h>
#include <renderer/CharacterDisplayRenderer.h>
#include <widget/WidgetList.h>

#define LCD_ROWS 2
#define LCD_COLS 16

// Declare the callbacks
void colorsCallback(uint8_t pos);
void numsCallback(uint8_t pos);

// Declare the array
extern String colors[];
// Initialize the array
String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};

// Declare the array
extern String nums[];
// Initialize the array
String nums[] = {"5", "7", "9", "12", "32"};
const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
const char* nums[] = {"5", "7", "9", "12", "32"};

forntoh marked this conversation as resolved.
Show resolved Hide resolved
// Initialize the main menu items
// clang-format off
MENU_SCREEN(mainScreen, mainItems,
ITEM_BASIC("List demo"),
ITEM_STRING_LIST("Col", colors, 8, colorsCallback),
ITEM_STRING_LIST("Num", nums, 5, numsCallback),
ITEM_WIDGET(
"Color",
[](const char* color) { Serial.println(color); },
WIDGET_LIST(colors, 8, 0, "%s")),
ITEM_WIDGET(
"Num",
[](const char* num) { Serial.println(num); },
WIDGET_LIST(nums, 5, 0, "%s")),
ITEM_BASIC("Example"));
forntoh marked this conversation as resolved.
Show resolved Hide resolved
// clang-format on

Expand All @@ -45,15 +41,4 @@ void setup() {

void loop() {
keyboard.observe();
}

// Define the callbacks
void colorsCallback(uint8_t pos) {
// do something with the index
Serial.println(colors[pos]);
}

void numsCallback(uint8_t pos) {
// do something with the index
Serial.println(nums[pos]);
}
Loading