LCD strlen functions like 2.0.x
This commit is contained in:
parent
756080fcca
commit
fbc3fdb490
@ -126,7 +126,7 @@ inline void lcd_implementation_status_message(const bool blink) {
|
|||||||
static bool last_blink = false;
|
static bool last_blink = false;
|
||||||
|
|
||||||
// Get the UTF8 character count of the string
|
// Get the UTF8 character count of the string
|
||||||
uint8_t slen = lcd_strlen(lcd_status_message);
|
uint8_t slen = utf8_strlen(lcd_status_message);
|
||||||
|
|
||||||
// If the string fits into the LCD, just print it and do not scroll it
|
// If the string fits into the LCD, just print it and do not scroll it
|
||||||
if (slen <= LCD_WIDTH) {
|
if (slen <= LCD_WIDTH) {
|
||||||
@ -147,7 +147,7 @@ inline void lcd_implementation_status_message(const bool blink) {
|
|||||||
const char *stat = lcd_status_message + status_scroll_offset;
|
const char *stat = lcd_status_message + status_scroll_offset;
|
||||||
|
|
||||||
// Get the string remaining length
|
// Get the string remaining length
|
||||||
const uint8_t rlen = lcd_strlen(stat);
|
const uint8_t rlen = utf8_strlen(stat);
|
||||||
|
|
||||||
// If we have enough characters to display
|
// If we have enough characters to display
|
||||||
if (rlen >= LCD_WIDTH) {
|
if (rlen >= LCD_WIDTH) {
|
||||||
@ -183,7 +183,7 @@ inline void lcd_implementation_status_message(const bool blink) {
|
|||||||
UNUSED(blink);
|
UNUSED(blink);
|
||||||
|
|
||||||
// Get the UTF8 character count of the string
|
// Get the UTF8 character count of the string
|
||||||
uint8_t slen = lcd_strlen(lcd_status_message);
|
uint8_t slen = utf8_strlen(lcd_status_message);
|
||||||
|
|
||||||
// Just print the string to the LCD
|
// Just print the string to the LCD
|
||||||
lcd_print_utf(lcd_status_message, LCD_WIDTH);
|
lcd_print_utf(lcd_status_message, LCD_WIDTH);
|
||||||
|
@ -618,7 +618,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) {
|
|||||||
const uint8_t lcd_len = 16;
|
const uint8_t lcd_len = 16;
|
||||||
#if ENABLED(STATUS_MESSAGE_SCROLLING)
|
#if ENABLED(STATUS_MESSAGE_SCROLLING)
|
||||||
|
|
||||||
uint8_t slen = lcd_strlen(str);
|
uint8_t slen = utf8_strlen(str);
|
||||||
|
|
||||||
// If the string fits into the LCD, just print it and do not scroll it
|
// If the string fits into the LCD, just print it and do not scroll it
|
||||||
if (slen <= lcd_len) {
|
if (slen <= lcd_len) {
|
||||||
@ -639,7 +639,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) {
|
|||||||
const char *stat = str + status_scroll_offset;
|
const char *stat = str + status_scroll_offset;
|
||||||
|
|
||||||
// Get the string remaining length
|
// Get the string remaining length
|
||||||
const uint8_t rlen = lcd_strlen(stat);
|
const uint8_t rlen = utf8_strlen(stat);
|
||||||
|
|
||||||
// If we have enough characters to display
|
// If we have enough characters to display
|
||||||
if (rlen >= lcd_len) {
|
if (rlen >= lcd_len) {
|
||||||
@ -670,7 +670,7 @@ void ST7920_Lite_Status_Screen::draw_status_message(const char *str) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Get the UTF8 character count of the string
|
// Get the UTF8 character count of the string
|
||||||
uint8_t slen = lcd_strlen(str);
|
uint8_t slen = utf8_strlen(str);
|
||||||
|
|
||||||
// Just print the string to the LCD
|
// Just print the string to the LCD
|
||||||
write_str(str, lcd_len);
|
write_str(str, lcd_len);
|
||||||
|
@ -5050,7 +5050,7 @@ void lcd_init() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t lcd_strlen(const char* s) {
|
int16_t utf8_strlen(const char* s) {
|
||||||
int16_t i = 0, j = 0;
|
int16_t i = 0, j = 0;
|
||||||
while (s[i]) {
|
while (s[i]) {
|
||||||
if (START_OF_UTF8_CHAR(s[i])) j++;
|
if (START_OF_UTF8_CHAR(s[i])) j++;
|
||||||
@ -5059,7 +5059,7 @@ int16_t lcd_strlen(const char* s) {
|
|||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t lcd_strlen_P(const char* s) {
|
int16_t utf8_strlen_P(const char* s) {
|
||||||
int16_t j = 0;
|
int16_t j = 0;
|
||||||
while (pgm_read_byte(s)) {
|
while (pgm_read_byte(s)) {
|
||||||
if (START_OF_UTF8_CHAR(pgm_read_byte(s))) j++;
|
if (START_OF_UTF8_CHAR(pgm_read_byte(s))) j++;
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
|
|
||||||
#include "Marlin.h"
|
#include "Marlin.h"
|
||||||
|
|
||||||
int16_t lcd_strlen(const char* s);
|
int16_t utf8_strlen(const char* s);
|
||||||
int16_t lcd_strlen_P(const char* s);
|
int16_t utf8_strlen_P(const char* s);
|
||||||
bool lcd_hasstatus();
|
bool lcd_hasstatus();
|
||||||
void lcd_setstatus(const char* message, const bool persist=false);
|
void lcd_setstatus(const char* message, const bool persist=false);
|
||||||
void lcd_setstatusPGM(const char* message, const int8_t level=0);
|
void lcd_setstatusPGM(const char* message, const int8_t level=0);
|
||||||
|
@ -468,7 +468,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
|
|||||||
int8_t n = LCD_WIDTH - (START_COL);
|
int8_t n = LCD_WIDTH - (START_COL);
|
||||||
|
|
||||||
if (center && !valstr) {
|
if (center && !valstr) {
|
||||||
int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
|
int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
|
||||||
while (--pad >= 0) { u8g.print(' '); n--; }
|
while (--pad >= 0) { u8g.print(' '); n--; }
|
||||||
}
|
}
|
||||||
while (n > 0 && (c = pgm_read_byte(pstr))) {
|
while (n > 0 && (c = pgm_read_byte(pstr))) {
|
||||||
@ -514,7 +514,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
|
|||||||
|
|
||||||
if (!PAGE_CONTAINS(row_y1, row_y2)) return;
|
if (!PAGE_CONTAINS(row_y1, row_y2)) return;
|
||||||
|
|
||||||
const uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
|
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data));
|
||||||
uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
|
uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
|
||||||
|
|
||||||
while (char c = pgm_read_byte(pstr)) {
|
while (char c = pgm_read_byte(pstr)) {
|
||||||
@ -535,8 +535,8 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
|
|||||||
#define DRAW_BOOL_SETTING(sel, row, pstr, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
|
#define DRAW_BOOL_SETTING(sel, row, pstr, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
|
||||||
|
|
||||||
void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
|
void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
|
||||||
const uint8_t labellen = lcd_strlen_P(pstr),
|
const uint8_t labellen = utf8_strlen_P(pstr),
|
||||||
vallen = lcd_strlen(value);
|
vallen = utf8_strlen(value);
|
||||||
|
|
||||||
uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
|
uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
|
|||||||
|
|
||||||
// Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
|
// Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
|
||||||
void lcd_scroll(const int16_t col, const int16_t line, const char* const text, const int16_t len, const int16_t time) {
|
void lcd_scroll(const int16_t col, const int16_t line, const char* const text, const int16_t len, const int16_t time) {
|
||||||
uint8_t slen = lcd_strlen_P(text);
|
uint8_t slen = utf8_strlen_P(text);
|
||||||
if (slen < len) {
|
if (slen < len) {
|
||||||
// Fits into,
|
// Fits into,
|
||||||
lcd.setCursor(col, line);
|
lcd.setCursor(col, line);
|
||||||
@ -926,7 +926,7 @@ static void lcd_implementation_status_screen() {
|
|||||||
static bool last_blink = false;
|
static bool last_blink = false;
|
||||||
|
|
||||||
// Get the UTF8 character count of the string
|
// Get the UTF8 character count of the string
|
||||||
uint8_t slen = lcd_strlen(lcd_status_message);
|
uint8_t slen = utf8_strlen(lcd_status_message);
|
||||||
|
|
||||||
// If the string fits into the LCD, just print it and do not scroll it
|
// If the string fits into the LCD, just print it and do not scroll it
|
||||||
if (slen <= LCD_WIDTH) {
|
if (slen <= LCD_WIDTH) {
|
||||||
@ -947,7 +947,7 @@ static void lcd_implementation_status_screen() {
|
|||||||
const char *stat = lcd_status_message + status_scroll_offset;
|
const char *stat = lcd_status_message + status_scroll_offset;
|
||||||
|
|
||||||
// Get the string remaining length
|
// Get the string remaining length
|
||||||
const uint8_t rlen = lcd_strlen(stat);
|
const uint8_t rlen = utf8_strlen(stat);
|
||||||
|
|
||||||
// If we have enough characters to display
|
// If we have enough characters to display
|
||||||
if (rlen >= LCD_WIDTH) {
|
if (rlen >= LCD_WIDTH) {
|
||||||
@ -984,7 +984,7 @@ static void lcd_implementation_status_screen() {
|
|||||||
UNUSED(blink);
|
UNUSED(blink);
|
||||||
|
|
||||||
// Get the UTF8 character count of the string
|
// Get the UTF8 character count of the string
|
||||||
uint8_t slen = lcd_strlen(lcd_status_message);
|
uint8_t slen = utf8_strlen(lcd_status_message);
|
||||||
|
|
||||||
// Just print the string to the LCD
|
// Just print the string to the LCD
|
||||||
lcd_print_utf(lcd_status_message, LCD_WIDTH);
|
lcd_print_utf(lcd_status_message, LCD_WIDTH);
|
||||||
@ -1019,8 +1019,8 @@ static void lcd_implementation_status_screen() {
|
|||||||
int8_t n = LCD_WIDTH;
|
int8_t n = LCD_WIDTH;
|
||||||
lcd.setCursor(0, row);
|
lcd.setCursor(0, row);
|
||||||
if (center && !valstr) {
|
if (center && !valstr) {
|
||||||
int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
|
|
||||||
while (--pad >= 0) { lcd.write(' '); n--; }
|
while (--pad >= 0) { lcd.write(' '); n--; }
|
||||||
|
int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
|
||||||
}
|
}
|
||||||
while (n > 0 && (c = pgm_read_byte(pstr))) {
|
while (n > 0 && (c = pgm_read_byte(pstr))) {
|
||||||
n -= charset_mapper(c);
|
n -= charset_mapper(c);
|
||||||
@ -1048,9 +1048,9 @@ static void lcd_implementation_status_screen() {
|
|||||||
|
|
||||||
static void lcd_implementation_drawmenu_setting_edit_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) {
|
static void lcd_implementation_drawmenu_setting_edit_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) {
|
||||||
char c;
|
char c;
|
||||||
uint8_t n = LCD_WIDTH - 2 - lcd_strlen(data);
|
|
||||||
lcd.setCursor(0, row);
|
lcd.setCursor(0, row);
|
||||||
lcd.print(sel ? pre_char : ' ');
|
lcd.print(sel ? pre_char : ' ');
|
||||||
|
uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data);
|
||||||
while ((c = pgm_read_byte(pstr)) && n > 0) {
|
while ((c = pgm_read_byte(pstr)) && n > 0) {
|
||||||
n -= charset_mapper(c);
|
n -= charset_mapper(c);
|
||||||
pstr++;
|
pstr++;
|
||||||
@ -1061,9 +1061,9 @@ static void lcd_implementation_status_screen() {
|
|||||||
}
|
}
|
||||||
static void lcd_implementation_drawmenu_setting_edit_generic_P(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) {
|
static void lcd_implementation_drawmenu_setting_edit_generic_P(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char* const data) {
|
||||||
char c;
|
char c;
|
||||||
uint8_t n = LCD_WIDTH - 2 - lcd_strlen_P(data);
|
|
||||||
lcd.setCursor(0, row);
|
lcd.setCursor(0, row);
|
||||||
lcd.print(sel ? pre_char : ' ');
|
lcd.print(sel ? pre_char : ' ');
|
||||||
|
uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data);
|
||||||
while ((c = pgm_read_byte(pstr)) && n > 0) {
|
while ((c = pgm_read_byte(pstr)) && n > 0) {
|
||||||
n -= charset_mapper(c);
|
n -= charset_mapper(c);
|
||||||
pstr++;
|
pstr++;
|
||||||
@ -1081,10 +1081,10 @@ static void lcd_implementation_status_screen() {
|
|||||||
lcd_printPGM_utf(pstr);
|
lcd_printPGM_utf(pstr);
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
lcd.write(':');
|
lcd.write(':');
|
||||||
const uint8_t valrow = (lcd_strlen_P(pstr) + 1 + lcd_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit
|
|
||||||
lcd.setCursor((LCD_WIDTH - 1) - (lcd_strlen(value) + 1), valrow); // Right-justified, padded by spaces
|
lcd.setCursor((LCD_WIDTH - 1) - (lcd_strlen(value) + 1), valrow); // Right-justified, padded by spaces
|
||||||
lcd.write(' '); // overwrite char if value gets shorter
|
lcd.write(' '); // overwrite char if value gets shorter
|
||||||
lcd_print(value);
|
lcd_print(value);
|
||||||
|
const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + utf8_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1; // Value on the next row if it won't fit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user