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

Generic canvas view exposed to WASM plugins for custom UIs. More...

#include <CanvasView.h>

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

Public Types

enum class  WidgetType : uint8_t { None = 0 , Slider = 1 , Text = 2 , Button = 3 }
enum class  WidgetEvent : uint8_t { Changed = 1 , Committed = 2 , Cancelled = 3 }
using KeyCallback = void(*)(char key, uint32_t focused_widget)
using WidgetCallback = void(*)(uint32_t widget_id, WidgetEvent event)
using LongPressCallback = void(*)(char key)

Public Member Functions

void init (const char *title)
void setKeyCallback (KeyCallback cb)
void setWidgetCallback (WidgetCallback cb)
void setLongPressCallback (LongPressCallback cb)
void setFooter (const char *hint)
void setKeyRepeat (uint16_t initial_ms, uint16_t repeat_ms)
void getBodySize (uint16_t *w, uint16_t *h) const
void clearBody ()
void setTextSize (uint8_t size)
void setTextInverted (bool inverted)
void setFontId (uint8_t font_id)
 Select one of the canonical font ids (see cdc_views/Fonts.h).
void drawText (int16_t x, int16_t y, const char *text)
void drawTextAligned (int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
void drawRect (int16_t x, int16_t y, int16_t w, int16_t h, bool filled)
void invertRect (int16_t x, int16_t y, int16_t w, int16_t h)
void drawHLine (int16_t x, int16_t y, int16_t w)
void drawVLine (int16_t x, int16_t y, int16_t h)
void commit (bool full_refresh)
bool addSlider (uint32_t id, int32_t min, int32_t max, int32_t initial, int32_t step)
bool addText (uint32_t id, uint16_t max_len, const char *initial)
bool addButton (uint32_t id)
bool removeWidget (uint32_t id)
bool setValue (uint32_t id, int32_t value)
bool getValue (uint32_t id, int32_t *out) const
bool setText (uint32_t id, const char *text)
int getText (uint32_t id, char *out, size_t cap) const
bool setFocus (uint32_t id)
uint32_t getFocus () const
void render (bool partial) override
InputResult onKey (char key) override
InputResult onLongPress (char key) override
void onEnter (void *context) override
void onResume () override
void onExit () override
const char * getName () const override
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 void onTick (uint32_t nowMs)

Static Public Attributes

static constexpr uint8_t MAX_WIDGETS = 8
static constexpr uint16_t MAX_TEXT_LEN = 256
static constexpr uint16_t T9_SETTLE_MS = 800
static constexpr uint16_t MAX_CMDS = 96
static constexpr uint16_t TEXT_ARENA = 2048

Additional Inherited Members

Protected Member Functions inherited from cdc::ui::ViewBase
void setTitle (const char *title)
const char * getTitle () const
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

Generic canvas view exposed to WASM plugins for custom UIs.

The plugin draws into the body area via host_view_canvas_* draw primitives. Inline widgets (slider, text-input, button) have host-owned input state while their visual representation is rendered by the plugin reading the widget value/text on each frame.

Coordinates are body-local: (0,0) is the top-left of the body area (display rows after the header up to the footer bar).

Definition at line 22 of file CanvasView.h.

Member Typedef Documentation

◆ KeyCallback

using cdc::ui::CanvasView::KeyCallback = void(*)(char key, uint32_t focused_widget)

Definition at line 46 of file CanvasView.h.

◆ LongPressCallback

using cdc::ui::CanvasView::LongPressCallback = void(*)(char key)

Definition at line 48 of file CanvasView.h.

◆ WidgetCallback

using cdc::ui::CanvasView::WidgetCallback = void(*)(uint32_t widget_id, WidgetEvent event)

Definition at line 47 of file CanvasView.h.

Member Enumeration Documentation

◆ WidgetEvent

enum class cdc::ui::CanvasView::WidgetEvent : uint8_t
strong
Enumerator
Changed 
Committed 
Cancelled 

Definition at line 31 of file CanvasView.h.

◆ WidgetType

enum class cdc::ui::CanvasView::WidgetType : uint8_t
strong
Enumerator
None 
Slider 
Text 
Button 

Definition at line 24 of file CanvasView.h.

Member Function Documentation

◆ addButton()

bool cdc::ui::CanvasView::addButton ( uint32_t id)

Definition at line 327 of file CanvasView.cpp.

References Button, and MAX_WIDGETS.

◆ addSlider()

bool cdc::ui::CanvasView::addSlider ( uint32_t id,
int32_t min,
int32_t max,
int32_t initial,
int32_t step )

Definition at line 293 of file CanvasView.cpp.

References MAX_WIDGETS, and Slider.

◆ addText()

bool cdc::ui::CanvasView::addText ( uint32_t id,
uint16_t max_len,
const char * initial )

Definition at line 309 of file CanvasView.cpp.

References MAX_TEXT_LEN, MAX_WIDGETS, and Text.

◆ clearBody()

void cdc::ui::CanvasView::clearBody ( )

Definition at line 105 of file CanvasView.cpp.

◆ commit()

void cdc::ui::CanvasView::commit ( bool full_refresh)

Definition at line 266 of file CanvasView.cpp.

References cdc::ui::ViewBase::markDirty().

◆ drawHLine()

void cdc::ui::CanvasView::drawHLine ( int16_t x,
int16_t y,
int16_t w )

Definition at line 187 of file CanvasView.cpp.

References MAX_CMDS.

◆ drawRect()

void cdc::ui::CanvasView::drawRect ( int16_t x,
int16_t y,
int16_t w,
int16_t h,
bool filled )

Definition at line 169 of file CanvasView.cpp.

References MAX_CMDS.

◆ drawText()

void cdc::ui::CanvasView::drawText ( int16_t x,
int16_t y,
const char * text )

Definition at line 128 of file CanvasView.cpp.

References LOG_W, and MAX_CMDS.

◆ drawTextAligned()

void cdc::ui::CanvasView::drawTextAligned ( int16_t x,
int16_t y,
int16_t w,
const char * text,
uint8_t align )

Definition at line 147 of file CanvasView.cpp.

References LOG_W, and MAX_CMDS.

◆ drawVLine()

void cdc::ui::CanvasView::drawVLine ( int16_t x,
int16_t y,
int16_t h )

Definition at line 197 of file CanvasView.cpp.

References MAX_CMDS.

◆ getBodySize()

void cdc::ui::CanvasView::getBodySize ( uint16_t * w,
uint16_t * h ) const

Definition at line 94 of file CanvasView.cpp.

References cdc::ui::display, and cdc::hal::getDisplayInstance().

◆ getFocus()

uint32_t cdc::ui::CanvasView::getFocus ( ) const
inline

Definition at line 85 of file CanvasView.h.

◆ getName()

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

Get view name for debugging

Implements cdc::ui::IView.

Definition at line 93 of file CanvasView.h.

◆ getText()

int cdc::ui::CanvasView::getText ( uint32_t id,
char * out,
size_t cap ) const

Definition at line 380 of file CanvasView.cpp.

◆ getValue()

bool cdc::ui::CanvasView::getValue ( uint32_t id,
int32_t * out ) const

Definition at line 360 of file CanvasView.cpp.

◆ init()

void cdc::ui::CanvasView::init ( const char * title)

◆ invertRect()

void cdc::ui::CanvasView::invertRect ( int16_t x,
int16_t y,
int16_t w,
int16_t h )

Definition at line 181 of file CanvasView.cpp.

◆ onEnter()

void cdc::ui::CanvasView::onEnter ( void * context)
overridevirtual

Called when view becomes active (pushed or becomes top)

Parameters
contextOptional context data from parent

Implements cdc::ui::IView.

Definition at line 565 of file CanvasView.cpp.

References cdc::ui::ViewBase::onEnter().

◆ onExit()

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

Called when view is being removed from stack

Implements cdc::ui::IView.

Definition at line 575 of file CanvasView.cpp.

References cdc::hal::IKeypad::DEFER_SRC_VIEW, cdc::hal::getKeypadInstance(), and cdc::ui::ViewBase::onExit().

◆ onKey()

InputResult cdc::ui::CanvasView::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 522 of file CanvasView.cpp.

References cdc::ui::CONSUMED, cdc::ui::IGNORED, cdc::ui::KEY_NO, and cdc::ui::REQUEST_POP.

◆ onLongPress()

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

Handle long key press (optional)

Parameters
keyKey character
Returns
Input result

Reimplemented from cdc::ui::IView.

Definition at line 557 of file CanvasView.cpp.

References cdc::ui::CONSUMED, and cdc::ui::IGNORED.

◆ onResume()

void cdc::ui::CanvasView::onResume ( )
overridevirtual

Called when view becomes visible again (child popped)

Implements cdc::ui::IView.

Definition at line 570 of file CanvasView.cpp.

References cdc::ui::ViewBase::onResume().

◆ removeWidget()

bool cdc::ui::CanvasView::removeWidget ( uint32_t id)

Definition at line 338 of file CanvasView.cpp.

◆ render()

void cdc::ui::CanvasView::render ( bool partial)
overridevirtual

Render view content to display buffer

Parameters
partialTrue for partial update, false for full refresh

Implements cdc::ui::IView.

Definition at line 583 of file CanvasView.cpp.

References cdc::ui::ViewBase::customFooter_, cdc::ui::ViewBase::dirty_, cdc::ui::display, cdc::ui::render::drawFooterBar(), cdc::ui::render::drawHeaderLeft(), cdc::hal::getDisplayInstance(), cdc::ui::ViewBase::title_, and cdc::ui::TITLE_Y.

◆ setFocus()

bool cdc::ui::CanvasView::setFocus ( uint32_t id)

Definition at line 389 of file CanvasView.cpp.

◆ setFontId()

void cdc::ui::CanvasView::setFontId ( uint8_t font_id)
inline

Select one of the canonical font ids (see cdc_views/Fonts.h).

Definition at line 65 of file CanvasView.h.

◆ setFooter()

void cdc::ui::CanvasView::setFooter ( const char * hint)

Definition at line 83 of file CanvasView.cpp.

References cdc::ui::ViewBase::customFooter_.

◆ setKeyCallback()

void cdc::ui::CanvasView::setKeyCallback ( KeyCallback cb)
inline

Definition at line 52 of file CanvasView.h.

◆ setKeyRepeat()

void cdc::ui::CanvasView::setKeyRepeat ( uint16_t initial_ms,
uint16_t repeat_ms )

Definition at line 88 of file CanvasView.cpp.

◆ setLongPressCallback()

void cdc::ui::CanvasView::setLongPressCallback ( LongPressCallback cb)

Register a plugin long-press handler. Setting a non-null callback opts this canvas into deferred short-press keypad mode while it is active.

Definition at line 552 of file CanvasView.cpp.

◆ setText()

bool cdc::ui::CanvasView::setText ( uint32_t id,
const char * text )

Definition at line 367 of file CanvasView.cpp.

References Text.

◆ setTextInverted()

void cdc::ui::CanvasView::setTextInverted ( bool inverted)
inline

Definition at line 63 of file CanvasView.h.

◆ setTextSize()

void cdc::ui::CanvasView::setTextSize ( uint8_t size)
inline

Definition at line 62 of file CanvasView.h.

◆ setValue()

bool cdc::ui::CanvasView::setValue ( uint32_t id,
int32_t value )

Definition at line 353 of file CanvasView.cpp.

References Slider.

◆ setWidgetCallback()

void cdc::ui::CanvasView::setWidgetCallback ( WidgetCallback cb)
inline

Definition at line 53 of file CanvasView.h.

Member Data Documentation

◆ MAX_CMDS

uint16_t cdc::ui::CanvasView::MAX_CMDS = 96
staticconstexpr

Retained display list: draw primitives are recorded here and replayed in render() after the framework clears the screen. Fixed-size, no heap.

Definition at line 43 of file CanvasView.h.

Referenced by drawHLine(), drawRect(), drawText(), drawTextAligned(), and drawVLine().

◆ MAX_TEXT_LEN

uint16_t cdc::ui::CanvasView::MAX_TEXT_LEN = 256
staticconstexpr

Definition at line 38 of file CanvasView.h.

Referenced by addText().

◆ MAX_WIDGETS

uint8_t cdc::ui::CanvasView::MAX_WIDGETS = 8
staticconstexpr

Definition at line 37 of file CanvasView.h.

Referenced by addButton(), addSlider(), and addText().

◆ T9_SETTLE_MS

uint16_t cdc::ui::CanvasView::T9_SETTLE_MS = 800
staticconstexpr

Definition at line 39 of file CanvasView.h.

◆ TEXT_ARENA

uint16_t cdc::ui::CanvasView::TEXT_ARENA = 2048
staticconstexpr

Definition at line 44 of file CanvasView.h.


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