|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Scrollable viewer that renders a Markdown source. More...
#include <MarkdownView.h>
Classes | |
| struct | InteractRef |
| One selectable interactive element discovered in the rendered rows. More... | |
Public Types | |
| enum class | Interact : uint8_t { Link , Check , Submit , Image } |
| Interactive element kinds the view can select (4/6) and activate (Y). More... | |
| using | CheckSaveFn = void (*)(void* ud, const char* cp437Source, size_t len) |
| Persistence callback fired after a task-list checkbox toggles. Receives the full modified CP437 source so the owner can write it back (e.g. to the file). Leave unset for read-only documents. | |
Public Member Functions | |
| void | init (const char *title, const char *src, size_t len) |
| Loads and lays out a Markdown source. | |
| void | initPlain (const char *title, const char *src, size_t len) |
| Loads a source as plain, unrendered text (no Markdown parsing). | |
| void | appendParsed (const StyledLine &line) |
| Sink callback: wraps one parsed styled line into visual rows. | |
| void | render (bool partial) override |
| InputResult | onKey (char key) override |
| InputResult | onLongPress (char key) override |
| void | onExit () override |
| const char * | getName () const override |
| const char * | getFooterHint () const override |
| void | selectMarker (uint16_t linkNum) |
| Highlight the row containing the inline marker "[linkNum]" and scroll it into view. Pass 0 to clear the highlight. Used for in-view link selection by subclasses; the base renders the highlighted row inverted. | |
| void | cycleInteractive (int dir) |
Move the interactive selection by dir (+1/-1), highlighting its row. | |
| void | clearSelection () |
| Clear the current interactive selection. | |
| uint16_t | interactiveCount () const |
| Number of interactive elements on the page. | |
| void | setCheckSave (CheckSaveFn fn, void *ud) |
| Public Member Functions inherited from cdc::ui::ViewBase | |
| virtual | ~ViewBase ()=default |
| void | onEnter (void *context) override |
| void | onExit () override |
| void | onResume () override |
| void | onPause () override |
| void | setLifecycleHooks (void(*onHide)(void *), void(*onShow)(void *), void *userData) override |
| bool | needsRender () const override |
| void | markDirty () override |
| void | clearDirty () override |
| void | setFooterHint (const char *hint) override |
| const char * | getFooterHint () const override |
| Public Member Functions inherited from cdc::ui::IView | |
| virtual | ~IView ()=default |
| virtual bool | prefersLightRefresh () const |
| virtual hal::RefreshMode | preferredEnterRefresh () const |
| virtual void | onTick (uint32_t nowMs) |
Static Public Attributes | |
| static constexpr uint32_t | MAX_SOURCE = 64u * 1024u |
| Source byte cap. | |
| static constexpr uint16_t | MAX_ROWS = 600 |
| Visual-row cap. | |
Protected Member Functions | |
| virtual void | rebuildInteractive () |
| Rebuild the interactive-element list from the rendered rows. Base finds task-list checkboxes; subclasses extend with links/forms. | |
| virtual void | activateSelected () |
| Activate the selected element (Y). Base toggles checkboxes. | |
| uint16_t | mdRowCount () const |
| void | mdRowInfo (uint16_t i, const char *&text, uint16_t &len, bool &first, uint32_t &srcOff) const |
| void | addInteract (uint16_t row, Interact kind, uint16_t id, uint32_t srcOff) |
| void | clearInteract () |
| const InteractRef * | selectedRef () const |
| bool | flipCheckChar (uint32_t srcOff) |
| Toggle a checkbox state char in the source. | |
| void | fireCheckSave () |
| Run the persistence callback with the current source (if set). | |
| Protected Member Functions inherited from cdc::ui::ViewBase | |
| void | setTitle (const char *title) |
| const char * | getTitle () const |
Additional Inherited Members | |
| Protected Attributes inherited from cdc::ui::ViewBase | |
| bool | dirty_ = true |
| const char * | title_ = nullptr |
| const char * | customFooter_ = nullptr |
| void(* | onHide_ )(void *) = nullptr |
| void(* | onShow_ )(void *) = nullptr |
| void * | lifecycleUserData_ = nullptr |
Scrollable viewer that renders a Markdown source.
Parses the source into styled lines (parseMarkdown), wraps them into per-font visual rows, and scrolls them with variable line heights. Headings use the larger bold fonts; lists, block quotes, code and rules are visually distinct. All buffers live in PSRAM and are released on exit.
Keys: 2 = up, 8 = down, N = back.
Definition at line 22 of file MarkdownView.h.
| using cdc::ui::MarkdownView::CheckSaveFn = void (*)(void* ud, const char* cp437Source, size_t len) |
Persistence callback fired after a task-list checkbox toggles. Receives the full modified CP437 source so the owner can write it back (e.g. to the file). Leave unset for read-only documents.
Definition at line 88 of file MarkdownView.h.
|
strong |
Interactive element kinds the view can select (4/6) and activate (Y).
| Enumerator | |
|---|---|
| Link | |
| Check | |
| Submit | |
| Image | |
Definition at line 64 of file MarkdownView.h.
|
protectedvirtual |
Activate the selected element (Y). Base toggles checkboxes.
Definition at line 451 of file MarkdownView.cpp.
References Check, fireCheckSave(), flipCheckChar(), cdc::ui::MarkdownView::InteractRef::id, Image, cdc::ui::imageOpener(), cdc::ui::MarkdownView::InteractRef::kind, Link, selectedRef(), cdc::ui::MarkdownView::InteractRef::srcOff, and cdc::ui::urlOpener().
Referenced by onKey().
|
protected |
Definition at line 344 of file MarkdownView.cpp.
Referenced by rebuildInteractive().
| void cdc::ui::MarkdownView::appendParsed | ( | const StyledLine & | line | ) |
Sink callback: wraps one parsed styled line into visual rows.
Definition at line 94 of file MarkdownView.cpp.
References cdc::ui::Blank, cdc::ui::mdfont::Builtin, cdc::ui::Bullet, cdc::ui::StyledLine::font, cdc::ui::StyledLine::indent, INDENT_PX, cdc::ui::StyledLine::inverted, cdc::ui::StyledLine::kind, cdc::ui::StyledLine::len, cdc::ui::Ordered, cdc::ui::Quote, cdc::ui::Rule, and cdc::ui::StyledLine::text.
|
inlineprotected |
Definition at line 104 of file MarkdownView.h.
Referenced by rebuildInteractive().
|
inline |
Clear the current interactive selection.
Definition at line 78 of file MarkdownView.h.
References cdc::ui::ViewBase::dirty_.
| void cdc::ui::MarkdownView::cycleInteractive | ( | int | dir | ) |
Move the interactive selection by dir (+1/-1), highlighting its row.
Definition at line 425 of file MarkdownView.cpp.
References cdc::ui::ViewBase::dirty_, and cdc::ui::MarkdownView::InteractRef::row.
Referenced by onKey().
|
protected |
Run the persistence callback with the current source (if set).
Definition at line 447 of file MarkdownView.cpp.
Referenced by activateSelected().
|
protected |
Toggle a checkbox state char in the source.
Definition at line 438 of file MarkdownView.cpp.
References cdc::ui::ViewBase::dirty_.
Referenced by activateSelected().
|
overridevirtual |
Get footer hint text (e.g., "[Y] OK [N] Back") Return nullptr for no footer
Reimplemented from cdc::ui::IView.
Definition at line 274 of file MarkdownView.cpp.
References cdc::ui::tr().
Referenced by render().
|
inlineoverridevirtual |
Get view name for debugging
Implements cdc::ui::IView.
Definition at line 53 of file MarkdownView.h.
| void cdc::ui::MarkdownView::init | ( | const char * | title, |
| const char * | src, | ||
| size_t | len ) |
Loads and lays out a Markdown source.
| title | Header title (CP437). |
| src | Markdown source (CP437; ASCII markup is codepage-independent). |
| len | Source length in bytes. |
Definition at line 141 of file MarkdownView.cpp.
References cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::hal::getDisplayInstance(), LOG_D, MAX_ROWS, MAX_SOURCE, cdc::ui::parseMarkdown(), cdc::core::psramAlloc(), rebuildInteractive(), SCROLL_INDICATOR_WIDTH, cdc::ui::TAG, and cdc::ui::TEXT_MARGIN.
| void cdc::ui::MarkdownView::initPlain | ( | const char * | title, |
| const char * | src, | ||
| size_t | len ) |
Loads a source as plain, unrendered text (no Markdown parsing).
Splits on newlines and word-wraps each line with the built-in font; inline emphasis markers are shown verbatim. Used for the browser's source view.
| title | Header title (CP437). |
| src | Text (CP437). |
| len | Source length in bytes. |
Definition at line 186 of file MarkdownView.cpp.
References cdc::ui::mdfont::Builtin, cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::hal::getDisplayInstance(), LOG_D, MAX_ROWS, MAX_SOURCE, cdc::ui::Paragraph, cdc::core::psramAlloc(), SCROLL_INDICATOR_WIDTH, cdc::ui::TAG, and cdc::ui::TEXT_MARGIN.
|
inline |
Number of interactive elements on the page.
Definition at line 81 of file MarkdownView.h.
|
inlineprotected |
Definition at line 100 of file MarkdownView.h.
|
protected |
Definition at line 335 of file MarkdownView.cpp.
|
overridevirtual |
Called when view is being removed from stack
Implements cdc::ui::IView.
Definition at line 261 of file MarkdownView.cpp.
|
overridevirtual |
Handle key press
| key | Key character ('0'-'9', 'Y', 'N', etc.) |
Implements cdc::ui::IView.
Definition at line 278 of file MarkdownView.cpp.
References activateSelected(), cdc::ui::CONSUMED, cycleInteractive(), cdc::ui::ViewBase::dirty_, cdc::ui::IGNORED, cdc::ui::KEY_DOWN, cdc::ui::KEY_NO, cdc::ui::KEY_UP, cdc::ui::KEY_YES, cdc::ui::REQUEST_POP, and selectedRef().
|
overridevirtual |
Handle long key press (optional)
| key | Key character |
Reimplemented from cdc::ui::IView.
Definition at line 305 of file MarkdownView.cpp.
References cdc::ui::CONSUMED, cdc::ui::ViewBase::dirty_, cdc::ui::IGNORED, cdc::ui::KEY_DOWN, and cdc::ui::KEY_UP.
|
protectedvirtual |
Rebuild the interactive-element list from the rendered rows. Base finds task-list checkboxes; subclasses extend with links/forms.
Definition at line 402 of file MarkdownView.cpp.
References addInteract(), cdc::ui::Bullet, Check, clearInteract(), Image, Link, and cdc::ui::Ordered.
Referenced by init().
|
overridevirtual |
Render view content to display buffer
| partial | True for partial update, false for full refresh |
Implements cdc::ui::IView.
Definition at line 495 of file MarkdownView.cpp.
References cdc::ui::Blank, BLANK_HEIGHT, cdc::ui::mdfont::Builtin, cdc::ui::Bullet, cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::ui::render::drawFooterBar(), cdc::ui::render::drawHeaderLeft(), cdc::ui::render::drawScrollIndicator(), cdc::ui::render::drawText(), FOOTER_HEIGHT, cdc::hal::getDisplayInstance(), getFooterHint(), cdc::ui::getGfxFont(), INDENT_PX, cdc::ui::Ordered, cdc::ui::Quote, cdc::ui::Rule, RULE_HEIGHT, SCROLL_INDICATOR_WIDTH, cdc::ui::TEXT_MARGIN, TEXT_START_Y, cdc::ui::TITLE_Y, and cdc::ui::tr().
|
protected |
Definition at line 349 of file MarkdownView.cpp.
Referenced by activateSelected(), and onKey().
| void cdc::ui::MarkdownView::selectMarker | ( | uint16_t | linkNum | ) |
Highlight the row containing the inline marker "[linkNum]" and scroll it into view. Pass 0 to clear the highlight. Used for in-view link selection by subclasses; the base renders the highlighted row inverted.
Definition at line 314 of file MarkdownView.cpp.
References cdc::ui::ViewBase::dirty_.
|
inline |
Definition at line 89 of file MarkdownView.h.
|
staticconstexpr |
Visual-row cap.
Definition at line 25 of file MarkdownView.h.
Referenced by init(), and initPlain().
|
staticconstexpr |
Source byte cap.
Definition at line 24 of file MarkdownView.h.
Referenced by init(), and initPlain().