为Menu增加了回调

This commit is contained in:
梦凌汐 2024-12-19 20:52:41 +08:00
parent ac4e01daf6
commit e1fa660a7f

View File

@ -27,6 +27,7 @@ private:
MyVector<Option> options_; MyVector<Option> options_;
int currentIndex_ = 0; int currentIndex_ = 0;
Rect border_ = {0, 0, 0, 0}; Rect border_ = {0, 0, 0, 0};
void onOptionSelected(const std::string& id);
public: public:
Menu(int left, int top, RichText title, MyVector<MenuOption> options) : BaseComponent(left, top, 0, 0) { // set left/top to -1 to center the menu Menu(int left, int top, RichText title, MyVector<MenuOption> options) : BaseComponent(left, top, 0, 0) { // set left/top to -1 to center the menu
@ -95,6 +96,8 @@ public:
} else if(key == 80 + 256) { } else if(key == 80 + 256) {
if(currentIndex_ == options_.size() - 1) return; if(currentIndex_ == options_.size() - 1) return;
currentIndex_++; currentIndex_++;
} else if(key == 13) { // enter
onOptionSelected(options_[currentIndex_].option.id);
} }
for (int i = 0; i < options_.size(); i++) { for (int i = 0; i < options_.size(); i++) {