Update gui_file_dialog.h

This commit is contained in:
Ray
2020-12-18 20:06:38 +01:00
parent 3b44da667b
commit f5bd6c08f8

View File

@ -248,7 +248,7 @@ void GuiFileDialog(GuiFileDialogState *state)
{ {
if (strcmp(state->fileNameText, state->dirFiles[f]) == 0) if (strcmp(state->fileNameText, state->dirFiles[f]) == 0)
{ {
if (state->filesListActive != f) state->filesListScrollIndex = state->filesListActive = f; // make it active and visible only on first call if (state->filesListActive != f) state->filesListScrollIndex = state->filesListActive = f; // Make it active and visible only on first call
break; break;
} }
@ -395,8 +395,8 @@ void GuiFileDialog(GuiFileDialogState *state)
} }
} }
// Read all filenames from directory (supported file types) // Compare two files from a directory
static inline int _file_comp(const char *d1, const char *d2, const char *dir) static inline int FileCompare(const char *d1, const char *d2, const char *dir)
{ {
const bool b1 = DirectoryExists(TextFormat("%s/%s", dir, d1)); const bool b1 = DirectoryExists(TextFormat("%s/%s", dir, d1));
const bool b2 = DirectoryExists(TextFormat("%s/%s", dir, d2)); const bool b2 = DirectoryExists(TextFormat("%s/%s", dir, d2));
@ -409,6 +409,8 @@ static inline int _file_comp(const char *d1, const char *d2, const char *dir)
return strcmp(d1, d2); return strcmp(d1, d2);
} }
// Read all filenames from directory (supported file types)
static char **ReadDirectoryFiles(const char *dir, int *filesCount, char *filterExt) static char **ReadDirectoryFiles(const char *dir, int *filesCount, char *filterExt)
{ {
int validFilesCount = 0; int validFilesCount = 0;
@ -431,27 +433,27 @@ static char **ReadDirectoryFiles(const char *dir, int *filesCount, char *filterE
for (;;) for (;;)
{ {
for (; left+1 < len; len++) /* sort left to len-1 */ for (; left + 1 < len; len++) // Sort left to len - 1
{ {
if (pos == MAX) len = stack[pos = 0]; /* stack overflow, reset */ if (pos == MAX) len = stack[pos = 0]; // Stack overflow, reset
char *pivot = files[left+seed%(len-left)]; /* pick random pivot */ char *pivot = files[left + seed%(len - left)]; // Pick random pivot
seed = seed*69069+1; /* next pseudorandom number */ seed = seed*69069 + 1; // Next pseudo-random number
stack[pos++] = len; /* sort right part later */ stack[pos++] = len; // Sort right part later
for (unsigned int right = left-1; ; ) /* inner loop: partitioning */ for (unsigned int right = left - 1;;) // Inner loop: partitioning
{ {
while (_file_comp(files[++right], pivot, dir) < 0);/* look for greater element */ while (FileCompare(files[++right], pivot, dir) < 0); // Look for greater element
while (_file_comp(pivot, files[--len], dir) < 0); /* look for smaller element */ while (FileCompare(pivot, files[--len], dir) < 0); // Look for smaller element
if (right >= len) break; /* partition point found? */ if (right >= len) break; // Partition point found?
char *temp = files[right]; char *temp = files[right];
files[right] = files[len]; /* the only swap */ files[right] = files[len]; // The only swap
files[len] = temp; files[len] = temp;
} /* partitioned, continue left part */ } // Partitioned, continue left part
} }
if (pos == 0) break; /* stack empty? */ if (pos == 0) break; // Stack empty?
left = len; /* left to right is sorted */ left = len; // Left to right is sorted
len = stack[--pos]; /* get next range to sort */ len = stack[--pos]; // Get next range to sort
} }
} }