5#include "TinyGPU/Color/RGB565.h"
6#include "TinyGPU/Color/RGB666.h"
7#include "TinyGPU/Color/RGB888.h"
8#include "TinyMaterialDesign/Core/Widget.h"
9#include "TinyMaterialDesign/Widgets/IconButton.h"
10#include "TinyMaterialDesign/Widgets/Label.h"
15
16
17
18
19
20
25 ListItem(
Bounds bounds,
const char* title, IconPainter<RGB_T> icon =
nullptr)
27 this->bounds = bounds;
32 void setTitle(
const char* title) { title_ = title; }
33 void setIcon(IconPainter<RGB_T> icon) { icon_ = icon; }
43 void draw(tinygpu::ISurface<RGB_T>& target)
override {
44 RGB_T background = selected_ ?
this->theme().colors.secondaryContainer :
this->theme().colors.surface;
45 RGB_T foreground = selected_ ?
this->theme().colors.onSecondaryContainer :
this->theme().colors.onSurfaceVariant;
46 RGB_T textColor = selected_ ?
this->theme().colors.onSecondaryContainer :
this->theme().colors.onSurface;
48 background = blend(background,
this->theme().colors.surface, 0.5f);
49 foreground = blend(foreground,
this->theme().colors.surface, 0.5f);
50 textColor = blend(textColor,
this->theme().colors.surface, 0.5f);
53 const int32_t margin = 8;
54 const Bounds pill =
this->bounds.inset(margin);
57 target.fillRoundRect(toPx(pill.x), toPx(pill.y), toPx(pill.w), toPx(pill.h),
58 toPx(
this->theme().shape.full), background);
61 const int32_t pad = 16;
62 const int32_t iconSize = pill
.h - 16;
63 int32_t textX = pill
.x + pad;
64 if (icon_ !=
nullptr) {
65 const Bounds iconRect
(pill
.x + pad
, pill
.y + (pill
.h - iconSize) / 2
, iconSize
, iconSize
);
66 icon_(target, iconRect, foreground, 2);
70 tinygpu::IFont<RGB_T>& font = *fontForTypographyRole(role_,
this->theme());
71 const int32_t textY = pill.centerY() -
static_cast<int32_t>(font.getHeight(1)) / 2;
72 font.drawText(target,
static_cast<int16_t>(textX),
static_cast<int16_t>(textY),
73 title_.c_str(), textColor, background,
false);
76 bool onGesture(
const tinygpu::GestureEvent& event)
override {
77 if (!isTapGesture(event.type))
return false;
78 if (onClick) onClick();
84 IconPainter<RGB_T> icon_ =
nullptr;
85 bool selected_ =
false;
Tappable row: optional leading icon + title, with a selected state.
Definition: ListItem.h:22
void setTypographyRole(TypographyRole role)
Definition: ListItem.h:41
ListItem(Bounds bounds, const char *title, IconPainter< RGB_T > icon=nullptr)
Definition: ListItem.h:25
bool onGesture(const tinygpu::GestureEvent &event) override
Handles one gesture event. Returns true if this widget consumed it.
Definition: ListItem.h:76
void setIcon(IconPainter< RGB_T > icon)
Definition: ListItem.h:33
bool selected() const
Definition: ListItem.h:35
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: ListItem.h:43
void setTitle(const char *title)
Definition: ListItem.h:32
void setSelected(bool selected)
Definition: ListItem.h:36
std::function< void()> onClick
Definition: ListItem.h:30
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 right() const
Definition: Bounds.h:30
Bounds(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: Bounds.h:28
int32_t h
Definition: Bounds.h:25
int32_t y
Definition: Bounds.h:23
int32_t x
Definition: Bounds.h:22