CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
RenderHelpers.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include <gfxfont.h>
7
9
10class Gdey029T94;
11
12namespace cdc::ui::render {
13
14// Backwards-compatible aliases for the shared layout constants.
15// Prefer the canonical names in cdc::ui::layout for new code.
18
19void drawHeaderLeft(Gdey029T94* gfx, const char* title, int x, int y,
20 uint16_t width, int underlineOffset = 18);
21void drawHeaderCentered(Gdey029T94* gfx, const char* title, int y, uint16_t width);
22
23void drawFooterBar(Gdey029T94* gfx, uint16_t width, uint16_t height,
24 const char* prefix, const char* hint, bool force = false);
25
26void drawScrollIndicator(Gdey029T94* gfx, int x, int y, int listHeight,
27 uint16_t totalItems, uint16_t visibleItems,
28 uint16_t scrollPos);
29
30void drawDialogFrame(Gdey029T94* gfx, int x, int y, int w, int h);
31
40void printTruncated(Gdey029T94* gfx, const char* text, int maxWidthPx);
41
48uint8_t cp437ToLatin1(uint8_t c);
49
55void utf8ToCp437Inplace(char* buf);
56
58enum class DisplayTarget : uint8_t {
59 Cp437 = 0,
60 Latin1 = 1,
61};
62
80void decodeWebText(const char* in, char* out, size_t out_size,
82
89void drawCp437Text(Gdey029T94* gfx, const char* text);
90
102void drawText(Gdey029T94* gfx, const char* text, const GFXfont* font);
103
114void printText(Gdey029T94* gfx, const char* text);
115
130void measureText(Gdey029T94* gfx, const char* text, const GFXfont* font,
131 int16_t x0, int16_t y0, int16_t* x1, int16_t* y1,
132 uint16_t* w, uint16_t* h);
133
151const GFXfont* pickFontThatFits(Gdey029T94* gfx,
152 const char* text,
153 int maxWidthPx,
154 const GFXfont* const* candidates,
155 size_t count,
156 bool cp437 = false);
157
169void measureCp437Text(Gdey029T94* gfx, const char* text, int16_t x0, int16_t y0,
170 int16_t* x1, int16_t* y1, uint16_t* w, uint16_t* h);
171
172} // namespace cdc::ui::render
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 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 CP4...
void drawDialogFrame(Gdey029T94 *gfx, int x, int y, int w, int h)
Draws a framed dialog box with double border.
void drawHeaderCentered(Gdey029T94 *gfx, const char *title, int y, uint16_t width)
Draws a centered header title.
void utf8ToCp437Inplace(char *buf)
Decodes a UTF-8 string in place to CP437 single bytes. Truncates if the buffer is too small....
void drawHeaderLeft(Gdey029T94 *gfx, const char *title, int x, int y, uint16_t width, int underlineOffset=18)
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,...
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....
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 ...
constexpr int SCROLL_INDICATOR_WIDTH
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....
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).
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 alre...
void printText(Gdey029T94 *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
DisplayTarget
Display encoding targets for decodeWebText().
@ Cp437
GFX builtin glcdfont (default after setFont(nullptr)).
@ Latin1
FreeMonoBold*pt8b fonts (Latin-1 indexed, 0x20..0xFF).
constexpr int FOOTER_HEIGHT
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 ...
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.