mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2024-11-09 13:47:17 -05:00
Add justification option for text rendering
This commit is contained in:
parent
c013281a31
commit
0417907d03
11
nano_gui.cpp
11
nano_gui.cpp
@ -228,7 +228,8 @@ void displayRawText(char *text, int x1, int y1, int w, int color, int background
|
|||||||
tft.print(text);
|
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);
|
displayFillrect(x1, y1, w ,h, background);
|
||||||
displayRect(x1, y1, w ,h, border);
|
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 width_out;
|
||||||
uint16_t height_out;
|
uint16_t height_out;
|
||||||
tft.getTextBounds(text,x1,y1,&x1_out,&y1_out,&width_out,&height_out,w);
|
tft.getTextBounds(text,x1,y1,&x1_out,&y1_out,&width_out,&height_out,w);
|
||||||
|
if(TextJustification_e::Center == justification){
|
||||||
x1 += (w - ( (int32_t)width_out + (x1_out-x1)))/2;
|
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;
|
y1 += (ubitx_font->yAdvance + h - ( (int32_t)height_out))/2;
|
||||||
displayRawText(text,x1,y1,w,color,background);
|
displayRawText(text,x1,y1,w,color,background);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,13 @@ struct Point {
|
|||||||
};
|
};
|
||||||
extern struct Point ts_point;
|
extern struct Point ts_point;
|
||||||
|
|
||||||
|
enum TextJustification_e : uint8_t
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Center
|
||||||
|
};
|
||||||
|
|
||||||
void displayInit();
|
void displayInit();
|
||||||
void displayClear(unsigned int color);
|
void displayClear(unsigned int color);
|
||||||
void displayPixel(unsigned int x, unsigned int y, unsigned int c);
|
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 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 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 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);
|
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user