Added TextWithHighlightedValueHelper
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user