Add gfx_getFontHeigth() function

replace/6682e70c347ca6867759c468dc025eb04a572365
Federico Amedeo Izzo 2021-04-10 10:35:02 +02:00
rodzic c3a8251ca9
commit 3e326a43f0
2 zmienionych plików z 39 dodań i 3 usunięć

Wyświetl plik

@ -223,6 +223,26 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
*/
void gfx_drawCircle(point_t start, uint16_t r, color_t color);
/**
* Estimates the maximum font height by reading the gliph | height
* @param size: text font size, defined as enum.
* @return font height
*/
uint8_t gfx_getFontHeight(fontSize_t size);
/**
* Prints text on the screen at the specified coordinates.
* Reads text from a given char buffer
* @param start: text line start point, in pixel coordinates.
* @param size: text font size, defined as enum.
* @param alignment: text alignment type, defined as enum.
* @param color: text color, in color_t format.
* @param buf: char buffer
* @return text width and height as point_t coordinates
*/
point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment,
color_t color, const char *buf);
/**
* Prints text on the screen at the specified coordinates.
* @param start: text line start point, in pixel coordinates.
@ -232,7 +252,8 @@ void gfx_drawCircle(point_t start, uint16_t r, color_t color);
* @param fmt: printf style format string
* @return text width and height as point_t coordinates
*/
point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment, color_t color, const char* fmt, ... );
point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment,
color_t color, const char* fmt, ... );
/**
* Prints text on the screen, calculating the print position.
@ -248,8 +269,9 @@ point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment, color_t
* @param fmt: printf style format string
* @return text width and height as point_t coordinates
*/
point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY, uint16_t startX,
fontSize_t size, textAlign_t alignment, color_t color, const char* fmt, ... );
point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY,
uint16_t startX, fontSize_t size, textAlign_t alignment,
color_t color, const char* fmt, ... );
/**
* Prints an error message surrounded by a red box on the screen.

Wyświetl plik

@ -385,6 +385,13 @@ static inline uint16_t get_reset_x(textAlign_t alignment, uint16_t line_size,
return 0;
}
uint8_t gfx_getFontHeight(fontSize_t size)
{
GFXfont f = fonts[size];
GFXglyph glyph = f.glyph['|' - f.first];
return glyph.height;
}
point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment,
color_t color, const char *buf)
{
@ -503,6 +510,13 @@ point_t gfx_printLine(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY,
uint16_t step = (endY - startY) / (tot + 1);
uint16_t printY = startY + (step * cur);
// Estimate font height by reading the gliph | height
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};
return gfx_printBuffer(start, size, alignment, color, text);
}