ItemToggle

Defines

ITEM_TOGGLE(...)
class ItemToggle : public MenuItem
#include <ItemToggle.h>

Item that allows user to toggle between ON/OFF states.

┌────────────────────────────┐
│ > T E X T : O F F          │
└────────────────────────────┘

Additionally to text this item has ON/OFF enabled state.

Public Functions

inline ItemToggle(const char *key, fptrBool callback)

Create an ItemToggle object with default values as ON and OFF.

Parameters:
  • key – key of the item

  • callback – reference to callback function

inline ItemToggle(const char *text, boolean enabled, fptrBool callback)

Construct a new Item Toggle object with an initial state and default ON/OFF texts.

Parameters:
  • text

  • enabled

  • callback

inline ItemToggle(const char *text, const char *textOn, const char *textOff, fptrBool callback)

Construct a new Item Toggle object.

Parameters:
  • text – the text of the item

  • textOn – display text when ON

  • textOff – display text when OFF

  • callback – reference to callback function

inline fptrBool getCallbackInt()

Get the integer callback function of this item.

Returns:

the integer callback function

inline boolean isOn()

Get the current state of this toggle item.

Returns:

the current state

inline void setIsOn(boolean isOn)

Set the current state of this toggle item.

Note

You need to call LcdMenu::refresh after this method to see the changes.

Parameters:

isOn – the new state

inline const char *getTextOn()
inline const char *getTextOff()
inline virtual void draw(MenuRenderer *renderer) override

Draw this menu item on specified display on current row.

Parameters:

renderer – The renderer to use for drawing.

Protected Functions

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

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 operation was successful or ignored. If the parent of item received that handle was ignored it can execute it’s own action on this command. Thus, the item always has priority in processing; if it is ignored, it is delegated to the parent element. Behaviour is very similar to Even Bubbling in JavaScript.

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

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

Returns:

true if command was successfully handled by item.

inline void toggle(MenuRenderer *renderer)

Private Members

bool enabled = false
const char *textOn = NULL
const char *textOff = NULL
fptrBool callback = NULL