diff --git a/CMakeLists.txt b/CMakeLists.txt index 237bfd9..96fac73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ set(headers src/menuitem.h src/messagepopupdisplay.h src/popupdisplay.h + src/richtexthelper.h src/richtextrenderer.h src/screenmanager.h src/scrollinterface.h diff --git a/src/textwithvaluehelper.h b/src/textwithvaluehelper.h index 7b506cc..b16b565 100644 --- a/src/textwithvaluehelper.h +++ b/src/textwithvaluehelper.h @@ -9,6 +9,7 @@ // local includes #include "textinterface.h" +#include "richtexthelper.h" #include "richtextrenderer.h" namespace espgui { @@ -52,4 +53,43 @@ private: std::string m_prefix; }; +template +struct TextWithHighlightedValueHelper : public Taccessor, public virtual TextInterface +{ + using Taccessor::Taccessor; + + std::string text() const override + { + using cpputils::toString; + using espcpputils::toString; + using wifi_stack::toString; + using espchrono::toString; + + return fmt::format("{} {}{}", Tprefix, Tguilib_color, richTextEscape(toString(Taccessor::getValue()))); + } +}; + +template +struct ChangeableTextWithHighlightedValueHelper : public Taccessor, public virtual TextInterface +{ + using Taccessor::Taccessor; + + std::string text() const override + { + using cpputils::toString; + using espcpputils::toString; + using wifi_stack::toString; + using espchrono::toString; + + return fmt::format("{} {}{}", m_prefix, Tguilib_color, richTextEscape(toString(Taccessor::getValue()))); + } + + const std::string &prefix() const { return m_prefix; } + void setPrefix(std::string_view prefix) { m_prefix = std::string{prefix}; } + void setPrefix(std::string &&prefix) { m_prefix = std::move(prefix); } + +private: + std::string m_prefix; +}; + } // namespace espgui