🧑💻 Extend LCD string substitution (#24278)
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// TODO: Make AVR-compatible with separate ROM / RAM string methods
|
||||
|
||||
#include "../../fontutils.h"
|
||||
#include "../../marlinui.h"
|
||||
|
||||
@@ -41,14 +43,14 @@ class DWIN_String {
|
||||
//static glyph_t *glyphs[256];
|
||||
//static font_t *font_header;
|
||||
|
||||
static uint8_t data[MAX_STRING_LENGTH + 1];
|
||||
static char data[MAX_STRING_LENGTH + 1];
|
||||
static uint16_t span; // in pixels
|
||||
static uint8_t len; // in characters
|
||||
|
||||
static void add_character(const uint8_t character);
|
||||
static void eol() { data[len] = 0x00; }
|
||||
static void add_character(const char character);
|
||||
static void eol() { data[length] = 0x00; }
|
||||
|
||||
public:
|
||||
static uint8_t length; // in characters
|
||||
//static void set_font(const uint8_t *font);
|
||||
//static void add_glyphs(const uint8_t *font);
|
||||
|
||||
@@ -57,34 +59,71 @@ class DWIN_String {
|
||||
//static glyph_t *glyph(uint8_t character) { return glyphs[character] ?: glyphs[0x3F]; } /* Use '?' for unknown glyphs */
|
||||
//static glyph_t *glyph(uint8_t *character) { return glyph(*character); }
|
||||
|
||||
/**
|
||||
* @brief Set the string empty
|
||||
*/
|
||||
static void set();
|
||||
//static void add(uint8_t character) { add_character(character); eol(); }
|
||||
|
||||
//static void add(const char character) { add_character(character); eol(); }
|
||||
|
||||
/**
|
||||
* @brief Append a UTF-8 character
|
||||
*
|
||||
* @param character The UTF-8 character
|
||||
*/
|
||||
static void add(wchar_t character);
|
||||
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
|
||||
static void add(uint8_t *string, const int8_t index, uint8_t *inStr=nullptr);
|
||||
static void set(uint8_t *string) { set(); add(string); }
|
||||
static void set(wchar_t character) { set(); add(character); }
|
||||
static void set(uint8_t *string, int8_t index, const char *inStr=nullptr) { set(); add(string, index, (uint8_t *)inStr); }
|
||||
static void set(const char *string) { set((uint8_t *)string); }
|
||||
static void set(const char *string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)string, index, inStr); }
|
||||
static void add(const char *string) { add((uint8_t *)string); }
|
||||
|
||||
static void add(FSTR_P const string, uint8_t max_len=MAX_STRING_LENGTH) { add((uint8_t *)FTOP(string), max_len); }
|
||||
static void add(FSTR_P const string, int8_t index, uint8_t *inStr=nullptr) { add((uint8_t *)FTOP(string), index, inStr); }
|
||||
static void set(FSTR_P const string) { set((uint8_t *)FTOP(string)); }
|
||||
static void set(FSTR_P const string, int8_t index, const char *inStr=nullptr) { set((uint8_t *)FTOP(string), index, inStr); }
|
||||
static void add(FSTR_P const string) { add((uint8_t *)FTOP(string)); }
|
||||
/**
|
||||
* @brief Append / Set C-string
|
||||
*
|
||||
* @param cstr The string
|
||||
* @param max_len Character limit
|
||||
*/
|
||||
static void add(const char *cstr, uint8_t max_len=MAX_STRING_LENGTH);
|
||||
static void set(const char *cstr) { set(); add(cstr); }
|
||||
|
||||
static void trim(const uint8_t character=0x20);
|
||||
static void rtrim(const uint8_t character=0x20);
|
||||
static void ltrim(const uint8_t character=0x20);
|
||||
/**
|
||||
* @brief Append / Set F-string
|
||||
*
|
||||
* @param fstr The string
|
||||
* @param max_len Character limit
|
||||
*/
|
||||
static void add(FSTR_P const fstr, uint8_t max_len=MAX_STRING_LENGTH) { add(FTOP(fstr), max_len); }
|
||||
static void set(FSTR_P const fstr) { set(FTOP(fstr)); }
|
||||
|
||||
static void truncate(uint8_t maxlen) { if (len > maxlen) { len = maxlen; eol(); } }
|
||||
/**
|
||||
* @brief Append / Set C-string with optional substitution
|
||||
*
|
||||
* @param tpl A string with optional substitution
|
||||
* @param index An index
|
||||
* @param cstr An SRAM C-string to use for $ substitution
|
||||
* @param fstr A ROM F-string to use for $ substitution
|
||||
*/
|
||||
static void add(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr);
|
||||
static void set(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(tpl, index, cstr, fstr); }
|
||||
|
||||
static uint8_t length() { return len; }
|
||||
/**
|
||||
* @brief Append / Set F-string with optional substitution
|
||||
*
|
||||
* @param ftpl A ROM F-string with optional substitution
|
||||
* @param index An index
|
||||
* @param cstr An SRAM C-string to use for $ substitution
|
||||
* @param fstr A ROM F-string to use for $ substitution
|
||||
*/
|
||||
static void add(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { add(FTOP(ftpl), index, cstr, fstr); }
|
||||
static void set(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(ftpl, index, cstr, fstr); }
|
||||
|
||||
// Common string ops
|
||||
static void trim(const char character=' ');
|
||||
static void rtrim(const char character=' ');
|
||||
static void ltrim(const char character=' ');
|
||||
static void truncate(const uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
|
||||
|
||||
// Accessors
|
||||
static char *string() { return data; }
|
||||
static uint16_t width() { return span; }
|
||||
static uint8_t *string() { return data; }
|
||||
static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }
|
||||
static uint16_t center(const uint16_t width) { return span > width ? 0 : (width - span) / 2; }
|
||||
};
|
||||
|
||||
int dwin_charmap_compare(dwin_charmap_t *v1, dwin_charmap_t *v2);
|
||||
|
Reference in New Issue
Block a user