GUI: Use the real page size for page scrolling

This commit is contained in:
Jeffrey Pfau 2015-08-26 21:45:55 -07:00
parent 87a05e3ed1
commit d5697971a9
1 changed files with 10 additions and 4 deletions

View File

@ -85,6 +85,12 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
} }
size_t fileIndex = 0; size_t fileIndex = 0;
size_t start = 0; size_t start = 0;
size_t pageSize = params->height / GUIFontHeight(params->font);
if (pageSize > 4) {
pageSize -= 4;
} else {
pageSize = 1;
}
struct FileList currentFiles; struct FileList currentFiles;
FileListInit(&currentFiles, 0); FileListInit(&currentFiles, 0);
@ -113,15 +119,15 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
++fileIndex; ++fileIndex;
} }
if (newInput & (1 << GUI_INPUT_LEFT)) { if (newInput & (1 << GUI_INPUT_LEFT)) {
if (fileIndex >= ITERATION_SIZE) { if (fileIndex >= pageSize) {
fileIndex -= ITERATION_SIZE; fileIndex -= pageSize;
} else { } else {
fileIndex = 0; fileIndex = 0;
} }
} }
if (newInput & (1 << GUI_INPUT_RIGHT)) { if (newInput & (1 << GUI_INPUT_RIGHT)) {
if (fileIndex + ITERATION_SIZE < FileListSize(&currentFiles)) { if (fileIndex + pageSize < FileListSize(&currentFiles)) {
fileIndex += ITERATION_SIZE; fileIndex += pageSize;
} else { } else {
fileIndex = FileListSize(&currentFiles) - 1; fileIndex = FileListSize(&currentFiles) - 1;
} }