CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::ui::render Namespace Reference

Enumerations

enum class  DisplayTarget : uint8_t { Cp437 = 0 , Latin1 = 1 }
 Display encoding targets for decodeWebText(). More...

Functions

void drawHeaderLeft (Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18)
void drawHeaderCentered (Gdey029T94 *gfx, const char *title, int y, uint16_t width)
 Draws a centered header title.
void drawFooterBar (Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force)
 Draws footer bar with optional prefix and hint text.
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.
void drawDialogFrame (Gdey029T94 *gfx, int x, int y, int w, int h)
 Draws a framed dialog box with double border.
void printTruncated (Gdey029T94 *gfx, const char *text, int maxWidthPx)
 Print text at the current cursor, truncated with an ellipsis to fit maxWidthPx. Caller must have already called setCursor and setTextColor/setTextSize. Adafruit-GFX text wrap should be off.
uint8_t cp437ToLatin1 (uint8_t c)
 Maps a CP437 byte to the equivalent Latin-1 byte for use with Unicode/Latin-1 indexed GFX fonts (e.g. FreeMonoBold*pt8b).
void utf8ToCp437Inplace (char *buf)
 Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small. Unmapped codepoints are dropped silently.
void decodeWebText (const char *in, char *out, size_t out_size, DisplayTarget target=DisplayTarget::Cp437)
 Normalises a web payload for display: HTML named/numeric entities decode first, then UTF-8 multibyte sequences collapse into the single-byte layout expected by the target font.
void drawCp437Text (Gdey029T94 *gfx, const char *text)
 Prints a CP437 string by mapping each byte to Latin-1 before drawing. Use with TTF-derived GFX fonts (range 0x20..0xFF) that expect Latin-1 indices.
void drawText (Gdey029T94 *gfx, const char *text, const GFXfont *font)
 Draws CP437-encoded text correctly for the given font: the built-in glcdfont (font == nullptr) is CP437-indexed and receives the bytes raw; TTF-derived GFX fonts are Latin-1-indexed and receive a per-byte CP437->Latin1 mapping. This is the single point where the in-memory CP437 canonical form is adapted to the active font's index space. The caller must have set font on gfx and positioned the cursor.
void printText (Gdey029T94 *gfx, const char *text)
 Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
void measureText (Gdey029T94 *gfx, const char *text, const GFXfont *font, int16_t x0, int16_t y0, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
 Measures CP437 text exactly as drawText would render it with font, so width-based layout (centering, fitting, truncation) matches the drawn glyphs.
const GFXfont * pickFontThatFits (Gdey029T94 *gfx, const char *text, int maxWidthPx, const GFXfont *const *candidates, size_t count, bool cp437=false)
 Picks the largest font from candidates whose rendered width of text fits within maxWidthPx. Candidates are evaluated in array order; pass them sorted from largest to smallest so the first match is the biggest font that still fits.
void measureCp437Text (Gdey029T94 *gfx, const char *text, int16_t x0, int16_t y0, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
 Measures a CP437 string using the current font (via Latin-1 mapping).

Variables

constexpr int FOOTER_HEIGHT = cdc::ui::layout::FOOTER_HEIGHT
constexpr int SCROLL_INDICATOR_WIDTH = cdc::ui::layout::SCROLL_INDICATOR_WIDTH

Detailed Description

RenderHelpers

Shared rendering utilities for common UI chrome and dialogs.

Enumeration Type Documentation

◆ DisplayTarget

enum class cdc::ui::render::DisplayTarget : uint8_t
strong

Display encoding targets for decodeWebText().

Enumerator
Cp437 

GFX builtin glcdfont (default after setFont(nullptr)).

Latin1 

FreeMonoBold*pt8b fonts (Latin-1 indexed, 0x20..0xFF).

Definition at line 58 of file RenderHelpers.h.

Function Documentation

◆ cp437ToLatin1()

uint8_t cdc::ui::render::cp437ToLatin1 ( uint8_t c)

Maps a CP437 byte to the equivalent Latin-1 byte for use with Unicode/Latin-1 indexed GFX fonts (e.g. FreeMonoBold*pt8b).

Maps a CP437 byte to the equivalent Latin-1 byte for use with Latin-1 indexed GFX fonts (TTF-derived range 0x20..0xFF). ASCII (<0x80) and untracked codes pass through unchanged.

Parameters
cCP437 byte value.
Returns
Latin-1 byte representing the same character, or c when no mapping is needed.

Definition at line 218 of file RenderHelpers.cpp.

Referenced by drawCp437Text(), and measureCp437Text().

◆ decodeWebText()

void cdc::ui::render::decodeWebText ( const char * in,
char * out,
size_t out_size,
DisplayTarget target = DisplayTarget::Cp437 )

Normalises a web payload for display: HTML named/numeric entities decode first, then UTF-8 multibyte sequences collapse into the single-byte layout expected by the target font.

target picks the output codepage:

Output is always NUL-terminated. Unmapped codepoints are dropped. in and out must not alias.

Parameters
inSource string (UTF-8, optionally containing HTML entities).
outDestination buffer.
out_sizeCapacity of out in bytes (including the terminator).
targetEncoding target. Defaults to CP437.

Definition at line 395 of file RenderHelpers.cpp.

References Latin1, and utf8ToCp437Inplace().

Referenced by host_str_to_display(), and cdc::plugin_manager::toDisplay().

◆ drawCp437Text()

void cdc::ui::render::drawCp437Text ( Gdey029T94 * gfx,
const char * text )

Prints a CP437 string by mapping each byte to Latin-1 before drawing. Use with TTF-derived GFX fonts (range 0x20..0xFF) that expect Latin-1 indices.

Parameters
gfxTarget display.
textCP437-encoded null-terminated string.

Definition at line 421 of file RenderHelpers.cpp.

References cp437ToLatin1().

Referenced by drawText().

◆ drawDialogFrame()

void cdc::ui::render::drawDialogFrame ( Gdey029T94 * gfx,
int x,
int y,
int w,
int h )

Draws a framed dialog box with double border.

Parameters
gfxDisplay drawing context.
xLeft position.
yTop position.
wFrame width.
hFrame height.
Returns
void

Definition at line 205 of file RenderHelpers.cpp.

Referenced by cdc::ui::BlePairingPromptView::render(), cdc::ui::ConfirmView::render(), cdc::ui::ContextMenuView::render(), cdc::ui::MessageBox::render(), and cdc::ui::ToastView::render().

◆ drawFooterBar()

void cdc::ui::render::drawFooterBar ( Gdey029T94 * gfx,
uint16_t width,
uint16_t height,
const char * prefix,
const char * hint,
bool force )

Draws footer bar with optional prefix and hint text.

Parameters
gfxDisplay drawing context.
widthDisplay width.
heightDisplay height.
prefixOptional prefix text.
hintOptional hint text.
forceDraw even if prefix/hint are empty.
Returns
void

Definition at line 118 of file RenderHelpers.cpp.

References FOOTER_HEIGHT.

Referenced by cdc::ui::BlePairingView::render(), cdc::ui::CanvasView::render(), cdc::ui::ColorPickerView::render(), cdc::ui::DateInputView::render(), cdc::ui::InfoView::render(), cdc::ui::ListView::render(), cdc::ui::PasswordT9View::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::SliderView::render(), cdc::ui::T9InputView::render(), and cdc::ui::TimeInputView::render().

◆ drawHeaderCentered()

void cdc::ui::render::drawHeaderCentered ( Gdey029T94 * gfx,
const char * title,
int y,
uint16_t width )

Draws a centered header title.

Parameters
gfxDisplay drawing context.
titleTitle text.
yHeader text Y position.
widthTotal layout width.
Returns
void

Definition at line 98 of file RenderHelpers.cpp.

Referenced by cdc::ui::BlePairingView::render(), cdc::ui::DateInputView::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::SliderView::render(), and cdc::ui::TimeInputView::render().

◆ drawHeaderLeft()

void cdc::ui::render::drawHeaderLeft ( Gdey029T94 * gfx,
const char * title,
int x,
int y,
uint16_t width,
int underlineOffset = 18 )

◆ drawScrollIndicator()

void cdc::ui::render::drawScrollIndicator ( Gdey029T94 * gfx,
int x,
int y,
int listHeight,
uint16_t totalItems,
uint16_t visibleItems,
uint16_t scrollPos )

Draws scroll arrows and scrollbar thumb.

Parameters
gfxDisplay drawing context.
xIndicator X position.
yIndicator Y position.
listHeightHeight of the scrollable list area.
totalItemsTotal item count.
visibleItemsNumber of visible items.
scrollPosCurrent scroll offset.
Returns
void

Definition at line 148 of file RenderHelpers.cpp.

References SCROLL_INDICATOR_WIDTH.

Referenced by cdc::ui::InfoView::render(), and cdc::ui::ListView::render().

◆ drawText()

void cdc::ui::render::drawText ( Gdey029T94 * gfx,
const char * text,
const GFXfont * font )

Draws CP437-encoded text correctly for the given font: the built-in glcdfont (font == nullptr) is CP437-indexed and receives the bytes raw; TTF-derived GFX fonts are Latin-1-indexed and receive a per-byte CP437->Latin1 mapping. This is the single point where the in-memory CP437 canonical form is adapted to the active font's index space. The caller must have set font on gfx and positioned the cursor.

Parameters
gfxTarget display.
textCP437-encoded null-terminated string.
fontActive font (nullptr for the built-in glcdfont).

Definition at line 428 of file RenderHelpers.cpp.

References drawCp437Text().

Referenced by cdc::ui::LockScreenView::render().

◆ measureCp437Text()

void cdc::ui::render::measureCp437Text ( Gdey029T94 * gfx,
const char * text,
int16_t x0,
int16_t y0,
int16_t * x1,
int16_t * y1,
uint16_t * w,
uint16_t * h )

Measures a CP437 string using the current font (via Latin-1 mapping).

Parameters
gfxTarget display.
textCP437-encoded null-terminated string.
x0Starting x position for measurement.
y0Starting y position for measurement.
x1Output: top-left x of the rendered bounds.
y1Output: top-left y of the rendered bounds.
wOutput: width of the rendered text.
hOutput: height of the rendered text.

Definition at line 499 of file RenderHelpers.cpp.

References cp437ToLatin1().

Referenced by measureText(), and pickFontThatFits().

◆ measureText()

void cdc::ui::render::measureText ( Gdey029T94 * gfx,
const char * text,
const GFXfont * font,
int16_t x0,
int16_t y0,
int16_t * x1,
int16_t * y1,
uint16_t * w,
uint16_t * h )

Measures CP437 text exactly as drawText would render it with font, so width-based layout (centering, fitting, truncation) matches the drawn glyphs.

Parameters
gfxTarget display.
textCP437-encoded null-terminated string.
fontActive font (nullptr for the built-in glcdfont).
x0Starting x for measurement.
y0Starting y for measurement.
x1Output: top-left x of the rendered bounds.
y1Output: top-left y of the rendered bounds.
wOutput: rendered width.
hOutput: rendered height.

Definition at line 448 of file RenderHelpers.cpp.

References measureCp437Text().

Referenced by cdc::ui::LockScreenView::render().

◆ pickFontThatFits()

const GFXfont * cdc::ui::render::pickFontThatFits ( Gdey029T94 * gfx,
const char * text,
int maxWidthPx,
const GFXfont *const * candidates,
size_t count,
bool cp437 = false )

Picks the largest font from candidates whose rendered width of text fits within maxWidthPx. Candidates are evaluated in array order; pass them sorted from largest to smallest so the first match is the biggest font that still fits.

Parameters
gfxTarget display. Its current font is overwritten while measuring and restored to the selected font on return.
textNull-terminated text to measure.
maxWidthPxPixel budget that the rendered text must stay below.
candidatesArray of GFX font pointers. nullptr entries select the built-in 6x8 font.
countNumber of entries in candidates.
cp437If true, measure via measureCp437Text() (CP437->Latin1 mapping); otherwise use Adafruit-GFX getTextBounds() directly.
Returns
Selected font pointer. Falls back to the last (smallest) candidate when nothing fits; returns nullptr if the array is empty.

Definition at line 466 of file RenderHelpers.cpp.

References measureCp437Text().

Referenced by host_text_pick_font_that_fits(), and cdc::ui::LockScreenView::render().

◆ printText()

void cdc::ui::render::printText ( Gdey029T94 * gfx,
const char * text )

Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.

Use this instead of gfx->print(const char*) for any user/i18n string: the CalEPD Epd::print(const std::string&) overload assumes UTF-8 and adds 64 to bytes 0x84..0xBE, corrupting CP437 umlauts (ae 0x84 -> 0xC4 etc.). This forces the built-in font and writes each byte straight through, bypassing that.

Parameters
gfxDisplay drawing context.
textCP437-encoded null-terminated string.

Definition at line 442 of file RenderHelpers.cpp.

Referenced by host_display_draw_text(), cdc::mod_2fa::OathCodeView::render(), cdc::ui::BlePairingView::render(), cdc::ui::ColorPickerView::render(), cdc::ui::ConfirmView::render(), cdc::ui::ContextMenuView::render(), cdc::ui::ListView::render(), cdc::ui::LockScreenView::render(), cdc::ui::MessageBox::render(), cdc::ui::PasswordT9View::render(), cdc::ui::PinChangeView::render(), cdc::ui::PinEntryView::render(), cdc::ui::QRCodeView::render(), cdc::ui::T9InputView::render(), cdc::ui::renderBleRow(), and cdc::ui::renderWifiRow().

◆ printTruncated()

void cdc::ui::render::printTruncated ( Gdey029T94 * gfx,
const char * text,
int maxWidthPx )

Print text at the current cursor, truncated with an ellipsis to fit maxWidthPx. Caller must have already called setCursor and setTextColor/setTextSize. Adafruit-GFX text wrap should be off.

Draws a left-aligned header with optional underline.

Parameters
gfxDisplay drawing context.
textNull-terminated text.
maxWidthPxMaximum width in pixels.
gfxDisplay drawing context.
titleOptional title text.
xHeader text X position.
yHeader text Y position.
widthWidth used for underline.
underlineOffsetVertical offset for underline.
Returns
void

Definition at line 40 of file RenderHelpers.cpp.

Referenced by cdc::ui::BlePairingView::render(), and cdc::ui::ToastView::render().

◆ utf8ToCp437Inplace()

void cdc::ui::render::utf8ToCp437Inplace ( char * buf)

Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small. Unmapped codepoints are dropped silently.

Parameters
bufMutable null-terminated UTF-8 buffer; written back as CP437.

Definition at line 357 of file RenderHelpers.cpp.

References cdc::core::cp437::fromUtf8().

Referenced by decodeWebText().

Variable Documentation

◆ FOOTER_HEIGHT

int cdc::ui::render::FOOTER_HEIGHT = cdc::ui::layout::FOOTER_HEIGHT
constexpr

Definition at line 16 of file RenderHelpers.h.

Referenced by drawFooterBar().

◆ SCROLL_INDICATOR_WIDTH

int cdc::ui::render::SCROLL_INDICATOR_WIDTH = cdc::ui::layout::SCROLL_INDICATOR_WIDTH
constexpr

Definition at line 17 of file RenderHelpers.h.

Referenced by drawScrollIndicator().