Implement multi-linewrap in lcd_display_text
This commit is contained in:
@@ -38,31 +38,18 @@ void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t
|
||||
BSP_LCD_SetFont(font);
|
||||
|
||||
if (tot_length > BSP_LCD_GetXSize()) {
|
||||
uint16_t wrap_idx = (BSP_LCD_GetXSize() - x_pos)/font->Width;
|
||||
if (isalpha(text[wrap_idx - 1]) && isalpha(text[wrap_idx])) {
|
||||
x_pos -= (font->Width-2);
|
||||
char part_one[wrap_idx+2];
|
||||
char part_two[(strlen(text) - wrap_idx)+1];
|
||||
strncpy(part_one, text, wrap_idx);
|
||||
part_one[wrap_idx] = '-';
|
||||
part_one[wrap_idx+1] = '\00';
|
||||
strncpy(part_two, &text[wrap_idx], (strlen(text) - wrap_idx));
|
||||
part_two[(strlen(text) - wrap_idx)] = '\00';
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_one, LEFT_MODE);
|
||||
y_pos += font->Height;
|
||||
x_pos = 0;
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_two, LEFT_MODE);
|
||||
} else {
|
||||
char part_one[wrap_idx+1];
|
||||
char part_two[(strlen(text) - wrap_idx)+1];
|
||||
strncpy(part_one, text, wrap_idx);
|
||||
part_one[wrap_idx] = '\00';
|
||||
strncpy(part_two, &text[wrap_idx], (strlen(text) - wrap_idx));
|
||||
part_two[(strlen(text) - wrap_idx)] = '\00';
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_one, LEFT_MODE);
|
||||
y_pos += font->Height;
|
||||
x_pos = 0;
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, part_two, LEFT_MODE);
|
||||
for (int i = 0; i < strlen(text); i++) {
|
||||
if ((x_pos) > BSP_LCD_GetXSize() - (font->Width)*2) {
|
||||
if (isalpha(text[i-1]) && isalpha(text[i])) {
|
||||
BSP_LCD_DisplayChar(x_pos, y_pos, '-');
|
||||
i -= 1;
|
||||
}
|
||||
x_pos = 0;
|
||||
y_pos += font->Height;
|
||||
} else {
|
||||
BSP_LCD_DisplayChar(x_pos, y_pos, text[i]);
|
||||
x_pos += font->Width;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, text, LEFT_MODE);
|
||||
|
||||
Reference in New Issue
Block a user