Color/Font utilities and new TextWithValueHelper #14

Merged
CommanderRedYT merged 3 commits from better-ui into main 2022-06-09 16:12:15 +02:00
3 changed files with 57 additions and 6 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

20
src/richtexthelper.h Normal file
View File

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

View File

@ -4,11 +4,10 @@
#include <fmt/core.h>
#include <strutils.h>
#include <espstrutils.h>
#include <espwifiutils.h>
#include <espchrono.h>
// 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<const char *Tprefix, typename Taccessor, const char *Tguilib_color = espgui::colors::GREY>
struct TextWithHighlightedValueHelper : public Taccessor, public virtual TextInterface
{
0xFEEDC0DE64 commented 2022-06-09 13:16:03 +02:00 (Migrated from github.com)
Review

muss die gui lib explicit jede meiner anderen libs erwähnen? was wurde aus ferdis ADL

muss die gui lib explicit jede meiner anderen libs erwähnen? was wurde aus ferdis ADL
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<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;
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