BaseWidget

Defines

ITEM_DRAW_BUFFER_SIZE
class BaseWidget
#include <BaseWidget.h>

Base class for widgets.

Subclassed by BaseWidgetValue< bool >, BaseWidgetValue< T >

Public Functions

virtual ~BaseWidget() = default

Protected Functions

inline BaseWidget(const uint8_t cursorOffset = 0)
virtual bool process(LcdMenu *menu, unsigned char command) = 0

Process a command decoded in 1 byte. It can be a printable character or a control command like ENTER or LEFT. Return value is used to determine if the operation was successful or ignored. If the item’s handler ignores the command, the parent can execute its own action on this command. Thus, the item always has priority in processing; if it ignores a command, the command is delegated to the parent element. This behavior is similar to event delegation, where an event is handled by the most specific handler first, and if not handled, it is passed up to more general handlers.

Parameters:
  • menu – the owner menu of the item, can be used to retrieve required objects, such as MenuRenderer or MenuScreen

  • command – the character command, can be a printable character or a control command

Returns:

true if the command was successfully handled by the item.

virtual uint8_t draw(char *buffer, const uint8_t start = 0) = 0

Draw the widget into specified buffer.

Parameters:
  • buffer – the buffer where widget will be drawn

  • start – the index where to start drawing in the buffer

Returns:

the number of characters written into the buffer

Protected Attributes

const uint8_t cursorOffset

This member variable specifies the position where the cursor should be placed within the widget’s text. For example, if the text format is “%dms” (20ms) and the user wants the cursor to be placed at the position of “%d”, they would set cursorOffset to 2. By default, the cursor is placed at the end of the resulting text.

Friends

friend class ItemWidget
friend class BaseItemManyWidgets