-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathItemCommand.h
41 lines (36 loc) · 1.25 KB
/
ItemCommand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include "BaseItemZeroWidget.h"
/**
* @brief A menu item that executes a callback function when selected.
*
* This class extends the BaseItemZeroWidget class and provides a menu item
* that executes a callback function when selected. The callback function is
* provided as a function pointer during construction.
*
* As a BaseItemZeroWidget, this item responds to selection events in the menu
* system. When the user confirms the selection, handleCommit is triggered,
* which executes the provided callback.
*/
class ItemCommand : public BaseItemZeroWidget {
private:
void (*callback)();
public:
ItemCommand(const char* text, void (*callback)()) : BaseItemZeroWidget(text), callback(callback) {}
protected:
void handleCommit(LcdMenu* menu) override {
if (callback) callback();
}
};
/**
* @brief Create a new command item.
*
* @param text The text to display for the item.
* @param callback The function to call when the item is selected.
* @return MenuItem* The created item. Caller takes ownership of the returned pointer.
*
* @example
* auto item = ITEM_COMMAND("Save", []() { save_data(); });
*/
inline MenuItem* ITEM_COMMAND(const char* text, void (*callback)()) {
return new ItemCommand(text, callback);
}