15#include <goodisplay/gdey029T94.h>
18static const char*
TAG =
"InfoView";
42constexpr uint16_t WRAP_COLS = 44;
44void wrapInPlace(
char* buf, uint16_t maxCols) {
45 if (!buf || maxCols == 0)
return;
47 char* lastSpace =
nullptr;
48 for (
char* p = buf; *p; ++p) {
54 if (col >= maxCols && lastSpace) {
56 col =
static_cast<uint16_t
>(p - lastSpace - 1);
59 if (*p ==
' ') lastSpace = p;
68 strncpy(titleBuf_, title, MAX_TITLE_LEN - 1);
69 titleBuf_[MAX_TITLE_LEN - 1] =
'\0';
82 textBuf_.get()[0] =
'\0';
84 wrapInPlace(textBuf_.get(), WRAP_COLS);
88 totalLines_ = countLines();
89 customHint_ =
nullptr;
92 LOG_D(
TAG,
"init: title='%s', lines=%d", titleBuf_, totalLines_);
99uint16_t InfoView::countLines()
const {
100 if (!textBuf_ || textBuf_.get()[0] ==
'\0')
return 0;
103 const char* p = textBuf_.get();
105 if (*p ==
'\n') lines++;
116void InfoView::scroll(
bool down) {
127 if (scrollLine_ > 0) {
144 if (key ==
KEY_YES && onYes_) {
145 onYes_(callbackUserData_);
148 if (key ==
KEY_NO && onNo_) {
149 onNo_(callbackUserData_);
153 onMenu_(menuUserData_);
198 return ui::tr(
"core.hint_scroll_back");
210 auto* gfx =
static_cast<Gdey029T94*
>(
display->getNativeHandle());
213 const uint16_t width =
display->getWidth();
214 const uint16_t height =
display->getHeight();
217 gfx->fillScreen(EPD_WHITE);
222 gfx->fillRect(0, 0, width, height -
FOOTER_HEIGHT, EPD_WHITE);
225 gfx->setFont(
nullptr);
226 gfx->setTextColor(EPD_BLACK);
230 const char* title = (titleBuf_[0] !=
'\0') ? titleBuf_ :
nullptr;
241 if (textBuf_ && textBuf_.get()[0] !=
'\0') {
242 const char* lineStart = textBuf_.get();
243 uint16_t currentLine = 0;
247 while (currentLine < scrollLine_ && *lineStart) {
248 if (*lineStart ==
'\n') currentLine++;
257 const char* lineEnd = lineStart;
258 while (*lineEnd && *lineEnd !=
'\n') lineEnd++;
261 while (lineStart < lineEnd) {
262 gfx->print(*lineStart);
267 if (*lineStart ==
'\n') lineStart++;
283 const char* prefix =
nullptr;
285 snprintf(posStr,
sizeof(posStr),
"%u-%u/%u ",
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
constexpr int SCROLL_INDICATOR_WIDTH
Scroll indicator column width in pixels.
static constexpr int TEXT_START_Y
static constexpr int TEXT_MARGIN
constexpr int FOOTER_HEIGHT
Footer bar height in pixels (used by drawFooterBar).
static constexpr int TITLE_Y
Display layout constants.
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_D(tag, fmt,...)
void render(bool partial) override
Renders the info view including title, body, scroll indicator, and footer.
static constexpr uint16_t MAX_TEXT_LEN
InputResult onKey(char key) override
Handles key input for scrolling and optional callbacks.
static constexpr uint8_t VISIBLE_LINES
InputResult onLongPress(char key) override
Long-press jumps to the first (KEY_UP) or last (KEY_DOWN) page.
static constexpr uint8_t LINE_HEIGHT
void init(const char *title, const char *text)
const char * getFooterHint() const override
Returns the footer hint text.
static ViewStack & instance()
Returns singleton view-stack instance.
void push(IView *view, void *context=nullptr)
PsramUniquePtr< T > psramAlloc(std::size_t count) noexcept
Allocate count elements of T in PSRAM (8-bit capable region).
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
constexpr int SCROLL_INDICATOR_WIDTH
Scroll indicator column width in pixels.
constexpr int FOOTER_HEIGHT
Footer bar height in pixels (used by drawFooterBar).
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 drawScrollIndicator(Gdey029T94 *gfx, int x, int y, int listHeight, uint16_t totalItems, uint16_t visibleItems, uint16_t scrollPos)
Draws scroll arrows and scrollbar thumb.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
InfoView * showInfo(const char *title, const char *text, const char *hint=nullptr)
Shows a shared info view instance and pushes it onto the view stack.
static constexpr char KEY_MENU
Open context menu / digit '3'.
static constexpr char KEY_DOWN
Move selection down (numeric '8').
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_UP
Move selection up (numeric '2').
static constexpr char KEY_YES
Confirm / OK / Save.
static InfoView s_sharedInfoView
Convenience factory/helper function.
static constexpr int TEXT_MARGIN