BaseItemManyWidgets

class BaseItemManyWidgets : public MenuItem

Subclassed by ItemWidget< Ts >

Public Functions

inline BaseItemManyWidgets(const char *text, BaseWidget **widgets, const uint8_t size, uint8_t activeWidget = 0)
inline uint8_t getActiveWidget() const
inline void setActiveWidget(const uint8_t activeWidget)
inline virtual ~BaseItemManyWidgets()

Protected Functions

virtual void handleCommit() = 0
inline void reset()

Reset the active widget to the first widget.

inline virtual void draw(MenuRenderer *renderer) override

Draws the menu item using the provided renderer.

This function is responsible for rendering the menu item and its associated widgets. It iterates through each widget, drawing them into a buffer, and then uses the renderer to display the combined result. If the renderer is in edit mode, it also handles the cursor positioning for editing.

The function performs the following steps:

  1. Initializes a buffer to hold the drawn content and variables for indexing and cursor positioning.

  2. Iterates through each widget, drawing it into the buffer and updating the index.

  3. If the active widget is being edited, it draws the item using the renderer and calculates the cursor position.

  4. Draws the final item using the renderer.

  5. If in edit mode, moves the cursor to the appropriate position for editing.

Parameters:

renderer – A pointer to the MenuRenderer object used for drawing the item.

inline virtual bool process(LcdMenu *menu, const unsigned char command) override

Processes a command for the active widget in the menu.

This function handles the processing of commands for the active widget in the menu. It first attempts to process the command using the active widget. If the widget processes the command successfully, it redraws the menu and returns true.

If the renderer is in edit mode, it handles navigation commands (ENTER, RIGHT, LEFT, BACK) to navigate through the widgets or exit edit mode.

When the ENTER command is received while the renderer is in edit mode and the active widget is not the last widget, it moves to the next widget. If the active widget is the last widget, it exits edit mode and calls the handleCommit function to commit the changes.

If the renderer is not in edit mode and the ENTER command is received, it sets the renderer to edit mode, redraws the menu, and draws a blinker.

Parameters:
  • menu – Pointer to the LcdMenu object.

  • command – The command to be processed.

Returns:

true if the command was processed successfully, false otherwise.

inline void left(MenuRenderer *renderer)
inline void right(MenuRenderer *renderer)
inline void back(MenuRenderer *renderer)

Protected Attributes

BaseWidget **widgets = nullptr
const uint8_t size = 0
uint8_t activeWidget = 0