Files
MuditaOS/module-gui/gui/widgets/TextFormat.hpp
Adam 07b243a084 Egd-3408 Rich text (#712)
* EGD-3408 gui::Text Rich text parser added with pugixml tree & tree walker

* EGD-3408 Fitted code in
2020-09-23 21:03:57 +02:00

59 lines
1.3 KiB
C++

#pragma once
#include "Alignment.hpp"
#include <Color.hpp>
#include <functional>
#include <string>
namespace gui
{
class RawFont;
class TextFormat
{
private:
mutable RawFont *font = nullptr;
Color color = ColorFullBlack;
Alignment alignment = Alignment(Alignment::Horizontal::Left);
static constexpr auto setter = [](auto &local, auto &next) {
if (local != next) {
local = next;
}
};
public:
TextFormat(const RawFont *font, Color color = {}) : font(const_cast<RawFont *>(font)), color(color){};
TextFormat(const TextFormat &) = default;
[[nodiscard]] auto getFont() const
{
return font;
}
[[nodiscard]] auto getColor() const
{
return color;
}
// sets font
// @note triggers onFormat change
void setFont(RawFont *font)
{
setter(this->font, font);
}
// sets color
// @note triggers onFormat change
void setColor(Color color)
{
setter(this->color, color);
}
void setAlignment(Alignment alignment)
{
setter(this->alignment, alignment);
}
auto str() const -> std::string;
};
}; // namespace gui