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/richtexthelper.h b/src/richtexthelper.h new file mode 100644 index 0000000..31a2772 --- /dev/null +++ b/src/richtexthelper.h @@ -0,0 +1,20 @@ +#pragma once + +namespace espgui { +namespace colors { +constexpr char RED[] = "&1"; // #ff0000 (TFT_RED) +constexpr char GREEN[] = "&2"; // #00ff00 (TFT_GREEN) +constexpr char BLUE[] = "&3"; // #0000ff (TFT_BLUE) +constexpr char YELLOW[] = "&4"; // #ffff00 (TFT_YELLOW) +constexpr char BLACK[] = "&5"; // #000000 (TFT_BLACK) +constexpr char WHITE[] = "&6"; // #ffffff (TFT_WHITE) +constexpr char GREY[] = "&7"; // #888888 (TFT_GREY) +constexpr char RESET[] = "&0"; // reset to previous color set by tft.setTextColor() +} // namespace colors + +namespace fonts { +constexpr char SMALL[] = "&s"; // tft.setTextFont(2) +constexpr char MEDIUM[] = "&m"; // tft.setTextFont(4) +constexpr char RESTORE[] = "&f"; // restore original font +} // namespace fonts +} // namespace espgui diff --git a/src/textwithvaluehelper.h b/src/textwithvaluehelper.h index 7b506cc..81cb3ce 100644 --- a/src/textwithvaluehelper.h +++ b/src/textwithvaluehelper.h @@ -4,11 +4,10 @@ #include #include #include -#include -#include // local includes #include "textinterface.h" +#include "richtexthelper.h" #include "richtextrenderer.h" namespace espgui { @@ -22,8 +21,6 @@ struct TextWithValueHelper : public Taccessor, public virtual TextInterface { using cpputils::toString; using espcpputils::toString; - using wifi_stack::toString; - using espchrono::toString; return fmt::format("{} {}", Tprefix, richTextEscape(toString(Taccessor::getValue()))); } @@ -38,8 +35,6 @@ struct ChangeableTextWithValueHelper : public Taccessor, public virtual TextInte { using cpputils::toString; using espcpputils::toString; - using wifi_stack::toString; - using espchrono::toString; return fmt::format("{} {}", m_prefix, richTextEscape(toString(Taccessor::getValue()))); } @@ -52,4 +47,39 @@ 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; + + 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; + + 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