Config: Implement "onSelected" callback

This commit is contained in:
Maschell 2022-09-23 21:39:34 +02:00
parent 4a2f60592e
commit 030c9b4265

View File

@ -160,6 +160,7 @@ void ConfigUtils::displayMenu() {
KPADStatus kpad_data{}; KPADStatus kpad_data{};
KPADError kpad_error; KPADError kpad_error;
int32_t prevSelectedItem = -1;
bool isItemMovementAllowed = true; bool isItemMovementAllowed = true;
while (true) { while (true) {
@ -316,6 +317,7 @@ void ConfigUtils::displayMenu() {
selectedBtn = 0; selectedBtn = 0;
start = 0; start = 0;
end = MAX_BUTTONS_ON_SCREEN; end = MAX_BUTTONS_ON_SCREEN;
prevSelectedItem = -1;
auto items = currentCategory->getItems(); auto items = currentCategory->getItems();
if (items.size() < MAX_BUTTONS_ON_SCREEN) { if (items.size() < MAX_BUTTONS_ON_SCREEN) {
@ -493,6 +495,14 @@ void ConfigUtils::displayMenu() {
} }
if (redraw) { if (redraw) {
if (prevSelectedItem != (int32_t) selectedBtn) {
if (prevSelectedItem >= 0) {
config_items[prevSelectedItem]->onSelected(false);
}
config_items[selectedBtn]->onSelected(true);
prevSelectedItem = (int32_t) selectedBtn;
}
DrawUtils::beginDraw(); DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BACKGROUND); DrawUtils::clear(COLOR_BACKGROUND);