In the previous example, we created a simple list for user selection. But what if the options aren't descriptive enough? Thatโs where ShellminatorListDetailed comes in!
This class works almost exactly like ShellminatorList, with one key difference: each option can have an additional description. This makes it easier for users to understand their choices.
Just like before, start by creating the list of choices:
const char* listOptions[] = {
"Aladdin",
"The Iron Giant",
"Treasure Planet"
};
A short description to guide the user:
const char* listText = "Choose a movie to watch:";
Just like with a regular list, you need a function to handle the user's selection:
void listCallback(
const char* optionsList[],
int listSize,
int selected,
ShellminatorScreen*);
This is an abstract object for graphics element creation.
Now comes the trick! Create a second list that contains extra details for each option. Make sure the order matches the main list!
const char* listDetails[] = {
"Released: November 25, 1992",
"Released: July 31, 1999",
"Released: November 27, 2002"
};
Finally, use the constructor to connect the options with their descriptions:
Aside from adding descriptions, everything else works the same as with ShellminatorList! This is a great way to provide more context while keeping the selection process simple.
Live Demo
Whole Code
const char* listOptions[] = {
"Aladdin",
"The Iron Giant",
"Treasure Planet"
};
const char* listDetails[] = {
"1992. November 25.",
"1999. June 31.",
"2002. November 27."
};
const char* listText = "Choose a movie to watch:";
void listCallback(
const char* optionsList[],
int listSize,
int selected,
ShellminatorScreen* );
void setup(){
Serial.begin(115200);
shell.clear();
Serial.println( "Program Start!" );
movieList.attachCallback( listCallback );
shell.begin( "arnold" );
shell.beginScreen( &movieList );
}
void loop(){
shell.update();
}
void listCallback(
const char* optionsList[],
int listSize,
int selected,
ShellminatorScreen* screen ){
parent = screen -> getParent();
if( parent == NULL ){
return;
}
if( selected == 0 ){
notification.
setText(
"Good choice, you can watch Aladdin here:\nhttps://www.imdb.com/title/tt0103639/" );
}
else if( selected == 1 ){
notification.
setText(
"Good choice, you can watch The Iron Giant here:\nhttps://www.imdb.com/title/tt0129167/" );
}
else{
notification.
setText(
"Good choice, you can watch the Treasure Planet here:\nhttps://www.imdb.com/title/tt0133240/" );
}
parent -> swapScreen( ¬ification );
}
void setText(const char *text_p)