CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
RenderHelpers.h File Reference
#include <cstddef>
#include <cstdint>
#include <gfxfont.h>
#include "cdc_views/LayoutConstants.h"

Go to the source code of this file.

Namespaces

namespace  cdc
namespace  cdc::ui
 Centralized key-code constants for cdc_views.
namespace  cdc::ui::render

Enumerations

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

Functions

void cdc::ui::render::drawHeaderLeft (Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18)
void cdc::ui::render::drawHeaderCentered (Gdey029T94 *gfx, const char *title, int y, uint16_t width)
 Draws a centered header title.
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.
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.
void cdc::ui::render::drawDialogFrame (Gdey029T94 *gfx, int x, int y, int w, int h)
 Draws a framed dialog box with double border.
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.
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).
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.
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.
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.
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.
void cdc::ui::render::printText (Gdey029T94 *gfx, const char *text)
 Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
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.
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.
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).

Variables

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