4#include "TinyMaterialDesign/Core/Widget.h"
5#include "TinyMaterialDesign/Widgets/Label.h"
10
11
12
13
14
15
16
17
18
19
20
27 this->bounds = bounds;
30 void setCaption(
const char* caption) { caption_ = caption; }
31 void setValue(
const char* value) { value_ = value; }
32 const std::string&
value()
const {
return value_; }
33 void setSub(
const char* sub) { sub_ = sub; }
43 void draw(tinygpu::ISurface<RGB_T>& target)
override {
45 const Bounds& b =
this->bounds;
46 const RGB_T bg =
tonal ? t.colors.surfaceVariant : t.colors.surface;
47 const size_t radius = toPx(t.shape.medium);
48 target.fillRoundRect(toPx(b.x), toPx(b.y), toPx(b.w), toPx(b.h), radius, bg);
49 if (!tonal) target.drawRoundRect(toPx(b.x), toPx(b.y), toPx(b.w), toPx(b.h), radius, t.colors.outline);
51 tinygpu::IFont<RGB_T>& small = *t.typography.label;
52 const int32_t x = b
.x + 5;
53 small.drawText(target,
static_cast<int16_t>(x),
static_cast<int16_t>(b.y + 4), caption_.c_str(),
54 t.colors.onSurfaceVariant, bg,
false);
57 tinygpu::IFont<RGB_T>* fonts[3] = {fontForTypographyRole(valueRole, t), t.typography.body, t.typography.label};
58 tinygpu::IFont<RGB_T>* font = fonts[2];
59 for (tinygpu::IFont<RGB_T>* f : fonts) {
60 if (
static_cast<int32_t>(f->measureTextWidth(value_.c_str())) <= b.w - 8) {
65 const int32_t smallH =
static_cast<int32_t>(small.getHeight(1));
66 const int32_t valueY = sub_.empty() ? b.bottom() - 5 -
static_cast<int32_t>(font->getHeight(1))
67 : b.y + 4 + smallH + 3;
68 font->drawText(target,
static_cast<int16_t>(x),
static_cast<int16_t>(valueY), value_.c_str(),
69 hasAccent_ ? accent_ : t.colors.primary, bg,
false);
71 small.drawText(target,
static_cast<int16_t>(x),
static_cast<int16_t>(b.bottom() - 4 - smallH), sub_.c_str(),
72 t.colors.onSurfaceVariant, bg,
false);
78 std::string value_ =
"--";
81 bool hasAccent_ =
false;
A small tile with one value: a caption at the top, the value in an accent color and an optional unit ...
Definition: StatTile.h:22
StatTile(Bounds bounds, const char *caption, const char *sub="")
Definition: StatTile.h:26
bool tonal
Filled with surfaceVariant instead of outlined.
Definition: StatTile.h:39
void setValue(const char *value)
Definition: StatTile.h:31
const std::string & value() const
Definition: StatTile.h:32
void setSub(const char *sub)
Definition: StatTile.h:33
void setCaption(const char *caption)
Definition: StatTile.h:30
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: StatTile.h:43
TypographyRole valueRole
Font of the value (default: title, which falls back to smaller fonts).
Definition: StatTile.h:41
void setAccent(RGB_T color)
Definition: StatTile.h:34
StatTile(const char *caption, const char *sub="")
Definition: StatTile.h:25
Definition: AnchorLayout.h:4
TypographyRole
Definition: Label.h:11
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21
int32_t x
Definition: Bounds.h:22
Bundles a color scheme, shape tokens, typography, and spacing into one theme, passed to widgets so th...
Definition: MaterialTheme.h:50