|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
Generic canvas view exposed to WASM plugins for custom UIs. More...
#include <CanvasView.h>
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 |
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.
| using cdc::ui::CanvasView::KeyCallback = void(*)(char key, uint32_t focused_widget) |
Definition at line 46 of file CanvasView.h.
| using cdc::ui::CanvasView::LongPressCallback = void(*)(char key) |
Definition at line 48 of file CanvasView.h.
| using cdc::ui::CanvasView::WidgetCallback = void(*)(uint32_t widget_id, WidgetEvent event) |
Definition at line 47 of file CanvasView.h.
|
strong |
| Enumerator | |
|---|---|
| Changed | |
| Committed | |
| Cancelled | |
Definition at line 31 of file CanvasView.h.
|
strong |
| Enumerator | |
|---|---|
| None | |
| Slider | |
| Text | |
| Button | |
Definition at line 24 of file CanvasView.h.
| bool cdc::ui::CanvasView::addButton | ( | uint32_t | id | ) |
Definition at line 327 of file CanvasView.cpp.
References Button, and MAX_WIDGETS.
| 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.
| 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.
| void cdc::ui::CanvasView::clearBody | ( | ) |
Definition at line 105 of file CanvasView.cpp.
| void cdc::ui::CanvasView::commit | ( | bool | full_refresh | ) |
Definition at line 266 of file CanvasView.cpp.
References cdc::ui::ViewBase::markDirty().
| 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.
| 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.
| void cdc::ui::CanvasView::drawText | ( | int16_t | x, |
| int16_t | y, | ||
| const char * | text ) |
Definition at line 128 of file CanvasView.cpp.
| 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.
| 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.
| 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().
|
inline |
Definition at line 85 of file CanvasView.h.
|
inlineoverridevirtual |
| int cdc::ui::CanvasView::getText | ( | uint32_t | id, |
| char * | out, | ||
| size_t | cap ) const |
Definition at line 380 of file CanvasView.cpp.
| bool cdc::ui::CanvasView::getValue | ( | uint32_t | id, |
| int32_t * | out ) const |
Definition at line 360 of file CanvasView.cpp.
| void cdc::ui::CanvasView::init | ( | const char * | title | ) |
Definition at line 60 of file CanvasView.cpp.
References cdc::ui::ViewBase::customFooter_, cdc::ui::ViewBase::dirty_, and cdc::ui::ViewBase::title_.
| 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.
|
overridevirtual |
Called when view becomes active (pushed or becomes top)
| context | Optional context data from parent |
Implements cdc::ui::IView.
Definition at line 565 of file CanvasView.cpp.
References cdc::ui::ViewBase::onEnter().
|
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().
|
overridevirtual |
Handle key press
| key | Key character ('0'-'9', 'Y', 'N', etc.) |
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.
|
overridevirtual |
Handle long key press (optional)
| key | Key character |
Reimplemented from cdc::ui::IView.
Definition at line 557 of file CanvasView.cpp.
References cdc::ui::CONSUMED, and cdc::ui::IGNORED.
|
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().
| bool cdc::ui::CanvasView::removeWidget | ( | uint32_t | id | ) |
Definition at line 338 of file CanvasView.cpp.
|
overridevirtual |
Render view content to display buffer
| partial | True 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.
| bool cdc::ui::CanvasView::setFocus | ( | uint32_t | id | ) |
Definition at line 389 of file CanvasView.cpp.
|
inline |
Select one of the canonical font ids (see cdc_views/Fonts.h).
Definition at line 65 of file CanvasView.h.
| void cdc::ui::CanvasView::setFooter | ( | const char * | hint | ) |
Definition at line 83 of file CanvasView.cpp.
References cdc::ui::ViewBase::customFooter_.
|
inline |
Definition at line 52 of file CanvasView.h.
| void cdc::ui::CanvasView::setKeyRepeat | ( | uint16_t | initial_ms, |
| uint16_t | repeat_ms ) |
Definition at line 88 of file CanvasView.cpp.
| 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.
| bool cdc::ui::CanvasView::setText | ( | uint32_t | id, |
| const char * | text ) |
Definition at line 367 of file CanvasView.cpp.
References Text.
|
inline |
Definition at line 63 of file CanvasView.h.
|
inline |
Definition at line 62 of file CanvasView.h.
| bool cdc::ui::CanvasView::setValue | ( | uint32_t | id, |
| int32_t | value ) |
Definition at line 353 of file CanvasView.cpp.
References Slider.
|
inline |
Definition at line 53 of file CanvasView.h.
|
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().
|
staticconstexpr |
Definition at line 38 of file CanvasView.h.
Referenced by addText().
|
staticconstexpr |
Definition at line 37 of file CanvasView.h.
Referenced by addButton(), addSlider(), and addText().
|
staticconstexpr |
Definition at line 39 of file CanvasView.h.
|
staticconstexpr |
Definition at line 44 of file CanvasView.h.