CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
MessageBox.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
11enum class MessageIcon : uint8_t {
12 NONE = 0, // No icon
13 SUCCESS, // Checkmark
14 ERROR, // X mark
15 INFO, // Info circle
16 WARNING // Warning triangle
17};
18
28class MessageBox : public ViewBase {
29public:
33 using CloseCallback = void(*)();
34
41 void init(const char* message, MessageIcon icon = MessageIcon::NONE,
42 uint32_t timeoutMs = 0);
43
47 void setOnClose(CloseCallback callback) { onClose_ = callback; }
48
49 // IView implementation
50 void render(bool partial) override;
51 InputResult onKey(char key) override;
52 void onTick(uint32_t nowMs) override;
53 const char* getName() const override { return "MessageBox"; }
54 const char* getFooterHint() const override { return nullptr; }
55
56private:
57 const char* message_ = nullptr;
59 uint32_t timeoutMs_ = 0;
60 uint32_t startTimeMs_ = 0;
61 CloseCallback onClose_ = nullptr;
62};
63
64// ============================================================================
65// Convenience Functions
66// ============================================================================
67
82void showMessage(const char* message, MessageIcon icon = MessageIcon::NONE,
83 uint32_t timeoutMs = 0, MessageBox::CloseCallback onClose = nullptr);
84
88inline void showSuccess(const char* message, uint32_t timeoutMs = 2000) {
89 showMessage(message, MessageIcon::SUCCESS, timeoutMs);
90}
91
95inline void showError(const char* message, uint32_t timeoutMs = 2000) {
96 showMessage(message, MessageIcon::ERROR, timeoutMs);
97}
98
102void hideMessage();
103
104} // namespace cdc::ui
void onTick(uint32_t nowMs) override
Updates timeout-based auto-dismiss behavior.
const char * getName() const override
Definition MessageBox.h:53
InputResult onKey(char key) override
Handles key input for manual dismissal.
void setOnClose(CloseCallback callback)
Definition MessageBox.h:47
void(*)() CloseCallback
Definition MessageBox.h:33
const char * getFooterHint() const override
Definition MessageBox.h:54
void init(const char *message, MessageIcon icon=MessageIcon::NONE, uint32_t timeoutMs=0)
Initializes message box state.
Centralized key-code constants for cdc_views.
Definition IModule.h:8
void hideMessage()
Hides the currently shown modal message box.
void showError(const char *message, uint32_t timeoutMs=2000)
Definition MessageBox.h:95
InputResult
Definition IView.h:10
void showSuccess(const char *message, uint32_t timeoutMs=2000)
Definition MessageBox.h:88
void showMessage(const char *message, MessageIcon icon=MessageIcon::NONE, uint32_t timeoutMs=0, MessageBox::CloseCallback onClose=nullptr)
Shows the shared modal message box.