WidgetList

Functions

template<typename T>
inline BaseWidgetValue<uint8_t> *WIDGET_LIST(const std::vector<T> &values, const uint8_t activePosition = 0, const char *format = "%s", const uint8_t cursorOffset = 0, const bool cycle = false, void (*callback)(const uint8_t&) = nullptr)

Function to create a new WidgetList<T> instance.

Template Parameters:

T – The type of the value.

Parameters:
  • values – The list of values to choose from.

  • activePosition – The initial active position in the list (default: 0).

  • format – The format of the value (default: “%s”).

  • cursorOffset – The cursor offset (default: 0).

  • cycle – Whether to cycle through the list (default: false).

  • callback – The callback function to call when the value changes (default: nullptr).

template<typename T>
inline BaseWidgetValue<Ref<uint8_t>> *WIDGET_LIST_REF(const std::vector<T> &values, uint8_t &activePosition, const char *format = "%s", const uint8_t cursorOffset = 0, const bool cycle = false, void (*callback)(const Ref<uint8_t>&) = nullptr)

Function to create a new WidgetList<T> instance.

Note

Make sure that value reference is not deallocated earlier than this widget.

Template Parameters:

T – The type of the value.

Parameters:
  • values – The list of values to choose from.

  • activePosition – Initial active position in the list (this value is passed by reference, so it can be updated externally).

  • format – The format of the value (default: “%s”).

  • cursorOffset – The cursor offset (default: 0).

  • cycle – Whether to cycle through the list (default: false).

  • callback – The callback function to call when the value changes (default: nullptr), parameter of callback will be Ref<uint8_t>

template<typename T, typename V = uint8_t>
class WidgetList : public BaseWidgetValue<uint8_t>
#include <WidgetList.h>

Widget that allows a user to select a value from a list. Manages a value within a specified list, allowing cycling through values.

NOTE: Despite the fact that the class has template type <T> the base Widget will have type <uint8_t>. It reflects that the value of this widget is index in the specified list, not value itself. Also be aware that the ItemWidget’s callback should have correct type <uint8_t>, not <T>.

Template Parameters:
  • T – the type of value

  • V – the type of stored value, the type should be fully compatible with uint8_t type, meaning all arithmetic operations, cast, assignment should be supported for type V. For example, T = char*, V = Ref<uint8_t>.

Public Functions

inline WidgetList(const std::vector<T> &values, const V activePosition, const char *format, const uint8_t cursorOffset, const bool cycle, void (*callback)(const V&))

Protected Functions

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

Process command.

Handle commands:

  • UP - increment value and trigger callback;

  • DOWN - decrement value and trigger callback;

inline void updateValue(const __FlashStringHelper *action)
inline virtual uint8_t draw(char *buffer, const uint8_t start) override

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

inline bool nextValue()
inline bool previousValue()
inline virtual void startEdit() override
inline virtual void cancelEdit() override

Protected Attributes

const bool cycle
const std::vector<T> &values
V originalValue