4#include "TinyGPU/Color/RGB565.h"
5#include "TinyGPU/Color/RGB666.h"
6#include "TinyGPU/Color/RGB888.h"
7#include "TinyGPU/Font/LinePrinter.h"
8#include "TinyMaterialDesign/Core/Widget.h"
18 Card(
Bounds bounds,
const char* title =
nullptr,
const char* body =
nullptr) {
39 this->bounds = bounds;
53 void draw(tinygpu::ISurface<RGB_T>& target)
override {
54 const size_t radius = toPx(largeCorners ?
this->theme().shape.large :
this->theme().shape.medium);
57 const RGB_T shadow = blend(
this->theme().colors.surface,
this->theme().colors.onBackground, 0.30f);
58 target.fillRoundRect(toPx(
this->bounds.x + 1), toPx(
this->bounds.y + 2),
59 toPx(
this->bounds.w), toPx(
this->bounds.h), radius, shadow);
62 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
63 toPx(
this->bounds.h), radius,
this->theme().colors.surface);
64 target.drawRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
65 toPx(
this->bounds.h), radius, hasOutline_ ? outline_ :
this->theme().colors.outline);
67 const int32_t pad =
this->theme().spacing;
68 int32_t cursorY =
this->bounds.y + pad;
71 tinygpu::IFont<RGB_T>& titleFont = *
this->theme().typography.title;
72 titleFont.drawText(target,
static_cast<int16_t>(
this->bounds.x + pad),
73 static_cast<int16_t>(cursorY), title_.c_str(),
this->theme().colors.onSurface,
74 this->theme().colors.surface,
false);
75 cursorY +=
static_cast<int32_t>(titleFont.getHeight(1)) + pad / 2;
83 const int32_t rightEdge =
this->bounds.right() - pad;
84 const size_t rightBorder =
85 rightEdge <
static_cast<int32_t>(target.width())
86 ? target.width() -
static_cast<size_t>(rightEdge)
89 tinygpu::LinePrinter<RGB_T> printer;
90 printer.setFont(*
this->theme().typography.body);
91 printer.setTarget(target);
92 printer.setColor(
this->theme().colors.onSurfaceVariant);
93 printer.setTopBorder(toPx(cursorY));
94 printer.setLeftBorder(toPx(
this->bounds.x + pad));
95 printer.setRightBorder(rightBorder);
96 printer.print(body_.c_str());
103 bool hasTitle_ =
false;
104 bool hasBody_ =
false;
106 bool hasOutline_ =
false;
Elevated rounded-rect container with an optional title and word-wrapped body text.
Definition: Card.h:15
void clearOutlineColor()
Definition: Card.h:48
void setBody(const char *body)
Definition: Card.h:33
bool largeCorners
Corner radius from the theme's large shape instead of the medium one.
Definition: Card.h:51
bool elevated
Definition: Card.h:26
Card(Bounds bounds, const char *title=nullptr, const char *body=nullptr)
Definition: Card.h:18
void setBounds(Bounds bounds)
Definition: Card.h:38
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: Card.h:53
void setOutlineColor(RGB_T color)
Definition: Card.h:44
void setTitle(const char *title)
Definition: Card.h:28
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21