From 0417907d039cced53ea5de0b600d1f5c59cc6bdb Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Mon, 27 Jan 2020 23:08:32 -0800 Subject: [PATCH 1/3] Add justification option for text rendering --- nano_gui.cpp | 13 +++++++++++-- nano_gui.h | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/nano_gui.cpp b/nano_gui.cpp index fdfdfa3..1bc9d55 100644 --- a/nano_gui.cpp +++ b/nano_gui.cpp @@ -228,7 +228,8 @@ void displayRawText(char *text, int x1, int y1, int w, int color, int background tft.print(text); } -void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border) { +void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border, TextJustification_e justification) +{ displayFillrect(x1, y1, w ,h, background); displayRect(x1, y1, w ,h, border); @@ -237,7 +238,15 @@ void displayText(char *text, int x1, int y1, int w, int h, int color, int backgr uint16_t width_out; uint16_t height_out; tft.getTextBounds(text,x1,y1,&x1_out,&y1_out,&width_out,&height_out,w); - x1 += (w - ( (int32_t)width_out + (x1_out-x1)))/2; + if(TextJustification_e::Center == justification){ + x1 += (w - ( (int32_t)width_out + (x1_out-x1)))/2; + } + else if(TextJustification_e::Right == justification){ + x1 += w - ((int32_t)width_out + (x1_out-x1)); + } + else{ + x1 += 2;//Give a little bit of padding from the border + } y1 += (ubitx_font->yAdvance + h - ( (int32_t)height_out))/2; displayRawText(text,x1,y1,w,color,background); } diff --git a/nano_gui.h b/nano_gui.h index b6d24ac..7c1fd21 100644 --- a/nano_gui.h +++ b/nano_gui.h @@ -7,6 +7,13 @@ struct Point { }; extern struct Point ts_point; +enum TextJustification_e : uint8_t +{ + Left, + Right, + Center +}; + void displayInit(); void displayClear(unsigned int color); void displayPixel(unsigned int x, unsigned int y, unsigned int c); @@ -16,7 +23,7 @@ void displayRect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,uns void displayFillrect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c); void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg); void displayRawText(char *text, int x1, int y1, int color, int background); -void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border); +void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border, TextJustification_e justification = TextJustification_e::Center); void formatFreq(uint32_t freq, char* buff, uint16_t buff_size); From ceec8e2eb29cc54a3b7de7af27c4f57c1861e07c Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Mon, 27 Jan 2020 23:09:05 -0800 Subject: [PATCH 2/3] Push CW settings text to left, version to right --- ubitx_ui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ubitx_ui.cpp b/ubitx_ui.cpp index 8a26b59..329376f 100644 --- a/ubitx_ui.cpp +++ b/ubitx_ui.cpp @@ -511,13 +511,13 @@ void drawCWStatus(){ itoa(globalSettings.cwSideToneFreq, c, 10); strncat(b, c, sizeof(b) - strlen(b)); strncat_P(b,(const char*)F("hz"), sizeof(b) - strlen(b)); - displayText(b, LAYOUT_CW_TEXT_X, LAYOUT_CW_TEXT_Y, LAYOUT_CW_TEXT_WIDTH, LAYOUT_CW_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); + displayText(b, LAYOUT_CW_TEXT_X, LAYOUT_CW_TEXT_Y, LAYOUT_CW_TEXT_WIDTH, LAYOUT_CW_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Left); } void drawVersion() { strncpy_P(b,VERSION_STRING,sizeof(b)); - displayText(b, LAYOUT_VERSION_TEXT_X, LAYOUT_VERSION_TEXT_Y, LAYOUT_VERSION_TEXT_WIDTH, LAYOUT_VERSION_TEXT_HEIGHT, COLOR_VERSION_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); + displayText(b, LAYOUT_VERSION_TEXT_X, LAYOUT_VERSION_TEXT_Y, LAYOUT_VERSION_TEXT_WIDTH, LAYOUT_VERSION_TEXT_HEIGHT, COLOR_VERSION_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Right); } void drawTx(){ From 03c159ba5198e4e6b51da4ae84016d69d2338736 Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Mon, 27 Jan 2020 23:09:34 -0800 Subject: [PATCH 3/3] Render menus to the left, rather than center --- setup.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cpp b/setup.cpp index 135ec00..70852ff 100644 --- a/setup.cpp +++ b/setup.cpp @@ -69,7 +69,7 @@ void displayDialog(const char* title, strncpy_P(b,title,sizeof(b)); displayText(b, LAYOUT_TITLE_X, LAYOUT_TITLE_Y, LAYOUT_TITLE_WIDTH, LAYOUT_TITLE_HEIGHT, COLOR_TEXT, COLOR_TITLE_BACKGROUND, COLOR_ACTIVE_BORDER); strncpy_P(b,instructions,sizeof(b)); - displayText(b, LAYOUT_INSTRUCTIONS_TEXT_X, LAYOUT_INSTRUCTIONS_TEXT_Y, LAYOUT_INSTRUCTIONS_TEXT_WIDTH, LAYOUT_INSTRUCTIONS_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); + displayText(b, LAYOUT_INSTRUCTIONS_TEXT_X, LAYOUT_INSTRUCTIONS_TEXT_Y, LAYOUT_INSTRUCTIONS_TEXT_WIDTH, LAYOUT_INSTRUCTIONS_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND, TextJustification_e::Left); strncpy_P(b,(const char*)F("Push Tune to Save"),sizeof(b)); displayText(b, LAYOUT_CONFIRM_TEXT_X, LAYOUT_CONFIRM_TEXT_Y, LAYOUT_CONFIRM_TEXT_WIDTH, LAYOUT_CONFIRM_TEXT_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_BACKGROUND); } @@ -456,11 +456,11 @@ void drawMenu(const MenuItem_t* const items, const uint16_t num_items) for(unsigned int i = 1; i < num_items; ++i){ memcpy_P(&mi,&items[i],sizeof(mi)); strncpy_P(b,mi.ItemName,sizeof(b)); - displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (i-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER); + displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (i-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER, TextJustification_e::Left); } memcpy_P(&mi,&exitMenu,sizeof(mi)); strncpy_P(b,mi.ItemName,sizeof(b)); - displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (num_items-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER); + displayText(b, LAYOUT_ITEM_X, LAYOUT_ITEM_Y + (num_items-1)*LAYOUT_ITEM_PITCH_Y, LAYOUT_ITEM_WIDTH, LAYOUT_ITEM_HEIGHT, COLOR_TEXT, COLOR_BACKGROUND, COLOR_INACTIVE_BORDER, TextJustification_e::Left); } void movePuck(unsigned int old_index, unsigned int new_index)