Use u8g int type for screen coordinates (#14965)

This commit is contained in:
Robby Candra
2019-08-18 07:58:38 +07:00
committed by Scott Lahteine
parent 6715fd159c
commit 823178c272
8 changed files with 104 additions and 107 deletions

View File

@@ -205,13 +205,13 @@ millis_t next_button_update_ms;
#endif
void _wrap_string(uint8_t &x, uint8_t &y, const char * const string, read_byte_cb_t cb_read_byte, bool wordwrap/*=false*/) {
SETCURSOR(x, y);
void _wrap_string(uint8_t &col, uint8_t &row, const char * const string, read_byte_cb_t cb_read_byte, bool wordwrap/*=false*/) {
SETCURSOR(col, row);
if (!string) return;
auto _newline = [&x, &y]() {
x = 0; y++; // move x to string len (plus space)
SETCURSOR(0, y); // simulate carriage return
auto _newline = [&col, &row]() {
col = 0; row++; // Move col to string len (plus space)
SETCURSOR(0, row); // Simulate carriage return
};
uint8_t *p = (uint8_t*)string;
@@ -227,9 +227,9 @@ millis_t next_button_update_ms;
if (eol || ch == ' ' || ch == '-' || ch == '+' || ch == '.') {
if (!c && ch == ' ') { if (wrd) wrd++; continue; } // collapse extra spaces
// Past the right and the word is not too long?
if (x + c > LCD_WIDTH && x >= (LCD_WIDTH) / 4) _newline(); // should it wrap?
if (col + c > LCD_WIDTH && col >= (LCD_WIDTH) / 4) _newline(); // should it wrap?
c += !eol; // +1 so the space will be printed
x += c; // advance x to new position
col += c; // advance col to new position
while (c) { // character countdown
--c; // count down to zero
wrd = get_utf8_value_cb(wrd, cb_read_byte, &ch); // get characters again
@@ -246,25 +246,25 @@ millis_t next_button_update_ms;
p = get_utf8_value_cb(p, cb_read_byte, &ch);
if (!ch) break;
lcd_put_wchar(ch);
x++;
if (x >= LCD_WIDTH) _newline();
col++;
if (col >= LCD_WIDTH) _newline();
}
}
}
void MarlinUI::draw_select_screen_prompt(PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
const uint8_t plen = utf8_strlen_P(pref), slen = suff ? utf8_strlen_P(suff) : 0;
uint8_t x = 0, y = 0;
uint8_t row = 0, col = 0;
if (!string && plen + slen <= LCD_WIDTH) {
x = (LCD_WIDTH - plen - slen) / 2;
y = LCD_HEIGHT > 3 ? 1 : 0;
row = (LCD_WIDTH - plen - slen) / 2;
col = LCD_HEIGHT > 3 ? 1 : 0;
}
wrap_string_P(x, y, pref, true);
wrap_string_P(row, col, pref, true);
if (string) {
if (x) { x = 0; y++; } // Move to the start of the next line
wrap_string(x, y, string);
if (row) { row = 0; col++; } // Move to the start of the next line
wrap_string(row, col, string);
}
if (suff) wrap_string_P(x, y, suff);
if (suff) wrap_string_P(row, col, suff);
}
#endif // HAS_LCD_MENU