Introduce separators in drawList
This commit is contained in:
@@ -73,6 +73,26 @@ bool ButtonNavigator::shouldNavigateContinuously() const {
|
||||
return buttonHeldLongEnough && navigationIntervalElapsed;
|
||||
}
|
||||
|
||||
void ButtonNavigator::setSelectablePredicate(std::function<bool(int)> selectablePredicate, int totalItems) {
|
||||
this->selectablePredicate = std::move(selectablePredicate);
|
||||
this->selectableTotalItems = totalItems;
|
||||
}
|
||||
|
||||
void ButtonNavigator::clearSelectablePredicate() {
|
||||
selectablePredicate = nullptr;
|
||||
selectableTotalItems = 0;
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextIndex(int currentIndex) const {
|
||||
if (!selectablePredicate || selectableTotalItems <= 0) return currentIndex;
|
||||
return nextIndex(currentIndex, selectableTotalItems, selectablePredicate);
|
||||
}
|
||||
|
||||
int ButtonNavigator::previousIndex(int currentIndex) const {
|
||||
if (!selectablePredicate || selectableTotalItems <= 0) return currentIndex;
|
||||
return previousIndex(currentIndex, selectableTotalItems, selectablePredicate);
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextIndex(const int currentIndex, const int totalItems) {
|
||||
if (totalItems <= 0) return 0;
|
||||
|
||||
@@ -87,6 +107,68 @@ int ButtonNavigator::previousIndex(const int currentIndex, const int totalItems)
|
||||
return (currentIndex + totalItems - 1) % totalItems;
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextIndex(const int currentIndex, const std::vector<bool>& selectable) {
|
||||
const int totalItems = static_cast<int>(selectable.size());
|
||||
if (totalItems <= 0) return 0;
|
||||
|
||||
int index = nextIndex(currentIndex, totalItems);
|
||||
for (int i = 0; i < totalItems; ++i) {
|
||||
if (selectable[index]) {
|
||||
return index;
|
||||
}
|
||||
index = nextIndex(index, totalItems);
|
||||
}
|
||||
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
int ButtonNavigator::previousIndex(const int currentIndex, const std::vector<bool>& selectable) {
|
||||
const int totalItems = static_cast<int>(selectable.size());
|
||||
if (totalItems <= 0) return 0;
|
||||
|
||||
int index = previousIndex(currentIndex, totalItems);
|
||||
for (int i = 0; i < totalItems; ++i) {
|
||||
if (selectable[index]) {
|
||||
return index;
|
||||
}
|
||||
index = previousIndex(index, totalItems);
|
||||
}
|
||||
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextIndex(const int currentIndex, const int totalItems,
|
||||
const std::function<bool(int index)>& isSelectable) {
|
||||
if (totalItems <= 0) return 0;
|
||||
if (!isSelectable) return nextIndex(currentIndex, totalItems);
|
||||
|
||||
int index = nextIndex(currentIndex, totalItems);
|
||||
for (int i = 0; i < totalItems; ++i) {
|
||||
if (isSelectable(index)) {
|
||||
return index;
|
||||
}
|
||||
index = nextIndex(index, totalItems);
|
||||
}
|
||||
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
int ButtonNavigator::previousIndex(const int currentIndex, const int totalItems,
|
||||
const std::function<bool(int index)>& isSelectable) {
|
||||
if (totalItems <= 0) return 0;
|
||||
if (!isSelectable) return previousIndex(currentIndex, totalItems);
|
||||
|
||||
int index = previousIndex(currentIndex, totalItems);
|
||||
for (int i = 0; i < totalItems; ++i) {
|
||||
if (isSelectable(index)) {
|
||||
return index;
|
||||
}
|
||||
index = previousIndex(index, totalItems);
|
||||
}
|
||||
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
int ButtonNavigator::nextPageIndex(const int currentIndex, const int totalItems, const int itemsPerPage) {
|
||||
if (totalItems <= 0 || itemsPerPage <= 0) return 0;
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ class ButtonNavigator final {
|
||||
const uint16_t continuousIntervalMs;
|
||||
uint32_t lastContinuousNavTime = 0;
|
||||
static const MappedInputManager* mappedInput;
|
||||
std::function<bool(int)> selectablePredicate;
|
||||
int selectableTotalItems = 0;
|
||||
|
||||
[[nodiscard]] bool shouldNavigateContinuously() const;
|
||||
|
||||
@@ -40,6 +42,17 @@ class ButtonNavigator final {
|
||||
|
||||
[[nodiscard]] static int nextIndex(int currentIndex, int totalItems);
|
||||
[[nodiscard]] static int previousIndex(int currentIndex, int totalItems);
|
||||
[[nodiscard]] static int nextIndex(int currentIndex, const std::vector<bool>& selectable);
|
||||
[[nodiscard]] static int previousIndex(int currentIndex, const std::vector<bool>& selectable);
|
||||
[[nodiscard]] static int nextIndex(int currentIndex, int totalItems,
|
||||
const std::function<bool(int index)>& isSelectable);
|
||||
[[nodiscard]] static int previousIndex(int currentIndex, int totalItems,
|
||||
const std::function<bool(int index)>& isSelectable);
|
||||
|
||||
[[nodiscard]] int nextIndex(int currentIndex) const;
|
||||
[[nodiscard]] int previousIndex(int currentIndex) const;
|
||||
void setSelectablePredicate(std::function<bool(int)> selectablePredicate, int totalItems);
|
||||
void clearSelectablePredicate();
|
||||
|
||||
[[nodiscard]] static int nextPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
||||
[[nodiscard]] static int previousPageIndex(int currentIndex, int totalItems, int itemsPerPage);
|
||||
|
||||
Reference in New Issue
Block a user