4#include "TinyGPU/Color/RGB565.h"
5#include "TinyGPU/Color/RGB666.h"
6#include "TinyGPU/Color/RGB888.h"
7#include "TinyMaterialDesign/Core/Widget.h"
8#include "TinyMaterialDesign/Draw/Icons.h"
18 this->bounds = bounds;
26 void draw(tinygpu::ISurface<RGB_T>& target)
override {
27 RGB_T fill = checked_ ?
this->theme().colors.primary :
this->theme().colors.surface;
28 RGB_T border = checked_ ?
this->theme().colors.primary :
this->theme().colors.outline;
29 RGB_T mark =
this->theme().colors.onPrimary;
31 fill = blend(fill,
this->theme().colors.surface, 0.6f);
32 border = blend(border,
this->theme().colors.surface, 0.5f);
33 mark = blend(mark,
this->theme().colors.surface, 0.4f);
36 const size_t radius = toPx(
this->theme().shape.small);
38 target.fillRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y),
39 toPx(
this->bounds.w), toPx(
this->bounds.h), radius, fill);
41 target.drawRoundRect(toPx(
this->bounds.x), toPx(
this->bounds.y),
42 toPx(
this->bounds.w), toPx(
this->bounds.h), radius, border);
44 drawCheckmark(target,
this->bounds, mark);
48 bool onGesture(
const tinygpu::GestureEvent& event)
override {
49 if (!isTapGesture(event.type))
return false;
51 if (onChange) onChange(checked_);
56 bool checked_ =
false;
Square checkbox, toggled by tap.
Definition: Checkbox.h:14
void setChecked(bool checked)
Definition: Checkbox.h:24
bool checked() const
Definition: Checkbox.h:23
Checkbox(Bounds bounds, bool checked=false)
Definition: Checkbox.h:17
bool onGesture(const tinygpu::GestureEvent &event) override
Handles one gesture event. Returns true if this widget consumed it.
Definition: Checkbox.h:48
std::function< void(bool)> onChange
Definition: Checkbox.h:21
void draw(tinygpu::ISurface< RGB_T > &target) override
Definition: Checkbox.h:26
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21