GUI: File selector usability improvements
Jeffrey Pfau jeffrey@endrift.com
Wed, 26 Aug 2015 19:37:21 -0700
1 files changed,
32 insertions(+),
6 deletions(-)
jump to
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -12,6 +12,9 @@
DECLARE_VECTOR(FileList, char*); DEFINE_VECTOR(FileList, char*); +#define ITERATION_SIZE 5 +#define SCANNING_THRESHOLD 20 + static void _cleanFiles(struct FileList* currentFiles) { size_t size = FileListSize(currentFiles); size_t i;@@ -37,7 +40,7 @@ }
// TODO: What if there was a trailing slash? } -static bool _refreshDirectory(const char* currentPath, struct FileList* currentFiles, bool (*filter)(struct VFile*)) { +static bool _refreshDirectory(const struct GUIParams* params, const char* currentPath, struct FileList* currentFiles, bool (*filter)(struct VFile*)) { _cleanFiles(currentFiles); struct VDir* dir = VDirOpen(currentPath);@@ -45,8 +48,16 @@ if (!dir) {
return false; } *FileListAppend(currentFiles) = "(Up)"; + size_t i = 0; struct VDirEntry* de; while ((de = dir->listNext(dir))) { + ++i; + if (i == SCANNING_THRESHOLD) { + params->drawStart(); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning)"); + params->drawEnd(); + } const char* name = de->name(de); if (name[0] == '.') { continue;@@ -77,7 +88,7 @@ size_t start = 0;
struct FileList currentFiles; FileListInit(¤tFiles, 0); - _refreshDirectory(currentPath, ¤tFiles, filter); + _refreshDirectory(params, currentPath, ¤tFiles, filter); int inputHistory[GUI_INPUT_MAX] = { 0 };@@ -101,6 +112,21 @@ }
if (newInput & (1 << GUI_INPUT_DOWN) && fileIndex < FileListSize(¤tFiles) - 1) { ++fileIndex; } + if (newInput & (1 << GUI_INPUT_LEFT)) { + if (fileIndex >= ITERATION_SIZE) { + fileIndex -= ITERATION_SIZE; + } else { + fileIndex = 0; + } + } + if (newInput & (1 << GUI_INPUT_RIGHT)) { + if (fileIndex + ITERATION_SIZE < FileListSize(¤tFiles)) { + fileIndex += ITERATION_SIZE; + } else { + fileIndex = FileListSize(¤tFiles) - 1; + } + } + if (fileIndex < start) { start = fileIndex; }@@ -115,7 +141,7 @@ }
if (newInput & (1 << GUI_INPUT_SELECT)) { if (fileIndex == 0) { _upDirectory(currentPath); - _refreshDirectory(currentPath, ¤tFiles, filter); + _refreshDirectory(params, currentPath, ¤tFiles, filter); } else { size_t len = strlen(currentPath); const char* sep = PATH_SEP;@@ -123,7 +149,7 @@ if (currentPath[len - 1] == *sep) {
sep = ""; } snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex)); - if (!_refreshDirectory(outPath, ¤tFiles, filter)) { + if (!_refreshDirectory(params, outPath, ¤tFiles, filter)) { return true; } strncpy(currentPath, outPath, outLen);@@ -137,13 +163,13 @@ FileListDeinit(¤tFiles);
return false; } _upDirectory(currentPath); - _refreshDirectory(currentPath, ¤tFiles, filter); + _refreshDirectory(params, currentPath, ¤tFiles, filter); fileIndex = 0; } params->drawStart(); int y = GUIFontHeight(params->font); - GUIFontPrintf(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, "Current directory: %s", currentPath); + GUIFontPrintf(params->font, 0, y, GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath); y += 2 * GUIFontHeight(params->font); size_t i; for (i = start; i < FileListSize(¤tFiles); ++i) {