CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
PasswordT9View.cpp
Go to the documentation of this file.
4#include "cdc_ui/I18n.h"
5#include "cdc_hal/IDisplay.h"
6#include <goodisplay/gdey029T94.h>
7#include <cstdio>
8
9namespace cdc::ui {
10
12static constexpr int TITLE_Y = 5;
13static constexpr int TEXT_Y = 50;
14static constexpr int TEXT_MARGIN = 10;
15
22void PasswordT9View::render(bool partial) {
24 if (!display) return;
25 auto* gfx = static_cast<Gdey029T94*>(display->getNativeHandle());
26 if (!gfx) return;
27
28 const uint16_t width = display->getWidth();
29 const uint16_t height = display->getHeight();
30
31 if (!partial) gfx->fillScreen(EPD_WHITE);
32
33 gfx->setTextColor(EPD_BLACK);
34 gfx->setTextSize(1);
35
37
38 // Input box
39 gfx->fillRect(TEXT_MARGIN, TEXT_Y - 5, width - TEXT_MARGIN * 2, 30, EPD_WHITE);
40 gfx->drawRect(TEXT_MARGIN - 2, TEXT_Y - 7, width - TEXT_MARGIN * 2 + 4, 34, EPD_BLACK);
41 gfx->setCursor(TEXT_MARGIN + 2, TEXT_Y);
42
43 if (len_ == 0 && placeholder_) {
44 gfx->setTextColor(EPD_DARKGREY);
46 gfx->setTextColor(EPD_BLACK);
47 } else {
48 for (uint16_t i = 0; i < len_; i++) {
49 const bool isCursorChar = cursorActive_ && i == len_ - 1;
50 const bool showPlain = revealed_ || isCursorChar;
51 char c = showPlain ? text_[i] : maskChar_;
52
53 if (isCursorChar) {
54 int16_t x = gfx->getCursorX();
55 int16_t y = gfx->getCursorY();
56 gfx->fillRect(x, y - 2, 8, 14, EPD_BLACK);
57 gfx->setTextColor(EPD_WHITE);
58 gfx->print(c);
59 gfx->setTextColor(EPD_BLACK);
60 } else {
61 gfx->print(c);
62 }
63 }
64 if (!cursorActive_) {
65 gfx->print("|");
66 }
67 }
68
69 char countStr[32];
70 snprintf(countStr, sizeof(countStr), "%u/%u %s",
71 len_, maxLen_, revealed_ ? "(shown)" : "(hidden)");
72 const char* hint = getFooterHint();
73 render::drawFooterBar(gfx, width, height, countStr, hint, true);
74
75 dirty_ = false;
76}
77
82 if (key == KEY_YES) {
83 revealed_ = !revealed_;
84 markDirty();
86 }
87 return T9InputView::onLongPress(key);
88}
89
90const char* PasswordT9View::getFooterHint() const {
91 return tr(revealed_ ? "core.hint_password_revealed"
92 : "core.hint_password_hidden");
93}
94
95} // namespace cdc::ui
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
const char * getFooterHint() const override
void render(bool partial) override
Renders title, masked text box and footer.
InputResult onLongPress(char key) override
Long-press on Y toggles the reveal state. Other keys delegate to T9.
const char * placeholder_
Definition T9InputView.h:98
char text_[MAX_TEXT_LEN+1]
InputResult onLongPress(char key) override
Handles long-press actions for clear and forced digit insertion.
const char * title_
Definition T9InputView.h:97
void markDirty() override
Definition IView.h:186
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 drawHeaderLeft(Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18)
void printText(Gdey029T94 *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
Centralized key-code constants for cdc_views.
Definition IModule.h:8
const char * tr(const char *key)
Look up a translation by string key.
Definition I18n.h:208
static constexpr int TEXT_Y
Gdey029T94 * display
InputResult
Definition IView.h:10
static constexpr int TITLE_Y
Layout constants mirror the ones used by T9InputView.
static constexpr char KEY_YES
Confirm / OK / Save.
Definition KeyCodes.h:41
static constexpr int TEXT_MARGIN