kopia lustrzana https://github.com/OpenRTX/OpenRTX
Improve gfx_printLine calculation
rodzic
3e326a43f0
commit
8045a9bcea
|
@ -260,8 +260,8 @@ point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment,
|
||||||
* The print position is calculated to fit the desired number of lines in the vertical space
|
* The print position is calculated to fit the desired number of lines in the vertical space
|
||||||
* @param cur: current line number over total (1-based)
|
* @param cur: current line number over total (1-based)
|
||||||
* @param tot: number of lines to fit in screen
|
* @param tot: number of lines to fit in screen
|
||||||
* @param startY: starting Y coordinate to leave space for top bar
|
* @param startY: starting Y coordinate to leave space at the top, use 0 to leave no space
|
||||||
* @param endY: ending Y coordinate to leave space for bottom bar
|
* @param endY: ending Y coordinate to leave space at the bottom, use 0 to leave no space
|
||||||
* @param startX: starting X coordinate to leave space on the screen sides
|
* @param startX: starting X coordinate to leave space on the screen sides
|
||||||
* @param size: text font size, defined as enum.
|
* @param size: text font size, defined as enum.
|
||||||
* @param alignment: text alignment type, defined as enum.
|
* @param alignment: text alignment type, defined as enum.
|
||||||
|
|
|
@ -492,8 +492,9 @@ point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment,
|
||||||
return gfx_printBuffer(start, size, alignment, color, text);
|
return gfx_printBuffer(start, size, alignment, color, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY, uint16_t startX,
|
point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY,
|
||||||
fontSize_t size, textAlign_t alignment, color_t color, const char* fmt, ... )
|
uint16_t startX, fontSize_t size, textAlign_t alignment,
|
||||||
|
color_t color, const char* fmt, ... )
|
||||||
{
|
{
|
||||||
// Get format string and arguments from var char
|
// Get format string and arguments from var char
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -501,21 +502,18 @@ point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY,
|
||||||
vsnprintf(text, sizeof(text)-1, fmt, ap);
|
vsnprintf(text, sizeof(text)-1, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
// Estimate font height by reading the gliph | height
|
||||||
|
uint8_t fontH = gfx_getFontHeight(size);
|
||||||
|
|
||||||
// If endY is 0 set it to default value = SCREEN_HEIGHT
|
// If endY is 0 set it to default value = SCREEN_HEIGHT
|
||||||
if(endY == 0)
|
if(endY == 0) endY = SCREEN_HEIGHT;
|
||||||
endY = SCREEN_HEIGHT;
|
|
||||||
|
|
||||||
// Calculate print coordinates
|
// Calculate print coordinates
|
||||||
// e.g. to print 2 lines we need 3 padding spaces
|
uint16_t height = endY - startY;
|
||||||
uint16_t step = (endY - startY) / (tot + 1);
|
// to print 2 lines we need 3 padding spaces
|
||||||
uint16_t printY = startY + (step * cur);
|
uint16_t gap = (height - (fontH * tot)) / (tot + 1);
|
||||||
|
// We need a gap and a line height for each line
|
||||||
// Estimate font height by reading the gliph | height
|
uint16_t printY = startY + (cur * (gap + fontH));
|
||||||
uint8_t h = gfx_getFontHeight(size);
|
|
||||||
|
|
||||||
// gfx_printBuffer() prints over the starting point
|
|
||||||
// Add half print_height to get vertically centered prints
|
|
||||||
printY += (h / 2);
|
|
||||||
|
|
||||||
point_t start = {startX, printY};
|
point_t start = {startX, printY};
|
||||||
return gfx_printBuffer(start, size, alignment, color, text);
|
return gfx_printBuffer(start, size, alignment, color, text);
|
||||||
|
|
Ładowanie…
Reference in New Issue