A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Scrolling page items calculation (#716)

## Summary

Fix for the page skip issue detected
https://github.com/crosspoint-reader/crosspoint-reader/pull/700#issuecomment-3856374323
by user @whyte-j

Skipping down on the last page now skips to the last item, and up on the
first page to the first item, rather than wrapping around the list in a
weird way.

## Additional Context

The calculation was outdated after several changes were added afterwards

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_

authored by

CaptainFrito and committed by
GitHub
5b90b68e 67ddd60f

+14 -10
+6 -4
src/activities/home/MyLibraryActivity.cpp
··· 3 3 #include <GfxRenderer.h> 4 4 #include <SDCardManager.h> 5 5 6 + #include <algorithm> 7 + 6 8 #include "MappedInputManager.h" 7 9 #include "components/UITheme.h" 8 10 #include "fontIds.h" ··· 114 116 mappedInput.wasReleased(MappedInputManager::Button::Down); 115 117 116 118 const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS; 117 - const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true); 119 + const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false); 118 120 119 121 if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { 120 122 if (files.empty()) { ··· 157 159 int listSize = static_cast<int>(files.size()); 158 160 if (upReleased) { 159 161 if (skipPage) { 160 - selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + listSize) % listSize; 162 + selectorIndex = std::max(static_cast<int>((selectorIndex / pageItems - 1) * pageItems), 0); 161 163 } else { 162 164 selectorIndex = (selectorIndex + listSize - 1) % listSize; 163 165 } 164 166 updateRequired = true; 165 167 } else if (downReleased) { 166 168 if (skipPage) { 167 - selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % listSize; 169 + selectorIndex = std::min(static_cast<int>((selectorIndex / pageItems + 1) * pageItems), listSize - 1); 168 170 } else { 169 171 selectorIndex = (selectorIndex + 1) % listSize; 170 172 } ··· 195 197 GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, folderName); 196 198 197 199 const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; 198 - const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; 200 + const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing; 199 201 if (files.empty()) { 200 202 renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding, contentTop + 20, "No books found"); 201 203 } else {
+5 -3
src/activities/home/RecentBooksActivity.cpp
··· 3 3 #include <GfxRenderer.h> 4 4 #include <SDCardManager.h> 5 5 6 + #include <algorithm> 7 + 6 8 #include "MappedInputManager.h" 7 9 #include "RecentBooksStore.h" 8 10 #include "components/UITheme.h" ··· 92 94 int listSize = static_cast<int>(recentBooks.size()); 93 95 if (upReleased) { 94 96 if (skipPage) { 95 - selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + listSize) % listSize; 97 + selectorIndex = std::max(static_cast<int>((selectorIndex / pageItems - 1) * pageItems), 0); 96 98 } else { 97 99 selectorIndex = (selectorIndex + listSize - 1) % listSize; 98 100 } 99 101 updateRequired = true; 100 102 } else if (downReleased) { 101 103 if (skipPage) { 102 - selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % listSize; 104 + selectorIndex = std::min(static_cast<int>((selectorIndex / pageItems + 1) * pageItems), listSize - 1); 103 105 } else { 104 106 selectorIndex = (selectorIndex + 1) % listSize; 105 107 } ··· 129 131 GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, "Recent Books"); 130 132 131 133 const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing; 132 - const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2; 134 + const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing; 133 135 134 136 // Recent tab 135 137 if (recentBooks.empty()) {
+2 -2
src/components/UITheme.cpp
··· 40 40 const ThemeMetrics& metrics = UITheme::getInstance().getMetrics(); 41 41 int reservedHeight = metrics.topPadding; 42 42 if (hasHeader) { 43 - reservedHeight += metrics.headerHeight; 43 + reservedHeight += metrics.headerHeight + metrics.verticalSpacing; 44 44 } 45 45 if (hasTabBar) { 46 - reservedHeight += metrics.tabBarHeight + metrics.verticalSpacing; 46 + reservedHeight += metrics.tabBarHeight; 47 47 } 48 48 if (hasButtonHints) { 49 49 reservedHeight += metrics.verticalSpacing + metrics.buttonHintsHeight;
+1 -1
src/components/themes/BaseTheme.cpp
··· 174 174 175 175 const int centerX = rect.x + rect.width - indicatorWidth / 2 - margin; 176 176 const int indicatorTop = rect.y; // Offset to avoid overlapping side button hints 177 - const int indicatorBottom = rect.y + rect.height - 30; 177 + const int indicatorBottom = rect.y + rect.height - arrowSize; 178 178 179 179 // Draw up arrow at top (^) - narrow point at top, wide base at bottom 180 180 for (int i = 0; i < arrowSize; ++i) {