ItemInput

Defines

ITEM_INPUT(...)
class ItemInput : public MenuItem
#include <ItemInput.h>

Item that allows user to input string information.

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

Additionally to text this item has string value. Has internal edit state. Value area is scrollable, see view.

Subclassed by ItemInputCharset

Public Functions

inline ItemInput(const char *text, char *value, fptrStr callback)

Construct a new ItemInput object with an initial value.

Parameters:
  • text – The text to display for the item.

  • value – The initial value for the input.

  • callback – A reference to the callback function to be invoked when the input is submitted.

inline ItemInput(const char *text, fptrStr callback)

Construct a new ItemInput object with no initial value.

Parameters:
  • text – The text to display for the item.

  • callback – A reference to the callback function to be invoked when the input is submitted.

inline char *getValue()

Get the current input value for this item.

Returns:

The current input value as a string.

inline bool setValue(char *value)

Set the input value for this item.

Note

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

Parameters:

value – The new input value.

Returns:

true if the value was changed, false otherwise.

inline fptrStr getCallbackStr()

Get the callback function for this item.

Returns:

The function pointer to the callback function.

Protected Functions

inline uint8_t getViewSize(MenuRenderer *renderer) const

The number of visible characters.

         visible area
       ┌───────────────┐
X X X X│X X X X █ X X X│X X
       ├───────────────┤
       │<── viewSize ─>│

Effectively const, but initialized lately when renderer is injected.

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.

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

Moves the cursor to the right within the input value.

inline void backspace(MenuRenderer *renderer)

Handles the backspace action for the input field.

inline void typeChar(MenuRenderer *renderer, const unsigned char character)

Types a character into the current input value at the cursor position.

This function inserts a character into the value string at the current cursor position. If the cursor is within the current length of the string, the string is split and the character is inserted in between. If the cursor is at the end of the string, the character is appended. The cursor is then incremented, and the view is adjusted if necessary. Finally, the renderer is updated and the blinker position is reset.

Parameters:
  • renderer – Pointer to the MenuRenderer object used for rendering.

  • character – The character to be typed into the input value.

inline void clear(MenuRenderer *renderer)

Clear the value of the input field.

Protected Attributes

char *value

String value of item.

uint8_t view = 0

The index of first visible character.

         visible area
       ┌───────────────┐
X X X X│X X X X █ X X X│X X
       └───────────────┘
  view--^

Is moved when cursor crosses the borders of visible area. When length of value < viewSize this index should be 0.

uint8_t cursor

Current index of the char to be edited.

         visible area
       ┌───────────────┐
X X X X│X X X X █ X X X│X X
       └───────────────┘
        cursor--^

When left or right then this position will be moved over the string accordingly. When type then new character will be appended on this position. When backspace then one character before will be removed. Always in range [view, view + viewSize - 1].

fptrStr callback

The call back that will be executed when edit will be finished. First parameter will be a value string.