From 9b545255d4496903455c5dd49042c87e1a1f7af4 Mon Sep 17 00:00:00 2001 From: physick Date: Mon, 31 Aug 2026 21:17:22 +0500 Subject: scroll in the puzzle selection scene --- src/puzzles/collection.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/puzzles') diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c index ca2743c..a88bae4 100644 --- a/src/puzzles/collection.c +++ b/src/puzzles/collection.c @@ -13,6 +13,14 @@ static const char *IMAGE_NAME = "icon.png"; static const float NAME_IN_CARD_RATIO = 0.2f; +int compare_elements(const void *a, const void *b) { + const CollectionElement *elA = (const CollectionElement *)a; + const CollectionElement *elB = (const CollectionElement *)b; + + // Sort alphabetically by name + return strcmp(elA->path, elB->path); +} + CollectionElementType getTypeFromPath(char *fullPath) { struct stat st; if (stat(fullPath, &st) != 0) return COLLECTION_ELEMENT_UNKNOWN; @@ -65,16 +73,20 @@ char *getName(char *name) { char buf[1024]; strncpy(buf, name, sizeof(buf)); size_t len = strlen(name); + size_t span_start = 0; + size_t span_end = 0; // Cutting a file extention for (size_t i = 0; i < len; ++i) { if (buf[i] == '.') { - buf[i] = 0x0; - break; + if (span_end != 0) span_start = span_end + 1; + span_end = i; } } + if (span_end != 0) + buf[span_end] = 0x0; - return strdup(buf); + return strdup(buf + span_start); } size_t getElementCount(DIR *dir, CollectionElement *el) { @@ -136,6 +148,9 @@ void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionEle idx += 1; } + if (idx > 1) { + qsort(el->children, idx, sizeof(CollectionElement), compare_elements); + } closedir(dir); } -- cgit v1.3