|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <ViewStack.h>
Public Types | |
| using | InactivityCallback = void(*)() |
Public Member Functions | |
| void | push (IView *view, void *context=nullptr) |
| void | pop () |
| void | replace (IView *view, void *context=nullptr) |
| void | popToRoot () |
| void | popToAnchor (IView *anchor) |
| Pops views until the specified anchor view is the current view. | |
| void | popToDepth (uint8_t targetDepth) |
| Pops views until the stack depth is at most targetDepth. | |
| IView * | current () const |
| IView * | at (uint8_t depth) const |
| uint8_t | depth () const |
| bool | isEmpty () const |
| void | dispatchKey (char key) |
| void | dispatchLongPress (char key) |
| void | dispatchTick (uint32_t nowMs) |
| void | render (bool synchronous=false) |
| Render current view (and modal if present) and flush to display. | |
| bool | needsRender () const |
| void | showModal (IView *modal) |
| void | hideModal () |
| void | removeModal (IView *modal) |
| Remove a specific modal from any position in the modal stack. | |
| bool | hasModal () const |
| IView * | getModal () const |
| void | forceFullRefresh () |
| bool | acquireExclusive (const void *owner) |
| Acquires exclusive ownership of the view stack. | |
| bool | releaseExclusive (const void *owner) |
| Releases exclusive ownership. | |
| const void * | exclusiveOwner () const |
| Returns current exclusive owner, or nullptr if none. | |
| void | setInactivityTimeout (InactivityCallback callback, uint32_t timeoutMs) |
| void | resetInactivityTimer () |
| void | checkInactivity (uint32_t nowMs) |
Static Public Member Functions | |
| static ViewStack & | instance () |
| Returns singleton view-stack instance. | |
Static Public Attributes | |
| static constexpr uint8_t | MAX_DEPTH = 20 |
ViewStack - Navigation stack for views
Manages a stack of views for hierarchical navigation. Supports push/pop/replace operations and modal overlays.
Reference: ~/GIT/cdc-badge-os-legacy/main/app_input.cpp (state machine)
Definition at line 18 of file ViewStack.h.
| using cdc::ui::ViewStack::InactivityCallback = void(*)() |
Callback type for inactivity timeout
Definition at line 196 of file ViewStack.h.
| bool cdc::ui::ViewStack::acquireExclusive | ( | const void * | owner | ) |
Acquires exclusive ownership of the view stack.
| owner | Caller-supplied identity token (use the view pointer or a static address). |
While exclusive ownership is held, push/pop/replace/showModal from anyone other than the owner are rejected with a warning log.
Definition at line 480 of file ViewStack.cpp.
References LOG_D, LOG_W, and cdc::ui::TAG.
Referenced by cdc::plugin_manager::PluginUiState::acquireExclusive().
| IView * cdc::ui::ViewStack::at | ( | uint8_t | depth | ) | const |
Get view at specific depth (0 = root)
Definition at line 246 of file ViewStack.cpp.
| void cdc::ui::ViewStack::checkInactivity | ( | uint32_t | nowMs | ) |
Check and handle inactivity (call in tick/loop)
| nowMs | Current time in milliseconds |
Definition at line 451 of file ViewStack.cpp.
References LOG_I, and cdc::ui::TAG.
Referenced by cdc::ui::ui_process().
| IView * cdc::ui::ViewStack::current | ( | ) | const |
Get current (top) view
Definition at line 240 of file ViewStack.cpp.
Referenced by cdc::serial::cmdPaste(), cdc::ui::isBadgeLocked(), cdc::plugin_manager::PluginUiState::setViewFooter(), and cdc::plugin_manager::PluginUiState::setViewLifecycle().
|
inline |
Get current stack depth
Definition at line 83 of file ViewStack.h.
Referenced by cdc::ui::isBadgeLocked(), and cdc::plugin_manager::PluginManager::startPlugin().
| void cdc::ui::ViewStack::dispatchKey | ( | char | key | ) |
Dispatch key press to current view
| key | Key character |
Definition at line 252 of file ViewStack.cpp.
References cdc::core::EventBus::instance(), cdc::core::KEY_PRESSED, cdc::ui::IView::onKey(), cdc::core::EventBus::publish(), cdc::ui::REQUEST_POP, and resetInactivityTimer().
Referenced by cdc::ui::ui_process().
| void cdc::ui::ViewStack::dispatchLongPress | ( | char | key | ) |
Dispatch long press to current view
| key | Key character |
Definition at line 277 of file ViewStack.cpp.
References cdc::ui::CONSUMED, cdc::core::EventBus::instance(), cdc::core::KEY_LONG_PRESS, cdc::ui::IView::onLongPress(), cdc::core::EventBus::publish(), and cdc::ui::REQUEST_POP.
Referenced by cdc::ui::ui_init().
| void cdc::ui::ViewStack::dispatchTick | ( | uint32_t | nowMs | ) |
Dispatch tick to current view and modal
| nowMs | Current time |
Definition at line 307 of file ViewStack.cpp.
References cdc::ui::IView::onTick().
Referenced by cdc::ui::ui_process().
|
inline |
Returns current exclusive owner, or nullptr if none.
Definition at line 189 of file ViewStack.h.
|
inline |
Force next render to use FULL refresh (called automatically after view changes)
Definition at line 165 of file ViewStack.h.
|
inline |
Get the top (input-receiving) modal view, or nullptr if none.
Definition at line 159 of file ViewStack.h.
|
inline |
Check if any modal is active
Definition at line 154 of file ViewStack.h.
| void cdc::ui::ViewStack::hideModal | ( | ) |
Hide the top modal, revealing the next modal beneath it (or the base view).
Definition at line 428 of file ViewStack.cpp.
Referenced by cdc::ui::WifiHandlers::connect(), cdc::ui::hideContextMenu(), cdc::ui::hideMessage(), cdc::ui::msgTransferUiProcess(), cdc::ui::ConfirmView::onKey(), cdc::ui::ToastView::onKey(), cdc::ui::ToastView::onTick(), cdc::ui::runTropicCacheCleanup(), cdc::ui::runTropicCacheRebuild(), cdc::ui::startBluetoothScan(), cdc::ui::wifiConnect(), cdc::ui::wifiNtpSync(), and cdc::ui::wifiStartScan().
|
static |
Returns singleton view-stack instance.
Get singleton instance
Definition at line 34 of file ViewStack.cpp.
References instance().
Referenced by cdc::plugin_manager::PluginUiState::acquireExclusive(), cdc::ui::SleepManager::checkLockScreenSleep(), cdc::serial::cmdPaste(), cdc::ui::WifiHandlers::connect(), cdc::mod_fido2::fido2_ui_user_presence_callback(), cdc::ui::hideContextMenu(), cdc::ui::hideMessage(), host_lockscreen_alert(), host_ui_pop(), host_ui_pop_to_plugin(), host_ui_push_info(), host_ui_push_toast(), cdc::plugin_manager::PluginUiState::insertListItem(), instance(), cdc::ui::isBadgeLocked(), cdc::ui::msgTransferUiProcess(), cdc::ui::onBlePairingRequestEvent(), cdc::ui::onBluetoothMenuSelect(), cdc::mod_nvsedit::onDeleteKey(), cdc::ui::onExpertMenuSelect(), cdc::mod_gpg::onGpgPinComplete(), cdc::ui::onInactivityTimeout(), cdc::ui::ColorPickerView::onKey(), cdc::ui::ConfirmView::onKey(), cdc::ui::DateInputView::onKey(), cdc::ui::SliderView::onKey(), cdc::ui::T9InputView::onKey(), cdc::ui::TimeInputView::onKey(), cdc::ui::ToastView::onKey(), cdc::ui::onLanguageSelect(), cdc::mod_2fa::onListSelect(), cdc::ui::T9InputView::onLongPress(), cdc::ui::onMainMenuSelect(), cdc::mod_password::onMenuDeleteConfirm(), cdc::mod_fido2::onPinCancel(), cdc::ui::settings::onPinChangeComplete(), cdc::mod_fido2::onPinFailure(), cdc::mod_fido2::onPinSuccess(), cdc::ui::onPinSuccess(), cdc::mod_fido2::onPromptApprove(), cdc::mod_gpg::onReceivedActionSelect(), cdc::mod_gpg::onReceivedDeleteConfirm(), cdc::mod_vcard::onReceivedDeleteConfirm(), cdc::mod_gpg::onSettingsSelect(), cdc::ui::onSettingsSelect(), cdc::ui::BlePairingView::onTick(), cdc::ui::ToastView::onTick(), cdc::ui::onToolsSelect(), cdc::ui::onUnlockRequested(), cdc::ui::onWifiMainSelect(), cdc::mod_2fa::onWizardAlgo(), cdc::mod_gpg::onWizardCurve(), cdc::mod_gpg::onWizardEmail(), cdc::mod_2fa::onWizardIssuer(), cdc::mod_gpg::onWizardName(), cdc::mod_password::onWizardUsername(), cdc::mod_vcard::openReceivedList(), cdc::ui::performAntiBlockLock(), cdc::ui::prepareForBootloaderReset(), cdc::mod_fido2::promptComplete(), cdc::mod_2fa::pushAlgoStep(), cdc::plugin_manager::PluginUiState::pushCanvas(), cdc::plugin_manager::PluginUiState::pushColorPicker(), cdc::plugin_manager::PluginUiState::pushConfirm(), cdc::plugin_manager::PluginUiState::pushContextMenu(), cdc::mod_vcard::pushCurrentStep(), cdc::plugin_manager::PluginUiState::pushDate(), cdc::plugin_manager::PluginUiState::pushList(), cdc::plugin_manager::PluginUiState::pushPin(), cdc::plugin_manager::PluginUiState::pushSlider(), cdc::plugin_manager::PluginUiState::pushT9(), cdc::mod_2fa::pushT9WizardStep(), cdc::mod_password::pushT9WizardStep(), cdc::plugin_manager::PluginUiState::pushTime(), cdc::mod_2fa::pushTouchStep(), cdc::mod_2fa::pushUsbCrStep(), cdc::plugin_manager::PluginUiState::releaseExclusive(), cdc::plugin_manager::PluginUiState::removeListItem(), cdc::plugin_manager::PluginUiState::resetForPluginStop(), cdc::mod_fido2::restoreView(), cdc::ui::runTropicCacheCleanup(), cdc::ui::runTropicCacheRebuild(), cdc::plugin_manager::PluginUiState::setInactivity(), cdc::plugin_manager::PluginUiState::setViewFooter(), cdc::plugin_manager::PluginUiState::setViewLifecycle(), cdc::ui::showBackupMenu(), cdc::ui::showBeaconMenu(), cdc::ui::showBluetoothMenu(), cdc::ui::showConfirm(), cdc::ui::showContextMenu(), cdc::mod_fido2::showDetail(), cdc::mod_password::showDetails(), cdc::ui::showDuressPinSetup(), cdc::ui::showExpertMenu(), cdc::mod_gpg::showExport(), cdc::ui::showInfo(), cdc::mod_nvsedit::showKeyListView(), cdc::ui::showListView(), cdc::ui::showMessage(), cdc::ui::showModulesView(), cdc::mod_nvsedit::showNamespaceListView(), cdc::ui::showPairedDevices(), cdc::ui::showPinEntry(), cdc::ui::showQRCode(), cdc::mod_gpg::showReceivedDetail(), cdc::mod_gpg::showReceivedKeys(), cdc::mod_gpg::showSettings(), cdc::ui::showSlider(), cdc::mod_gpg::showStatus(), cdc::ui::showT9Input(), cdc::ui::showToastInternal(), cdc::mod_nvsedit::showValueView(), cdc::mod_vcard::showVcardDetails(), cdc::ui::showWifiMainMenu(), cdc::ui::startBluetoothScan(), cdc::plugin_manager::PluginManager::startPlugin(), cdc::plugin_manager::PluginManager::stopActivePlugin(), cdc::ui::ui_init(), cdc::ui::ui_process(), cdc::plugin_manager::PluginManager::unloadAllFromRam(), cdc::plugin_manager::PluginManager::unloadFromRam(), cdc::plugin_manager::PluginUiState::updateListItem(), cdc::ui::updateLockScreenClock(), cdc::ui::wifiConnect(), cdc::ui::wifiFinishSetup(), cdc::ui::wifiNtpSync(), cdc::ui::wifiShowAuthMenu(), cdc::ui::wifiShowIpModeMenu(), cdc::ui::wifiStartScan(), cdc::mod_2fa::wizardFinish(), cdc::mod_password::wizardFinish(), cdc::mod_vcard::wizardFinish(), cdc::mod_2fa::wizardStart(), and cdc::mod_gpg::wizardStart().
|
inline |
Check if stack is empty
Definition at line 88 of file ViewStack.h.
| bool cdc::ui::ViewStack::needsRender | ( | ) | const |
Check if any view needs rendering
Definition at line 377 of file ViewStack.cpp.
References cdc::ui::IView::needsRender(), and needsRender().
Referenced by needsRender(), and render().
| void cdc::ui::ViewStack::pop | ( | ) |
Pop the top view from stack Does nothing if only one view remains
Definition at line 182 of file ViewStack.cpp.
Referenced by cdc::mod_nvsedit::onDeleteKey(), cdc::mod_gpg::onGpgPinComplete(), cdc::ui::onInactivityTimeout(), cdc::ui::ColorPickerView::onKey(), cdc::ui::DateInputView::onKey(), cdc::ui::SliderView::onKey(), cdc::ui::T9InputView::onKey(), cdc::ui::TimeInputView::onKey(), cdc::ui::onLanguageSelect(), cdc::ui::T9InputView::onLongPress(), cdc::ui::settings::onPinChangeComplete(), cdc::mod_gpg::onReceivedDeleteConfirm(), cdc::mod_gpg::onWizardCurve(), cdc::plugin_manager::PluginManager::stopActivePlugin(), cdc::plugin_manager::PluginManager::unloadAllFromRam(), cdc::plugin_manager::PluginManager::unloadFromRam(), and cdc::ui::wifiFinishSetup().
| void cdc::ui::ViewStack::popToAnchor | ( | IView * | anchor | ) |
Pops views until the specified anchor view is the current view.
| anchor | Anchor view to return to. |
Stops popping if the anchor is reached or only the root view remains. Useful for returning to a list view after wizard completion.
Definition at line 224 of file ViewStack.cpp.
Referenced by cdc::mod_password::onMenuDeleteConfirm(), cdc::mod_vcard::onReceivedDeleteConfirm(), cdc::mod_2fa::wizardFinish(), cdc::mod_password::wizardFinish(), and cdc::mod_vcard::wizardFinish().
| void cdc::ui::ViewStack::popToDepth | ( | uint8_t | targetDepth | ) |
Pops views until the stack depth is at most targetDepth.
| targetDepth | Depth to collapse down to; never pops below the root. |
Used by host_ui_pop_to_plugin to return to a plugin's first view in one step, since plugin root views have no stable pointer for popToAnchor.
Definition at line 233 of file ViewStack.cpp.
Referenced by host_ui_pop_to_plugin().
| void cdc::ui::ViewStack::popToRoot | ( | ) |
Pop all views except root
Definition at line 217 of file ViewStack.cpp.
| void cdc::ui::ViewStack::push | ( | IView * | view, |
| void * | context = nullptr ) |
Push a view onto the stack
| view | View to push |
| context | Optional context to pass to onEnter |
Definition at line 177 of file ViewStack.cpp.
Referenced by host_ui_push_info(), cdc::ui::onBluetoothMenuSelect(), cdc::ui::onExpertMenuSelect(), cdc::mod_2fa::onListSelect(), cdc::ui::onMainMenuSelect(), cdc::mod_gpg::onReceivedActionSelect(), cdc::mod_gpg::onSettingsSelect(), cdc::ui::onSettingsSelect(), cdc::ui::onToolsSelect(), cdc::ui::onUnlockRequested(), cdc::ui::onWifiMainSelect(), cdc::mod_2fa::onWizardAlgo(), cdc::mod_gpg::onWizardEmail(), cdc::mod_2fa::onWizardIssuer(), cdc::mod_gpg::onWizardName(), cdc::mod_password::onWizardUsername(), cdc::mod_vcard::openReceivedList(), cdc::mod_2fa::pushAlgoStep(), cdc::plugin_manager::PluginUiState::pushCanvas(), cdc::plugin_manager::PluginUiState::pushColorPicker(), cdc::mod_vcard::pushCurrentStep(), cdc::plugin_manager::PluginUiState::pushDate(), cdc::plugin_manager::PluginUiState::pushPin(), cdc::plugin_manager::PluginUiState::pushSlider(), cdc::plugin_manager::PluginUiState::pushT9(), cdc::mod_2fa::pushT9WizardStep(), cdc::mod_password::pushT9WizardStep(), cdc::plugin_manager::PluginUiState::pushTime(), cdc::mod_2fa::pushTouchStep(), cdc::mod_2fa::pushUsbCrStep(), cdc::ui::showBackupMenu(), cdc::ui::showBeaconMenu(), cdc::ui::showBluetoothMenu(), cdc::mod_fido2::showDetail(), cdc::mod_password::showDetails(), cdc::ui::showDuressPinSetup(), cdc::ui::showExpertMenu(), cdc::mod_gpg::showExport(), cdc::ui::showInfo(), cdc::mod_nvsedit::showKeyListView(), cdc::ui::showListView(), cdc::ui::showModulesView(), cdc::mod_nvsedit::showNamespaceListView(), cdc::ui::showPairedDevices(), cdc::ui::showPinEntry(), cdc::ui::showQRCode(), cdc::mod_gpg::showReceivedDetail(), cdc::mod_gpg::showReceivedKeys(), cdc::mod_gpg::showSettings(), cdc::ui::showSlider(), cdc::mod_gpg::showStatus(), cdc::ui::showT9Input(), cdc::mod_nvsedit::showValueView(), cdc::mod_vcard::showVcardDetails(), cdc::ui::showWifiMainMenu(), cdc::ui::startBluetoothScan(), cdc::ui::ui_init(), cdc::ui::wifiShowAuthMenu(), cdc::ui::wifiShowIpModeMenu(), cdc::ui::wifiStartScan(), cdc::mod_2fa::wizardStart(), and cdc::mod_gpg::wizardStart().
| bool cdc::ui::ViewStack::releaseExclusive | ( | const void * | owner | ) |
Releases exclusive ownership.
| owner | Must match the token used in acquireExclusive. |
Definition at line 495 of file ViewStack.cpp.
References LOG_D, LOG_W, and cdc::ui::TAG.
Referenced by cdc::plugin_manager::PluginUiState::releaseExclusive().
| void cdc::ui::ViewStack::removeModal | ( | IView * | modal | ) |
Remove a specific modal from any position in the modal stack.
Unlike hideModal() this does not require the modal to be on top; modals stacked above it stay in place. Used to retract an overlay whose backing view object is about to be destroyed (e.g. plugin teardown), so the stack keeps no dangling pointer. No-op if the modal is not currently shown.
| modal | The modal view to remove. |
Definition at line 433 of file ViewStack.cpp.
| void cdc::ui::ViewStack::render | ( | bool | synchronous = false | ) |
Render current view (and modal if present) and flush to display.
| synchronous | When true, flush via the blocking display path (flushSync) so the panel update has fully completed on return. When false (default), flush asynchronously via the render task. |
Definition at line 318 of file ViewStack.cpp.
References cdc::ui::IView::clearDirty(), cdc::ui::display, cdc::hal::FULL, cdc::hal::getDisplayInstance(), cdc::ui::IView::needsRender(), needsRender(), cdc::hal::PARTIAL, cdc::hal::PARTIAL_LIGHT, cdc::ui::IView::prefersLightRefresh(), and cdc::ui::IView::render().
Referenced by cdc::ui::WifiHandlers::connect(), host_ui_push_toast(), cdc::ui::showConfirm(), cdc::ui::showToastInternal(), cdc::plugin_manager::PluginManager::startPlugin(), and cdc::ui::ui_process().
| void cdc::ui::ViewStack::replace | ( | IView * | view, |
| void * | context = nullptr ) |
Replace top view with another
| view | New view |
| context | Optional context |
Definition at line 187 of file ViewStack.cpp.
References cdc::ui::IView::getName(), cdc::ui::isListView(), LOG_D, LOG_W, cdc::ui::IView::onEnter(), cdc::ui::IView::onExit(), and cdc::ui::TAG.
Referenced by cdc::ui::onPinSuccess().
| void cdc::ui::ViewStack::resetInactivityTimer | ( | ) |
Reset inactivity timer (called automatically on key press)
Definition at line 446 of file ViewStack.cpp.
Referenced by dispatchKey(), cdc::ui::onInactivityTimeout(), and cdc::ui::BlePairingView::onTick().
| void cdc::ui::ViewStack::setInactivityTimeout | ( | InactivityCallback | callback, |
| uint32_t | timeoutMs ) |
Set inactivity timeout callback
| callback | Function to call when timeout expires |
| timeoutMs | Timeout in milliseconds (0 to disable) |
Definition at line 438 of file ViewStack.cpp.
References LOG_D, and cdc::ui::TAG.
Referenced by cdc::plugin_manager::PluginUiState::setInactivity(), and cdc::ui::ui_init().
| void cdc::ui::ViewStack::showModal | ( | IView * | modal | ) |
Show a modal overlay (e.g., toast, context menu). Modals stack: the new one is pushed on top of any already-shown modal and receives input exclusively. If the same modal is already stacked it is lifted to the top.
| modal | Modal view |
Definition at line 386 of file ViewStack.cpp.
References cdc::ui::IView::getName(), LOG_D, LOG_W, cdc::ui::IView::onEnter(), cdc::ui::IView::onPause(), and cdc::ui::TAG.
Referenced by host_ui_push_toast(), cdc::ui::onBlePairingRequestEvent(), cdc::plugin_manager::PluginUiState::pushConfirm(), cdc::plugin_manager::PluginUiState::pushContextMenu(), cdc::ui::showConfirm(), cdc::ui::showContextMenu(), cdc::ui::showMessage(), cdc::ui::showToastInternal(), and cdc::plugin_manager::PluginManager::startPlugin().
|
staticconstexpr |
Definition at line 20 of file ViewStack.h.