4#include "TinyGPU/Color/RGB565.h"
5#include "TinyGPU/Color/RGB666.h"
6#include "TinyGPU/Color/RGB888.h"
7#include "TinyMaterialDesign/Core/Widget.h"
17template <
typename RGB_T>
21 return theme.typography.headline;
23 return theme.typography.title;
25 return theme.typography.label;
28 return theme.typography.body;
39 :
text_(
text), role_(role), align_(align) {
40 this->bounds = bounds;
43 void setText(
const char* text) { text_ = text; }
44 const std::string&
text()
const {
return text_; }
48 colorOverride_ = color;
49 hasColorOverride_ =
true;
55 hasBackground_ =
true;
65 void setFont(tinygpu::IFont<RGB_T>* font) { font_ = font; }
68 void draw(tinygpu::ISurface<RGB_T>& target)
override {
69 tinygpu::IFont<RGB_T>& font = font_ !=
nullptr ? *font_ : *fontForTypographyRole(role_,
this->theme());
70 RGB_T color = hasColorOverride_ ? colorOverride_
71 : variant_ ?
this->theme().colors.onSurfaceVariant
72 :
this->theme().colors.onSurface;
73 if (!
this->enabled) color = blend(color,
this->theme().colors.surface, 0.5f);
75 const size_t textWidth = font.measureTextWidth(text_.c_str());
76 const size_t textHeight = font.getHeight(1);
77 const int32_t textX = align_ == TextAlign::kCenter
78 ?
this->bounds.centerX() -
static_cast<int32_t>(textWidth) / 2
80 const int32_t textY =
this->bounds.centerY() -
static_cast<int32_t>(textHeight) / 2;
82 const RGB_T background = hasBackground_ ? background_
83 : onBackground_ ?
this->theme().colors.background
84 :
this->theme().colors.surface;
85 font.drawText(target,
static_cast<int16_t>(textX),
static_cast<int16_t>(textY),
86 text_.c_str(), color, background,
false);
93 RGB_T colorOverride_{};
94 bool hasColorOverride_ =
false;
96 bool hasBackground_ =
false;
97 bool onBackground_ =
false;
98 bool variant_ =
false;
99 tinygpu::IFont<RGB_T>* font_ =
nullptr;
Single line of themed, non-interactive text.
Definition: Label.h:34
void setBackgroundColor(RGB_T color)
Definition: Label.h:53
void setRole(TypographyRole role)
Definition: Label.h:45
tinygpu::IFont< RGB_T > * font() const
Definition: Label.h:66
void setText(const char *text)
Definition: Label.h:43
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: Label.h:68
void setVariantColor(bool variant)
Definition: Label.h:61
void setColor(RGB_T color)
Definition: Label.h:47
const std::string & text() const
Definition: Label.h:44
void setFont(tinygpu::IFont< RGB_T > *font)
Definition: Label.h:65
void setOnBackground(bool onBackground)
Draw the text on the theme's page background instead of the surface.
Definition: Label.h:58
Label(Bounds bounds, const char *text, TypographyRole role=TypographyRole::kBody, TextAlign align=TextAlign::kStart)
Definition: Label.h:37
void setAlign(TextAlign align)
Definition: Label.h:46
Definition: AnchorLayout.h:4
TypographyRole
Definition: Label.h:11
tinygpu::IFont< RGB_T > * fontForTypographyRole(TypographyRole role, const MaterialTheme< RGB_T > &theme)
Definition: Label.h:18
TextAlign
Definition: Label.h:12
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21