14#include <goodisplay/gdey029T94.h>
17static const char*
TAG =
"DateInputView";
39 day_ = (day >= 1 && day <= 31) ? day : 1;
40 month_ = (month >= 1 && month <= 12) ? month : 1;
42 currentField_ = Field::DAY;
52void DateInputView::nextField() {
53 if (currentField_ == Field::DAY) {
54 currentField_ = Field::MONTH;
55 }
else if (currentField_ == Field::MONTH) {
56 currentField_ = Field::YEAR;
66void DateInputView::prevField() {
67 if (currentField_ == Field::YEAR) {
68 currentField_ = Field::MONTH;
69 }
else if (currentField_ == Field::MONTH) {
70 currentField_ = Field::DAY;
80void DateInputView::clearField() {
81 switch (currentField_) {
101void DateInputView::enterDigit(
char digit) {
102 uint8_t d = digit -
'0';
104 switch (currentField_) {
106 if (digitPos_ == 0) {
110 day_ = (day_ / 10) * 10 + d;
111 if (day_ < 1) day_ = 1;
112 if (day_ > 31) day_ = 31;
118 if (digitPos_ == 0) {
122 month_ = (month_ / 10) * 10 + d;
123 if (month_ < 1) month_ = 1;
124 if (month_ > 12) month_ = 12;
130 if (digitPos_ == 0) {
133 }
else if (digitPos_ == 1) {
134 year_ = (year_ / 1000) * 1000 + d * 100;
136 }
else if (digitPos_ == 2) {
137 year_ = (year_ / 100) * 100 + d * 10;
140 year_ = (year_ / 10) * 10 + d;
154bool DateInputView::validateAndClamp() {
155 if (day_ < 1) day_ = 1;
156 if (day_ > 31) day_ = 31;
157 if (month_ < 1) month_ = 1;
158 if (month_ > 12) month_ = 12;
159 if (year_ < 2000) year_ = 2000;
160 if (year_ > 2099) year_ = 2099;
171 if (key >=
'0' && key <=
'9') {
179 (currentField_ == Field::DAY && day_ > 0) ||
180 (currentField_ == Field::MONTH && month_ > 0) ||
181 (currentField_ == Field::YEAR && year_ > 0)) {
193 LOG_I(
TAG,
"Date confirmed: %02d.%02d.%04d", day_, month_, year_);
196 onConfirm_(day_, month_, year_);
210 return ui::tr(
"core.hint_date_input");
222 auto* gfx =
static_cast<Gdey029T94*
>(
display->getNativeHandle());
225 const uint16_t width =
display->getWidth();
226 const uint16_t height =
display->getHeight();
229 gfx->fillScreen(EPD_WHITE);
232 gfx->setTextColor(EPD_BLACK);
240 snprintf(dateStr,
sizeof(dateStr),
"%02d / %02d / %04d", day_, month_, year_);
245 gfx->getTextBounds(dateStr, 0, 0, &x1, &y1, &w, &h);
246 int startX = (width - w) / 2;
247 gfx->setCursor(startX,
DATE_Y);
250 gfx->fillRect(0,
UNDERLINE_Y, width, 4, EPD_WHITE);
253 int underlineX = startX;
256 switch (currentField_) {
259 underlineW = 2 * charWidth;
262 underlineX = startX + 5 * charWidth;
263 underlineW = 2 * charWidth;
266 underlineX = startX + 10 * charWidth;
267 underlineW = 4 * charWidth;
271 gfx->fillRect(underlineX,
UNDERLINE_Y, underlineW, 3, EPD_BLACK);
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
static constexpr int DATE_Y
static constexpr int TITLE_Y
Display layout constants.
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_I(tag, fmt,...)
static ViewStack & instance()
Returns singleton view-stack instance.
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
static constexpr char KEY_NO
Cancel / Back / Backspace.
static constexpr int TITLE_Y
Layout constants mirror the ones used by T9InputView.
static constexpr char KEY_YES
Confirm / OK / Save.