A menu system for TFTs that uses the TFT_eSPI library
A one-level menu that provides:
- A title
- Items
- The number of items can exceed the number of items that can be displayed at once.
- The display will scroll as the you move the current selection up and down.
- Arrows will indicate if there are more items to see.
- Items can be regular, disabled or selected. Disabled items will never be selected.
- Both the title and items can have a border, label padding and (obviously?) a label.
- Separate color palettes can be defined for the title and the items, and for the border, padding, the label and for selected, unselected and disabled items.
- Separate fonts can be specified for the title and the menu items.
- Labels are clipped to the space available to draw them.
Use as follows:
- Create an instance of eSPI_Menu, passing in a pointer to a TFT_eSPI instance. This could be a sprite.
- Configure the title spec and the item spec to provide things such as:
- Selected, unselected and disabled palettes for borders, padding and text.
- Left, right, top and bottom border sizes and padding sizes.
- Font.
- Add items, specifying which item will be selected when the menu is drawn.
- Call show(). If you're using a sprite, remember to push it.
- Provide some means for the user to navigate the menu, you are responsible for calling the up() and down() methods (and pushing the menu if you're drawing into a sprite), but the menu class will make sure that:
- You can't go beyond the top and bottom of the menu.
- Scrolling the menu to fit the selected item in the space available,
- Skipping disabled items, drawing the scroll arrows if any.
- Provide some means for the user to exit the menu and for your code to figure out if a selection was made. I use a button click for making a selection and a long press for just exiting without a selection.
- Exiting the menu doesn't mean much, it won't be undrawn automatically, it is up to you to make it invisible somehow.
- You can retrieve whatever item is/was selected either by item number or by item label.
- If you re-use the menu for different contents, or you change the contents, call reset() before you modify it and then fully re-initialize the contents.