CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ContextMenuView.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_ui/IView.h"
4#include <cstdint>
5
6namespace cdc::ui {
7
12 const char* label;
13 void (*callback)();
14};
15
28class ContextMenuView : public ViewBase {
29public:
30 static constexpr uint8_t MAX_ITEMS = 8;
31 static constexpr uint8_t VISIBLE_ITEMS = 4;
32
39 void init(const char* title, const ContextMenuItem* items, uint8_t count);
40
44 uint8_t getSelection() const { return selection_; }
45
46 // IView implementation
47 void render(bool partial) override;
48 InputResult onKey(char key) override;
49 void onTick(uint32_t nowMs) override;
50 const char* getName() const override { return "ContextMenuView"; }
51 const char* getFooterHint() const override { return nullptr; }
52
53private:
54 const char* title_ = nullptr;
55 // Items are copied so callers can safely use stack arrays; the i18n
56 // strings the labels point to are stable for the program lifetime.
57 ContextMenuItem items_[MAX_ITEMS] = {};
58 uint8_t itemCount_ = 0;
59 uint8_t selection_ = 0;
60 uint8_t scrollPos_ = 0;
61 // Uptime (ms) of the last interaction; 0 until the first tick after show.
62 // Used for the auto-dismiss inactivity timeout.
63 uint32_t lastActivityMs_ = 0;
64
65 void navigate(bool down);
66 void select();
67};
68
69// ============================================================================
70// Convenience Functions
71// ============================================================================
72
90ContextMenuView* showContextMenu(const char* title, const ContextMenuItem* items, uint8_t count);
91
95void hideContextMenu();
96
97} // namespace cdc::ui
uint8_t getSelection() const
static constexpr uint8_t MAX_ITEMS
const char * getFooterHint() const override
static constexpr uint8_t VISIBLE_ITEMS
void onTick(uint32_t nowMs) override
Auto-dismisses the menu after a period of inactivity.
const char * getName() const override
InputResult onKey(char key) override
Handles key input for context menu navigation and actions.
void init(const char *title, const ContextMenuItem *items, uint8_t count)
Initializes context menu content and selection state.
const char * title_
Definition IView.h:202
Centralized key-code constants for cdc_views.
Definition IModule.h:8
InputResult
Definition IView.h:10
void hideContextMenu()
Hides the active context menu modal.
ContextMenuView * showContextMenu(const char *title, const ContextMenuItem *items, uint8_t count)
Shows the shared context menu instance as modal.