From 7e17dcf7d841d1b62798ee878cc5e08554e51b65 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 27 Apr 2023 17:07:08 +0200 Subject: [PATCH] Move rich text escape methods to helper .h .cpp files --- CMakeLists.txt | 1 + src/richtexthelper.cpp | 18 ++++++++++++++++++ src/richtexthelper.h | 8 ++++++++ src/richtextrenderer.cpp | 11 ----------- src/richtextrenderer.h | 3 --- 5 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 src/richtexthelper.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e00beeb..3da5c70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ set(sources src/screenmanager.cpp src/splitgraphdisplay.cpp src/popupdisplay.cpp + src/richtexthelper.cpp src/richtextrenderer.cpp src/icons/back.cpp src/icons/checked.cpp diff --git a/src/richtexthelper.cpp b/src/richtexthelper.cpp new file mode 100644 index 0000000..8f47f72 --- /dev/null +++ b/src/richtexthelper.cpp @@ -0,0 +1,18 @@ +#include "richtexthelper.h" + +// 3rdparty lib includes +#include + +namespace espgui { + +void richTextEscape(std::string &subject) +{ + cpputils::stringReplaceAll('&', "&&", subject); +} + +std::string richTextEscape(std::string_view subject) +{ + return cpputils::stringReplaceAll('&', "&&", subject); +} + +} // namespace espgui diff --git a/src/richtexthelper.h b/src/richtexthelper.h index 31a2772..559d7dd 100644 --- a/src/richtexthelper.h +++ b/src/richtexthelper.h @@ -1,5 +1,9 @@ #pragma once +// system includes +#include +#include + namespace espgui { namespace colors { constexpr char RED[] = "&1"; // #ff0000 (TFT_RED) @@ -17,4 +21,8 @@ constexpr char SMALL[] = "&s"; // tft.setTextFont(2) constexpr char MEDIUM[] = "&m"; // tft.setTextFont(4) constexpr char RESTORE[] = "&f"; // restore original font } // namespace fonts + +void richTextEscape(std::string &subject); +std::string richTextEscape(std::string_view subject); + } // namespace espgui diff --git a/src/richtextrenderer.cpp b/src/richtextrenderer.cpp index 0c76857..78f43f2 100644 --- a/src/richtextrenderer.cpp +++ b/src/richtextrenderer.cpp @@ -4,7 +4,6 @@ #include // 3rdparty lib includes -#include #include // local includes @@ -13,16 +12,6 @@ namespace espgui { -void richTextEscape(std::string &subject) -{ - cpputils::stringReplaceAll('&', "&&", subject); -} - -std::string richTextEscape(std::string_view subject) -{ - return cpputils::stringReplaceAll('&', "&&", 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}; diff --git a/src/richtextrenderer.h b/src/richtextrenderer.h index 59631e2..88a544f 100644 --- a/src/richtextrenderer.h +++ b/src/richtextrenderer.h @@ -9,9 +9,6 @@ namespace espgui { class TftInterface; class FontRenderer; } namespace espgui { -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);