Support selecting a menu and terminate execution if so

This commit is contained in:
Jaby
2024-01-03 16:31:43 -06:00
parent 7674d4b55f
commit 59c974ab17
3 changed files with 71 additions and 23 deletions

View File

@@ -2,10 +2,11 @@
#include <PSX/Periphery/periphery.hpp>
namespace Menu {
void SimpleMenu :: setup(const Entry* entries, size_t size) {
this->entries = entries;
this->size = size;
this->cur_selection = 0;
void SimpleMenu :: setup(Callback callback, const Entry* entries, size_t size) {
this->selection_callback = callback;
this->entries = entries;
this->size = size;
this->cur_selection = 0;
}
void SimpleMenu :: update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start) {
@@ -20,6 +21,10 @@ namespace Menu {
this->cur_selection += 1;
}
if(controller.button.went_down(DigitalButton::Cross)) {
this->selection_callback(this->cur_selection);
}
cursor.pos = Make::PositionI16(8, 64);
for(size_t n = 0; n < this->size; n++) {
const auto& cur_entry = this->entries[n];