mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
fix: replace for loop with std::any_of
This commit is contained in:
parent
cebfc54266
commit
45bba9a822
@ -30,40 +30,37 @@ void ButtonNavigator::onNextContinuous(const Callback& callback) { onContinuous(
|
|||||||
void ButtonNavigator::onPreviousContinuous(const Callback& callback) { onContinuous(getPreviousButtons(), callback); }
|
void ButtonNavigator::onPreviousContinuous(const Callback& callback) { onContinuous(getPreviousButtons(), callback); }
|
||||||
|
|
||||||
void ButtonNavigator::onPress(const Buttons& buttons, const Callback& callback) {
|
void ButtonNavigator::onPress(const Buttons& buttons, const Callback& callback) {
|
||||||
if (!mappedInput) return;
|
const bool wasPressed = std::any_of(buttons.begin(), buttons.end(), [](const MappedInputManager::Button button) {
|
||||||
|
return mappedInput != nullptr && mappedInput->wasPressed(button);
|
||||||
|
});
|
||||||
|
|
||||||
for (const MappedInputManager::Button button : buttons) {
|
if (wasPressed) {
|
||||||
if (mappedInput->wasPressed(button)) {
|
|
||||||
callback();
|
callback();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonNavigator::onRelease(const Buttons& buttons, const Callback& callback) {
|
void ButtonNavigator::onRelease(const Buttons& buttons, const Callback& callback) {
|
||||||
if (!mappedInput) return;
|
const bool wasReleased = std::any_of(buttons.begin(), buttons.end(), [](const MappedInputManager::Button button) {
|
||||||
|
return mappedInput != nullptr && mappedInput->wasReleased(button);
|
||||||
|
});
|
||||||
|
|
||||||
for (const MappedInputManager::Button button : buttons) {
|
if (wasReleased) {
|
||||||
if (mappedInput->wasReleased(button)) {
|
|
||||||
if (lastContinuousNavTime == 0) {
|
if (lastContinuousNavTime == 0) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
lastContinuousNavTime = 0;
|
lastContinuousNavTime = 0;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonNavigator::onContinuous(const Buttons& buttons, const Callback& callback) {
|
void ButtonNavigator::onContinuous(const Buttons& buttons, const Callback& callback) {
|
||||||
if (!mappedInput) return;
|
const bool isPressed = std::any_of(buttons.begin(), buttons.end(), [this](const MappedInputManager::Button button) {
|
||||||
|
return mappedInput != nullptr && mappedInput->isPressed(button) && shouldNavigateContinuously();
|
||||||
|
});
|
||||||
|
|
||||||
for (const MappedInputManager::Button button : buttons) {
|
if (isPressed) {
|
||||||
if (mappedInput->isPressed(button) && shouldNavigateContinuously()) {
|
|
||||||
callback();
|
callback();
|
||||||
lastContinuousNavTime = millis();
|
lastContinuousNavTime = millis();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user