ItemRangeBase

template<typename T>
class ItemRangeBase : public MenuItem
#include <ItemRangeBase.h>

Item that allows user to select a value from a range. It can be used to display all sorts of values that can be incremented or decremented. You can additionally pass a unit to be displayed after the value. e.g. “%”, “°C”, “°F” etc.

┌──────────────────────────────────┐
│ > T E X T : V A L U E U N I T    │
└──────────────────────────────────┘

Additionally to text this item has float currentValue. Has internal edit state.

Public Functions

inline ItemRangeBase(const char *text, const T min, const T max, T startingValue, void (*callback)(T), const char *unit = NULL, T step = 1, bool commitOnChange = false)

Construct a new Item Range Base object.

Parameters:
  • text – The text of the item.

  • min – The minimum value.

  • max – The maximum value.

  • startingValue – The current value.

  • callback – A pointer to the callback function to execute when this menu item is selected.

  • unit – The unit e.g. “%”, “°C”, “°F”.

  • step – The step value for increment/decrement.

  • commitOnChange – If true, the callback will be called every time the value changes.

inline bool increment()

Increments the value.

inline bool decrement()

Decrements the value.

inline bool setCurrentValue(T value)

Sets the value.

Note

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

Parameters:

value – The value to set.

Returns:

true if the value was set successfully, false otherwise.

inline T getCurrentValue()

Returns the current value.

Returns:

The current value.

virtual char *getDisplayValue() = 0

Returns the value to be displayed. If a unit is provided, it will be concatenated to the value.

Returns:

The value to be displayed.

Protected Functions

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.

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.

Protected Attributes

const T minValue
const T maxValue
T currentValue
void (*callback)(T)
const char *unit
const T step
bool commitOnChange