GUI: Add scrolling

This commit is contained in:
Jeffrey Pfau 2015-08-06 15:43:45 -07:00
parent 94e329a58c
commit 74c4cbe33e
1 changed files with 8 additions and 1 deletions

View File

@ -56,6 +56,7 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
strncpy(currentPath, basePath, sizeof(currentPath)); strncpy(currentPath, basePath, sizeof(currentPath));
int oldInput = -1; int oldInput = -1;
size_t fileIndex = 0; size_t fileIndex = 0;
size_t start = 0;
struct FileList currentFiles; struct FileList currentFiles;
FileListInit(&currentFiles, 0); FileListInit(&currentFiles, 0);
@ -72,6 +73,12 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
if (newInput & (1 << GUI_INPUT_DOWN) && fileIndex < FileListSize(&currentFiles) - 1) { if (newInput & (1 << GUI_INPUT_DOWN) && fileIndex < FileListSize(&currentFiles) - 1) {
++fileIndex; ++fileIndex;
} }
if (fileIndex < start) {
start = fileIndex;
}
while ((fileIndex - start + 4) * GUIFontHeight(params->font) > params->height) {
++start;
}
if (newInput & (1 << GUI_INPUT_CANCEL)) { if (newInput & (1 << GUI_INPUT_CANCEL)) {
_cleanFiles(&currentFiles); _cleanFiles(&currentFiles);
FileListDeinit(&currentFiles); FileListDeinit(&currentFiles);
@ -101,7 +108,7 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
GUIFontPrintf(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, "Current directory: %s", currentPath); GUIFontPrintf(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, "Current directory: %s", currentPath);
y += 2 * GUIFontHeight(params->font); y += 2 * GUIFontHeight(params->font);
size_t i; size_t i;
for (i = 0; i < FileListSize(&currentFiles); ++i) { for (i = start; i < FileListSize(&currentFiles); ++i) {
int color = 0xE0A0A0A0; int color = 0xE0A0A0A0;
char bullet = ' '; char bullet = ' ';
if (i == fileIndex) { if (i == fileIndex) {