diff options
Diffstat (limited to 'src/gdisp')
-rw-r--r-- | src/gdisp/gdisp.c | 20 | ||||
-rw-r--r-- | src/gdisp/gdisp.h | 17 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 43b470b2..6e431441 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -3324,12 +3324,26 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co return mf_character_width(font, c); } + coord_t gdispGetStringWidthCount(const char* str, font_t font, uint16_t count) { + if (!str) { + return 0; + } + + // No mutex required as we only read static data + #if GDISP_NEED_TEXT_KERNING + return mf_get_string_width(font, str, count, TRUE); + #else + return mf_get_string_width(font, str, count, FALSE); + #endif + } + coord_t gdispGetStringWidth(const char* str, font_t font) { - if (!str) + if (!str) { return 0; + } - /* No mutex required as we only read static data */ - return mf_get_string_width(font, str, 0, 0); + // No mutex required as we only read static data + return gdispGetStringWidthCount(str, font, 0); } #endif diff --git a/src/gdisp/gdisp.h b/src/gdisp/gdisp.h index 298258cb..b096cb3d 100644 --- a/src/gdisp/gdisp.h +++ b/src/gdisp/gdisp.h @@ -978,7 +978,22 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co coord_t gdispGetCharWidth(char c, font_t font); /** - * @brief Get the pixel width of a string. + * @brief Get the pixel width of a string of a given length. + * @return The width of the string in pixels. + * @pre GDISP_NEED_TEXT must be TRUE in your gfxconf.h + * + * @note Passing 0 to count has the same effect as calling gdispGetStringWidt() + * + * @param[in] str The string to measure + * @param[in] font The font to use + * @param[in] count The number of characters to take into account + * + * @api + */ + coord_t gdispGetStringWidthCount(const char* str, font_t font, uint16_t count); + + /** + * @brief Get the pixel width of an entire string. * @return The width of the string in pixels. * @pre GDISP_NEED_TEXT must be TRUE in your gfxconf.h * |