From a4125582f137a57b5617f884e8ef1c7f4a640c3d Mon Sep 17 00:00:00 2001 From: 3djc Date: Tue, 18 Feb 2020 12:42:24 +0100 Subject: [PATCH] Improve textView on colorlcd (#7395) --- radio/src/gui/480x272/bitmapbuffer.h | 18 ++++++++++++++++++ radio/src/gui/480x272/lcd.h | 7 ------- radio/src/gui/480x272/view_text.cpp | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/radio/src/gui/480x272/bitmapbuffer.h b/radio/src/gui/480x272/bitmapbuffer.h index 760215198..b9cdc0381 100644 --- a/radio/src/gui/480x272/bitmapbuffer.h +++ b/radio/src/gui/480x272/bitmapbuffer.h @@ -41,6 +41,14 @@ typedef int coord_t; typedef uint32_t LcdFlags; typedef uint16_t display_t; +int getTextWidth(const char * s, int len=0, LcdFlags flags=0); + +#if LCD_W >= 480 +#define LCD_COLS 80 +#else +#define LCD_COLS 30 +#endif + enum BitmapFormats { BMP_RGB565, @@ -275,6 +283,16 @@ class BitmapBuffer: public BitmapBufferBase uint8_t drawCharWithCache(coord_t x, coord_t y, const BitmapBuffer * font, const uint16_t * spec, int index, LcdFlags flags); + void drawTextMaxWidth(coord_t x, coord_t y, const char * s, LcdFlags flags, coord_t maxWidth) + { + for (int col = LCD_COLS; col > 0; col--) { + if (getTextWidth(s, col, flags) <= maxWidth) { + drawSizedText(x, y, s, col, flags); + return; + } + } + } + void drawText(coord_t x, coord_t y, const char * s, LcdFlags flags) { drawSizedText(x, y, s, 255, flags); diff --git a/radio/src/gui/480x272/lcd.h b/radio/src/gui/480x272/lcd.h index c66865d85..dfb42e829 100644 --- a/radio/src/gui/480x272/lcd.h +++ b/radio/src/gui/480x272/lcd.h @@ -24,12 +24,6 @@ #include "bitmapbuffer.h" #include "opentx_types.h" -#if LCD_W >= 480 - #define LCD_COLS 40 -#else - #define LCD_COLS 30 -#endif - #define CENTER /* lcd common flags */ @@ -254,7 +248,6 @@ inline int getBitmapHeight(const uint8_t * bmp) uint8_t getMappedChar(uint8_t c); uint8_t getFontHeight(LcdFlags flags); -int getTextWidth(const char * s, int len=0, LcdFlags flags=0); inline void lcdDrawBitmapPattern(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags=0, coord_t offset=0, coord_t width=0) { diff --git a/radio/src/gui/480x272/view_text.cpp b/radio/src/gui/480x272/view_text.cpp index 3038887bf..a7969d21f 100644 --- a/radio/src/gui/480x272/view_text.cpp +++ b/radio/src/gui/480x272/view_text.cpp @@ -56,7 +56,7 @@ bool menuTextView(event_t event) } for (int i=0; idrawTextMaxWidth(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + i * FH, reusableBuffer.viewText.lines[i], 0, LCD_W - 2 * MENUS_MARGIN_LEFT); } #if 0