From 2f8ccd3d104cd6067d8a13731466a2d8df23d969 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Thu, 3 Feb 2022 20:41:59 +0100 Subject: [PATCH] Added ChangeableTextWithValueHelper --- src/textwithvaluehelper.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/textwithvaluehelper.h b/src/textwithvaluehelper.h index 56884f9..7b506cc 100644 --- a/src/textwithvaluehelper.h +++ b/src/textwithvaluehelper.h @@ -29,4 +29,27 @@ struct TextWithValueHelper : public Taccessor, public virtual TextInterface } }; +template +struct ChangeableTextWithValueHelper : 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, 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