4#include "TinyGPU/Color/RGB565.h"
5#include "TinyGPU/Color/RGB666.h"
6#include "TinyGPU/Color/RGB888.h"
7#include "TinyMaterialDesign/Core/Widget.h"
12
13
14
15
16
17
18
19
25 this->bounds = bounds;
26 if (text !=
nullptr) text_ = text;
29 void setText(
const char* text) { text_ = text !=
nullptr ? text :
""; }
30 const std::string&
text()
const {
return text_; }
32 void draw(tinygpu::ISurface<RGB_T>& target)
override {
33 RGB_T background =
this->theme().colors.error;
34 RGB_T foreground =
this->theme().colors.onError;
36 background = blend(background,
this->theme().colors.surface, 0.5f);
37 foreground = blend(foreground,
this->theme().colors.surface, 0.5f);
41 const int32_t diameter =
this->bounds.w <
this->bounds.h ?
this->bounds.w :
this->bounds.h;
42 target.fillCircle(toPx(
this->bounds.centerX()), toPx(
this->bounds.centerY()),
43 toPx(diameter / 2), background);
47 const size_t radius = toPx(
this->bounds.h / 2);
48 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
49 toPx(
this->bounds.h), radius, background);
51 tinygpu::IFont<RGB_T>& font = *
this->theme().typography.label;
52 const size_t textWidth = font.measureTextWidth(text_.c_str());
53 const int32_t textX =
this->bounds.centerX() -
static_cast<int32_t>(textWidth) / 2;
54 const int32_t textY =
this->bounds.centerY() -
static_cast<int32_t>(font.getHeight(1)) / 2;
55 font.drawText(target,
static_cast<int16_t>(textX),
static_cast<int16_t>(textY), text_.c_str(),
56 foreground, background,
false);
Small status marker, typically overlaid on an icon's corner.
Definition: Badge.h:21
void setText(const char *text)
Definition: Badge.h:29
Badge(Bounds bounds, const char *text=nullptr)
Definition: Badge.h:24
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: Badge.h:32
const std::string & text() const
Definition: Badge.h:30
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21