This class contains everything needed to create and manage a menu and display it on an OLED.
More...
#include <menu.h>
This class contains everything needed to create and manage a menu and display it on an OLED.
§ Controller()
Menu::Controller::Controller |
( |
OLED & |
oled, |
|
|
uint8_t |
num_lines |
|
) |
| |
Sets up the menu.
- Parameters
-
oled | This is the oled object the menu should use for display. |
num_lines | This is the number of lines that the display should use when displaying the menu. |
§ AddMenu()
void Menu::Controller::AddMenu |
( |
Item ** |
items, |
|
|
uint8_t |
length |
|
) |
| |
Adds a sub menu to the currently selected item. Assumes an item is selected. Internally it creates a menu, and invokes AddMenuItem to add the items. Thus you could create an empty menu and add items using AddMenuItem instead. Do NOT use this to create the root menu; it is already made. Use AddMenuItem to add items to it.
- Parameters
-
items | An array of items to add to the newly created menu. |
length | The length of the array. |
§ AddMenuItem() [1/2]
void Menu::Controller::AddMenuItem |
( |
Item * |
item | ) |
|
Adds the item after the currently selected item. If no item is selected, the item is inserted as the first item.
- Parameters
-
§ AddMenuItem() [2/2]
void Menu::Controller::AddMenuItem |
( |
Item * |
item, |
|
|
uint8_t |
index |
|
) |
| |
Adds the item at the specified index. Thus index 0 will place it as the first element in the menu.
- Parameters
-
item | The item to insert. |
index | The index the inserted item should have. |
§ AddMenuItems()
void Menu::Controller::AddMenuItems |
( |
Item ** |
items, |
|
|
uint8_t |
length |
|
) |
| |
Internally invokes AddMenuItem to add the items. Adds to the selected item.
- Parameters
-
items | An array of items to add to the menu. |
length | The length of the array. |
§ ControlEnterSubMenu() [1/2]
void Menu::Controller::ControlEnterSubMenu |
( |
| ) |
|
Enters the sub menu the selected item links to (Item::action). Assumes the current item has a sub menu...
§ ControlEnterSubMenu() [2/2]
void Menu::Controller::ControlEnterSubMenu |
( |
uint8_t |
index | ) |
|
Same as ControlEnterSubMenu, except accesses the menu item with index index instead of the currently selected item.
- Parameters
-
index | The index of the item whose sub menu will be entered. |
§ ControlGoToItem()
void Menu::Controller::ControlGoToItem |
( |
uint8_t |
index | ) |
|
Sets the item to be controlled to the item with index index of the selected menu.
- Parameters
-
index | The index of the item to be selected. |
§ ControlGoToParent()
void Menu::Controller::ControlGoToParent |
( |
| ) |
|
Sets the menu to be controlled to the parent of the current menu. Assumes the currently selected menu isn't the root menu.
§ ControlGoToRoot()
void Menu::Controller::ControlGoToRoot |
( |
| ) |
|
Sets the menu to be controlled to root. The item selected will be none.
§ ExecuteItem()
void Menu::Controller::ExecuteItem |
( |
| ) |
|
Executes the currently selected items action (calling cb or entering sub menu). Use this as a handler for navigating the menu (for instance "clicking" an item).
§ GetMenuLength()
uint8_t Menu::Controller::GetMenuLength |
( |
Menu * |
menu | ) |
|
|
private |
This calculates the total length of a menu. It is used to for instance figure out what will be the first displayed menu option so that you cannot try to navigate below the menu.
- Parameters
-
menu | The menu to calculate the length of. |
- Returns
- The menu length.
§ GoToItem()
void Menu::Controller::GoToItem |
( |
uint8_t |
index | ) |
|
|
private |
Sets the currently selected navigate item to the item with this item. This will only update the item, not the navigate index. This is because this method is only used to select the item so it can be rendered or its action executed.
- Parameters
-
index | The index of the item to be selected. |
§ GoToMenu()
void Menu::Controller::GoToMenu |
( |
Menu * |
menu | ) |
|
Sets the specified menu as the current navigate menu. Thus calling this and rendering the menu will go to this menu.
- Parameters
-
§ GoToNextItem()
bool Menu::Controller::GoToNextItem |
( |
| ) |
|
|
private |
This will try to set the next item as the navigate item. It does not update the navigate index.
- Returns
- Whether there was another menu item.
§ GoToParent()
void Menu::Controller::GoToParent |
( |
| ) |
|
Sets the navigation to the parent menu. Used to go one menu up. Use this as a handler for navigating one level up in the menu.
§ GoToRoot()
void Menu::Controller::GoToRoot |
( |
| ) |
|
Sets the currently selected navigate item to the root. Also updates the navigate index and selected index. This is used to return the navigation to the root. Use this as a handler for navigating to the root in the menu.
§ Initialize()
void Menu::Controller::Initialize |
( |
OLED & |
oled, |
|
|
uint8_t |
num_lines |
|
) |
| |
Sets up the menu.
- Parameters
-
oled | This is the oled object the menu should use for display. |
num_lines | This is the number of lines that the display should use when displaying the menu. |
§ Render()
void Menu::Controller::Render |
( |
| ) |
|
Renders the menu to the screen. A normal use case would be to create the menu, add menus to it. Then bind listeners to the menu controls (e.g. buttons or joystick) and render the menu when you want to display it.
§ SelectNext()
void Menu::Controller::SelectNext |
( |
| ) |
|
Updates the selected index. If there is no next item it will not update anything. Use this as a handler for navigating downwards in the menu.
§ SelectPrevious()
void Menu::Controller::SelectPrevious |
( |
| ) |
|
Updates the selected index. If there is no previous item it will not update anything. Use this as a handler for navigating upwards in the menu.
§ current_index_navigate
uint8_t Menu::Controller::current_index_navigate = 0 |
|
private |
This stores the index of the first menu item to be displayed on screen. This will change as the user navigates downwards on a menu higher than the number of lines on the screen. When rendering it will be calculated such that the cursor, if possible, does not end up on the first or last lines of the menu. This ensures the user always sees the next item to be selected before it is selected.
§ current_index_selected
uint8_t Menu::Controller::current_index_selected = 0 |
|
private |
This stores the index of the currently selected menu item.
§ current_item_control
Item* Menu::Controller::current_item_control = nullptr |
|
private |
This stores the current item to be controlled. Should point to an item inside of current_menu_control.
§ current_item_navigate
Item* Menu::Controller::current_item_navigate = nullptr |
|
private |
This stores the item needed to for instance render the menu or execute the action of the item.
§ current_menu_control
Menu* Menu::Controller::current_menu_control = nullptr |
|
private |
When administrating the menu (control), you use methods to navigate to the item you want to change (e.g. add a menu item). This stores the menu to be controlled.
§ current_menu_navigate
Menu* Menu::Controller::current_menu_navigate = nullptr |
|
private |
When using the menu (navigate), you use methods to navigate. This stores the menu you are navigating (on screen).
§ num_lines
uint8_t Menu::Controller::num_lines |
|
private |
Specifies how many lines the menu should use (always uses the whole screen).
§ oled
OLED* Menu::Controller::oled = nullptr |
|
private |
Pointer to the oled object.
§ root
Menu* Menu::Controller::root |
|
private |
This is the root menu, in other words the first/main menu.
The documentation for this class was generated from the following files:
- lib/menu/menu.h
- lib/menu/menu.cpp