diff --git a/src/richtextrenderer.cpp b/src/richtextrenderer.cpp index a657fd7..0c76857 100644 --- a/src/richtextrenderer.cpp +++ b/src/richtextrenderer.cpp @@ -26,7 +26,11 @@ std::string richTextEscape(std::string_view subject) int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) { FontRenderer fontRenderer{tft}; + return renderRichText(tft, fontRenderer, str, poX, poY, color, bgcolor, font); +} +int16_t renderRichText(TftInterface &tft, FontRenderer &fontRenderer, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font) +{ if (str.empty()) return 0; diff --git a/src/richtextrenderer.h b/src/richtextrenderer.h index bcfeed5..59631e2 100644 --- a/src/richtextrenderer.h +++ b/src/richtextrenderer.h @@ -5,7 +5,7 @@ #include // forward declares -namespace espgui { class TftInterface; } +namespace espgui { class TftInterface; class FontRenderer; } namespace espgui { @@ -13,5 +13,6 @@ void richTextEscape(std::string &subject); std::string richTextEscape(std::string_view subject); int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font); +int16_t renderRichText(TftInterface &tft, FontRenderer &fontRenderer, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font); } // namespace espgui diff --git a/src/widgets/label.cpp b/src/widgets/label.cpp index bdb4dbe..b1ca960 100644 --- a/src/widgets/label.cpp +++ b/src/widgets/label.cpp @@ -38,7 +38,7 @@ void Label::redraw(TftInterface &tft, FontRenderer &fontRenderer, std::string_vi !forceRedraw) return; - const auto renderedWidth = renderRichText(tft, str, m_x, m_y, color, bgcolor, font); + const auto renderedWidth = renderRichText(tft, fontRenderer, str, m_x, m_y, color, bgcolor, font); const auto renderedHeight = fontRenderer.fontHeight(font); if (renderedWidth < m_lastWidth)