Moved all the bobbycar gui code into this library
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace espgui {
|
||||
class TextInterface {
|
||||
public:
|
||||
virtual std::string text() const = 0;
|
||||
};
|
||||
|
||||
class EmptyText : public virtual TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override { return {}; }
|
||||
};
|
||||
|
||||
template<const char *Ttext>
|
||||
class StaticText : public virtual TextInterface
|
||||
{
|
||||
public:
|
||||
static constexpr const char *STATIC_TEXT = Ttext;
|
||||
|
||||
std::string text() const override { return Ttext; }
|
||||
};
|
||||
|
||||
class ChangeableText : public virtual TextInterface
|
||||
{
|
||||
public:
|
||||
std::string text() const override { return m_title; }
|
||||
void setTitle(std::string &&title) { m_title = std::move(title); }
|
||||
void setTitle(const std::string &title) { m_title = title; }
|
||||
|
||||
private:
|
||||
std::string m_title;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class CachedText : public virtual T
|
||||
{
|
||||
public:
|
||||
std::string text() const override
|
||||
{
|
||||
if (!m_loaded)
|
||||
{
|
||||
m_text = T::text();
|
||||
m_loaded = true;
|
||||
}
|
||||
|
||||
return m_text;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable bool m_loaded{};
|
||||
mutable std::string m_text;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class StaticallyCachedText : public virtual T
|
||||
{
|
||||
public:
|
||||
std::string text() const override
|
||||
{
|
||||
static const auto text = T::text();
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
template<const char *Tprefix, typename Taccessor>
|
||||
struct TextWithValueHelper : public virtual TextInterface
|
||||
{
|
||||
std::string text() const override { return fmt::format("{} {}", Tprefix, Taccessor{}.getValue()); }
|
||||
};
|
||||
} // namespace espgui
|
||||
Reference in New Issue
Block a user