6#include "TinyGPU/Color/RGB565.h"
7#include "TinyGPU/Color/RGB666.h"
8#include "TinyGPU/Color/RGB888.h"
9#include "TinyMaterialDesign/Core/Container.h"
10#include "TinyMaterialDesign/Core/Widget.h"
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
36 this->bounds = bounds;
41 this->bounds = bounds;
45 void setTitle(
const char* title) { title_ = title !=
nullptr ? title :
""; }
55 typename Container<RGB_T>::ChildAtFn at) {
56 items_.setChildProvider(std::move(count), std::move(at));
60 Widget<RGB_T>::setTheme(theme);
61 items_.setTheme(theme);
71 return Bounds(
this->bounds.x, contentTop() + index * height,
this->bounds.w, height);
74 void draw(tinygpu::ISurface<RGB_T>& target)
override {
75 drawBackground(target);
86 const size_t radius = toPx(
this->theme().shape.large);
90 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y), toPx(
this->bounds.w),
91 toPx(
this->bounds.h), radius,
this->theme().colors.surface);
92 const int32_t squareTop =
this->bounds.y +
static_cast<int32_t>(radius);
93 if (squareTop <
this->bounds.bottom()) {
94 target.fillRect(toPx(
this->bounds.x), toPx(squareTop), toPx(
this->bounds.w),
95 toPx(
this->bounds.bottom() - squareTop),
this->theme().colors.surface);
98 constexpr int32_t kHandleWidth = 32;
99 constexpr int32_t kHandleHeight = 4;
100 const int32_t handleY =
this->bounds.y + 8;
101 target.fillRoundRect(toPx(
this->bounds.centerX() - kHandleWidth / 2), toPx(handleY),
102 toPx(kHandleWidth), toPx(kHandleHeight), toPx(kHandleHeight / 2),
103 this->theme().colors.outline);
105 if (!title_.empty()) {
106 tinygpu::IFont<RGB_T>& font = *
this->theme().typography.title;
107 const int32_t pad =
this->theme().spacing;
108 font.drawText(target,
static_cast<int16_t>(
this->bounds.x + pad * 2),
109 static_cast<int16_t>(handleY + kHandleHeight + pad), title_.c_str(),
110 this->theme().colors.onSurface,
this->theme().colors.surface,
false);
114 int childCount()
const override {
return items_.childCount(); }
115 Widget<RGB_T>*
child(
int index)
override {
return items_.child(index); }
120 bool onGesture(
const tinygpu::GestureEvent& event)
override {
123 if (Container<RGB_T>::isContinuousType(event.type)) {
124 if (event.phase == tinygpu::GesturePhase::kBegan) {
125 routingToItems_ = items_.bounds.contains(event.startPoint.x, event.startPoint.y);
127 return routingToItems_ ? items_.onGesture(event) :
true;
130 if (items_.bounds.contains(event.point.x, event.point.y) && items_.onGesture(event)) {
133 if (isTapGesture(event.type) && !
this->bounds.contains(event.point.x, event.point.y)) {
134 if (onScrimTap) onScrimTap();
139 bool update(uint32_t nowMs)
override {
return items_.update(nowMs); }
144 return items_.bounds.contains(x, y) && items_.isDraggableAt(x, y);
148 int32_t contentTop()
const {
149 constexpr int32_t kHandleHeight = 4;
150 constexpr int32_t kPad = 8;
154 constexpr int32_t kApproxTitleHeight = 20;
155 const int32_t afterHandle =
this->bounds.y + 8 + kHandleHeight + kPad;
156 if (title_.empty())
return afterHandle;
157 return afterHandle + kApproxTitleHeight + kPad;
162 void syncItemsBounds() {
163 const int32_t top = contentTop();
164 items_.bounds =
Bounds(
this->bounds.x, top,
this->bounds.w,
this->bounds.bottom() - top);
169 bool routingToItems_ =
false;
Modal panel sliding up from the bottom edge, full width, with rounded top corners and a drag-handle b...
Definition: BottomSheet.h:32
bool isDraggableAt(int32_t x, int32_t y) const override
Definition: BottomSheet.h:143
bool onGesture(const tinygpu::GestureEvent &event) override
Definition: BottomSheet.h:120
void setItemProvider(typename Container< RGB_T >::ChildCountFn count, typename Container< RGB_T >::ChildAtFn at)
Definition: BottomSheet.h:54
Widget< RGB_T > * child(int index) override
Definition: BottomSheet.h:115
BottomSheet(Bounds bounds)
Definition: BottomSheet.h:35
void addItem(Widget< RGB_T > &item)
Definition: BottomSheet.h:50
Bounds itemRect(int index, int32_t height=48) const
Definition: BottomSheet.h:70
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: BottomSheet.h:74
std::function< void()> onScrimTap
Fired when a tap lands outside the panel (i.e. on the scrim).
Definition: BottomSheet.h:48
void setTitle(const char *title)
Definition: BottomSheet.h:45
bool update(uint32_t nowMs) override
Definition: BottomSheet.h:139
int childCount() const override
Definition: BottomSheet.h:114
void setTheme(const MaterialTheme< RGB_T > &theme) override
Definition: BottomSheet.h:59
void drawBackground(tinygpu::ISurface< RGB_T > &target) override
Definition: BottomSheet.h:83
BottomSheet(Bounds bounds, const char *title)
Definition: BottomSheet.h:40
A widget that holds child widgets, draws/dispatches gestures to them, and scrolls its content vertica...
Definition: Container.h:56
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21
Bundles a color scheme, shape tokens, typography, and spacing into one theme, passed to widgets so th...
Definition: MaterialTheme.h:50