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

Scrollable viewer that renders a Markdown source. More...

#include <MarkdownView.h>

Inheritance diagram for cdc::ui::MarkdownView:
cdc::ui::ViewBase cdc::ui::IView

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 InteractRefselectedRef () 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

Detailed Description

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.

Member Typedef Documentation

◆ CheckSaveFn

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.

Member Enumeration Documentation

◆ Interact

enum class cdc::ui::MarkdownView::Interact : uint8_t
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.

Member Function Documentation

◆ activateSelected()

void cdc::ui::MarkdownView::activateSelected ( )
protectedvirtual

◆ addInteract()

void cdc::ui::MarkdownView::addInteract ( uint16_t row,
Interact kind,
uint16_t id,
uint32_t srcOff )
protected

Definition at line 344 of file MarkdownView.cpp.

Referenced by rebuildInteractive().

◆ appendParsed()

void cdc::ui::MarkdownView::appendParsed ( const StyledLine & line)

◆ clearInteract()

void cdc::ui::MarkdownView::clearInteract ( )
inlineprotected

Definition at line 104 of file MarkdownView.h.

Referenced by rebuildInteractive().

◆ clearSelection()

void cdc::ui::MarkdownView::clearSelection ( )
inline

Clear the current interactive selection.

Definition at line 78 of file MarkdownView.h.

References cdc::ui::ViewBase::dirty_.

◆ cycleInteractive()

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().

◆ fireCheckSave()

void cdc::ui::MarkdownView::fireCheckSave ( )
protected

Run the persistence callback with the current source (if set).

Definition at line 447 of file MarkdownView.cpp.

Referenced by activateSelected().

◆ flipCheckChar()

bool cdc::ui::MarkdownView::flipCheckChar ( uint32_t srcOff)
protected

Toggle a checkbox state char in the source.

Returns
the new checked state.

Definition at line 438 of file MarkdownView.cpp.

References cdc::ui::ViewBase::dirty_.

Referenced by activateSelected().

◆ getFooterHint()

const char * cdc::ui::MarkdownView::getFooterHint ( ) const
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().

◆ getName()

const char * cdc::ui::MarkdownView::getName ( ) const
inlineoverridevirtual

Get view name for debugging

Implements cdc::ui::IView.

Definition at line 53 of file MarkdownView.h.

◆ init()

void cdc::ui::MarkdownView::init ( const char * title,
const char * src,
size_t len )

Loads and lays out a Markdown source.

Parameters
titleHeader title (CP437).
srcMarkdown source (CP437; ASCII markup is codepage-independent).
lenSource 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.

◆ initPlain()

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.

Parameters
titleHeader title (CP437).
srcText (CP437).
lenSource 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.

◆ interactiveCount()

uint16_t cdc::ui::MarkdownView::interactiveCount ( ) const
inline

Number of interactive elements on the page.

Definition at line 81 of file MarkdownView.h.

◆ mdRowCount()

uint16_t cdc::ui::MarkdownView::mdRowCount ( ) const
inlineprotected

Definition at line 100 of file MarkdownView.h.

◆ mdRowInfo()

void cdc::ui::MarkdownView::mdRowInfo ( uint16_t i,
const char *& text,
uint16_t & len,
bool & first,
uint32_t & srcOff ) const
protected

Definition at line 335 of file MarkdownView.cpp.

◆ onExit()

void cdc::ui::MarkdownView::onExit ( )
overridevirtual

Called when view is being removed from stack

Implements cdc::ui::IView.

Definition at line 261 of file MarkdownView.cpp.

◆ onKey()

InputResult cdc::ui::MarkdownView::onKey ( char key)
overridevirtual

Handle key press

Parameters
keyKey character ('0'-'9', 'Y', 'N', etc.)
Returns
Input result

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().

◆ onLongPress()

InputResult cdc::ui::MarkdownView::onLongPress ( char key)
overridevirtual

Handle long key press (optional)

Parameters
keyKey character
Returns
Input result

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.

◆ rebuildInteractive()

void cdc::ui::MarkdownView::rebuildInteractive ( )
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().

◆ render()

◆ selectedRef()

const MarkdownView::InteractRef * cdc::ui::MarkdownView::selectedRef ( ) const
protected

Definition at line 349 of file MarkdownView.cpp.

Referenced by activateSelected(), and onKey().

◆ selectMarker()

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_.

◆ setCheckSave()

void cdc::ui::MarkdownView::setCheckSave ( CheckSaveFn fn,
void * ud )
inline

Definition at line 89 of file MarkdownView.h.

Member Data Documentation

◆ MAX_ROWS

uint16_t cdc::ui::MarkdownView::MAX_ROWS = 600
staticconstexpr

Visual-row cap.

Definition at line 25 of file MarkdownView.h.

Referenced by init(), and initPlain().

◆ MAX_SOURCE

uint32_t cdc::ui::MarkdownView::MAX_SOURCE = 64u * 1024u
staticconstexpr

Source byte cap.

Definition at line 24 of file MarkdownView.h.

Referenced by init(), and initPlain().


The documentation for this class was generated from the following files: