From 56faf93543c82e9182c16bf781facfeffddc944f Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Jun 2022 11:15:02 +0200 Subject: [PATCH 1/3] Added richtext colors for easier use --- src/richtexthelper.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/richtexthelper.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 -- 2.50.1 From c8c276691b2ff7e2e45d2fdd1ec2005f042eaded Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Jun 2022 11:15:14 +0200 Subject: [PATCH 2/3] Added TextWithHighlightedValueHelper --- CMakeLists.txt | 1 + src/textwithvaluehelper.h | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) 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 -- 2.50.1 From 2fe1d1ed2875252974e181fcd32719ca72a31399 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Jun 2022 13:40:01 +0200 Subject: [PATCH 3/3] Removed unused libs (ADL) --- src/textwithvaluehelper.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/textwithvaluehelper.h b/src/textwithvaluehelper.h index b16b565..81cb3ce 100644 --- a/src/textwithvaluehelper.h +++ b/src/textwithvaluehelper.h @@ -4,8 +4,6 @@ #include #include #include -#include -#include // local includes #include "textinterface.h" @@ -23,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()))); } @@ -39,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()))); } @@ -62,8 +56,6 @@ struct TextWithHighlightedValueHelper : public Taccessor, public virtual TextInt { using cpputils::toString; using espcpputils::toString; - using wifi_stack::toString; - using espchrono::toString; return fmt::format("{} {}{}", Tprefix, Tguilib_color, richTextEscape(toString(Taccessor::getValue()))); } @@ -78,8 +70,6 @@ struct ChangeableTextWithHighlightedValueHelper : public Taccessor, public virtu { using cpputils::toString; using espcpputils::toString; - using wifi_stack::toString; - using espchrono::toString; return fmt::format("{} {}{}", m_prefix, Tguilib_color, richTextEscape(toString(Taccessor::getValue()))); } -- 2.50.1