LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI

Single-line text-entry widget. More...

#include <text_entry.h>

Public Member Functions

 LcdGfxTextEntry (char *buffer, uint8_t maxLen, const NanoRect &rect, const char *charset=" ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-_")
 Creates a text-entry widget bound to the user's buffer. More...
 
void up ()
 Cycles the character at the cursor forward through the charset.
 
void down ()
 Cycles the character at the cursor backward through the charset.
 
void left ()
 Moves the cursor one cell to the left, clamped at 0.
 
void right ()
 Moves the cursor one cell to the right, clamped at maxLen - 1.
 
void setCursor (uint8_t cursor)
 Sets the cursor position. More...
 
uint8_t getCursor () const
 Returns the current cursor position.
 
const char * getText () const
 Returns the underlying NUL-terminated text buffer.
 
uint8_t getMaxLen () const
 Returns the maximum number of editable cells.
 
template<typename D >
void show (D &d)
 Renders the widget to the display. More...
 
template<typename D >
void updateSize (D &d)
 Auto-sizes the widget rectangle from the active font if a zero rect was supplied to the constructor.
 
const NanoRectgetRect () const
 Returns the rectangle occupied by the widget.
 

Detailed Description

Single-line text-entry widget.

Typical embedded UX where the user moves a cursor along a fixed buffer and cycles the character at the cursor through a charset with up/down. The widget operates on a single-byte charset (ASCII by default); each cell holds exactly one byte. UTF-8 strings can still be displayed if the active font's secondary table covers the codepoints, but each cell is one byte — the charset itself must therefore be single-byte. The default charset is uppercase A-Z, digits and a few punctuation marks plus a leading space (used as the "blank" character).

Key bindings:

  • up() : cycle char at cursor forward through charset
  • down() : cycle char at cursor backward
  • left() : move cursor one cell left (clamped at 0)
  • right() : move cursor one cell right (clamped at maxLen-1)

Definition at line 60 of file text_entry.h.

Constructor & Destructor Documentation

◆ LcdGfxTextEntry()

LcdGfxTextEntry::LcdGfxTextEntry ( char *  buffer,
uint8_t  maxLen,
const NanoRect rect,
const char *  charset = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-_" 
)

Creates a text-entry widget bound to the user's buffer.

Parameters
bufferuser-owned NUL-terminated buffer to edit. Must have at least maxLen + 1 bytes available. On construction, every byte up to and including maxLen is initialised to charset[0] (the first character of the charset, which acts as the "blank" placeholder), then a NUL is written at offset maxLen.
maxLenmaximum number of editable cells (excludes the trailing NUL).
rectscreen area for the widget. Pass an empty rect to have show() auto-size from the active font.
charsetNUL-terminated single-byte charset. The first character is treated as the blank/space. Defaults to space + A-Z + 0-9 + a small punctuation block.

Member Function Documentation

◆ setCursor()

void LcdGfxTextEntry::setCursor ( uint8_t  cursor)

Sets the cursor position.

Clamped to [0, maxLen - 1].

◆ show()

template<typename D >
void LcdGfxTextEntry::show ( D &  d)
inline

Renders the widget to the display.

Draws the buffer left-to-right inside the widget rectangle and underlines the cursor cell so the user can see which cell is being edited.

Parameters
ddisplay object

Definition at line 143 of file text_entry.h.


The documentation for this class was generated from the following file: