7#include "TinyGPU/Color/RGB565.h"
8#include "TinyGPU/Color/RGB666.h"
9#include "TinyGPU/Color/RGB888.h"
10#include "TinyMaterialDesign/Core/Widget.h"
11#include "TinyGPU/Font/LinePrinter.h"
16
17
18
19
20
21
22
23
24
25
26
27
31 using ActionCountFn = std::function<
int()>;
32 using ActionAtFn = std::function<
Widget<RGB_T>&(
int index)>;
36 this->bounds = bounds;
39 void setMessage(
const char* message) { message_ = message !=
nullptr ? message :
""; }
44 actions_.push_back(&action);
45 if (
this->theme_ !=
nullptr) action.setTheme(*
this->theme_);
50 actionCountFn_ = std::move(count);
51 actionAtFn_ = std::move(at);
55 Widget<RGB_T>::setTheme(theme);
56 for (Widget<RGB_T>* action : actions_) {
57 if (action !=
nullptr) action->setTheme(theme);
64 Bounds actionRect(
int index,
int count, int32_t width = 80, int32_t height = 32)
const {
65 const int32_t pad = 8;
66 const int32_t totalWidth = count * width + (count - 1) * pad;
67 const int32_t startX =
this->bounds.right() - pad - totalWidth;
68 const int32_t y =
this->bounds.bottom() - pad - height;
69 return Bounds(startX + index * (width + pad)
, y
, width
, height
);
72 void draw(tinygpu::ISurface<RGB_T>& target)
override {
73 target.fillRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
74 toPx(
this->bounds.h),
this->theme().colors.surfaceVariant);
75 target.drawLine(toPx(
this->bounds.x), toPx(
this->bounds.bottom() - 1), toPx(
this->bounds.right()),
76 toPx(
this->bounds.bottom() - 1),
this->theme().colors.outline);
78 const int32_t pad =
this->theme().spacing;
79 const int32_t rightEdge =
this->bounds.right() - pad;
80 const size_t rightBorder = rightEdge <
static_cast<int32_t>(target.width())
81 ? target.width() -
static_cast<size_t>(rightEdge)
85 target.pushClipRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
86 toPx(
this->bounds.h));
87 tinygpu::LinePrinter<RGB_T> printer;
88 printer.setFont(*
this->theme().typography.body);
89 printer.setTarget(target);
90 printer.setColor(
this->theme().colors.onSurfaceVariant);
91 printer.setTopBorder(toPx(
this->bounds.y + pad));
92 printer.setLeftBorder(toPx(
this->bounds.x + pad));
93 printer.setRightBorder(rightBorder);
94 printer.print(message_.c_str());
97 const int count = actionCount();
98 for (
int i = 0; i < count; ++i) {
99 Widget<RGB_T>* action = actionAt(i);
100 if (action->visible) action->draw(target);
104 bool onGesture(
const tinygpu::GestureEvent& event)
override {
105 const int count = actionCount();
106 for (
int i = 0; i < count; ++i) {
107 Widget<RGB_T>* action = actionAt(i);
108 if (action->enabled && action->bounds.contains(event.point.x, event.point.y)) {
109 return action->onGesture(event);
116 bool changed =
false;
117 const int count = actionCount();
118 for (
int i = 0; i < count; ++i) changed |= actionAt(i)->update(nowMs);
125 const int count = actionCount();
126 for (
int i = 0; i < count; ++i) {
127 Widget<RGB_T>* action = actionAt(i);
128 if (action->enabled && action->bounds.contains(x, y))
return action->isDraggableAt(x, y);
134 int actionCount()
const {
135 return actionCountFn_ ? actionCountFn_() :
static_cast<
int>(actions_.size());
138 Widget<RGB_T>* actionAt(
int index)
const {
140 Widget<RGB_T>& action = actionAtFn_(index);
141 if (
this->theme_ !=
nullptr) action.setTheme(*
this->theme_);
144 return actions_[
static_cast<size_t>(index)];
147 std::string message_;
148 std::vector<Widget<RGB_T>*> actions_;
149 ActionCountFn actionCountFn_;
150 ActionAtFn actionAtFn_;
Persistent, non-modal inline message with text actions - Material's "banner", e.g....
Definition: Banner.h:29
Banner(Bounds bounds, const char *message)
Definition: Banner.h:35
bool isDraggableAt(int32_t x, int32_t y) const override
Definition: Banner.h:124
bool onGesture(const tinygpu::GestureEvent &event) override
Handles one gesture event. Returns true if this widget consumed it.
Definition: Banner.h:104
Bounds actionRect(int index, int count, int32_t width=80, int32_t height=32) const
Definition: Banner.h:64
void setActionProvider(ActionCountFn count, ActionAtFn at)
Switches to callback-driven actions - see the class comment.
Definition: Banner.h:49
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: Banner.h:72
void setMessage(const char *message)
Definition: Banner.h:39
bool update(uint32_t nowMs) override
Definition: Banner.h:115
void setTheme(const MaterialTheme< RGB_T > &theme) override
Definition: Banner.h:54
void addAction(Widget< RGB_T > &action)
Definition: Banner.h:43
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
Bundles a color scheme, shape tokens, typography, and spacing into one theme, passed to widgets so th...
Definition: MaterialTheme.h:50