Added TextWithHighlightedValueHelper

This commit is contained in:
CommanderRedYT
2022-06-09 11:15:14 +02:00
parent 56faf93543
commit c8c276691b
2 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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<const char *Tprefix, typename Taccessor, const char *Tguilib_color = espgui::colors::GREY>
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<typename Taccessor, const char *Tguilib_color = espgui::colors::GREY>
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