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
20
27 void showFor(
Bounds anchor,
const char* text, uint32_t durationMs = 1500) {
28 text_ = text !=
nullptr ? text :
"";
29 durationMs_ = durationMs;
31 tinygpu::IFont<RGB_T>* font =
this->theme_ !=
nullptr ?
this->theme().typography.label :
nullptr;
32 const int32_t textWidth = font !=
nullptr ?
static_cast<int32_t>(font->measureTextWidth(text_.c_str())) : 0;
33 const int32_t textHeight = font !=
nullptr ?
static_cast<int32_t>(font->getHeight(1)) : 12;
34 const int32_t pad = 8;
35 const int32_t w = textWidth + pad * 2;
36 const int32_t h = textHeight + pad;
43 void hide() {
this->visible =
false; }
45 void draw(tinygpu::ISurface<RGB_T>& target)
override {
46 const RGB_T background =
this->theme().colors.onSurface;
47 const RGB_T foreground =
this->theme().colors.surface;
48 const size_t radius = toPx(
this->theme().shape.small);
50 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
51 toPx(
this->bounds.h), radius, background);
53 tinygpu::IFont<RGB_T>& font = *
this->theme().typography.label;
54 const size_t textWidth = font.measureTextWidth(text_.c_str());
55 const int32_t textX =
this->bounds.centerX() -
static_cast<int32_t>(textWidth) / 2;
56 const int32_t textY =
this->bounds.centerY() -
static_cast<int32_t>(font.getHeight(1)) / 2;
57 font.drawText(target,
static_cast<int16_t>(textX),
static_cast<int16_t>(textY), text_.c_str(),
58 foreground, background,
false);
61 bool update(uint32_t nowMs)
override {
62 if (!
this->visible)
return false;
68 if (nowMs - startMs_ >= durationMs_) {
69 this->visible =
false;
77 uint32_t durationMs_ = 1500;
78 bool started_ =
false;
79 uint32_t startMs_ = 0;
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21
Bounds(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: Bounds.h:28
int32_t centerX() const
Definition: Bounds.h:32
int32_t y
Definition: Bounds.h:23