From 5cbca6a081fd5e48188eabceb360741ee40fd8c6 Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Sun, 25 Aug 2024 14:21:46 -0400 Subject: [PATCH] Launcher: Make sure folders are always at the top of the list Previously I was just hoping no file would start with '[' or lower, so that folders would naturally end on top. But now the lists support grouping, so that folders (or pinned items in the future) are always at the top. --- CHANGELOG.md | 1 + launcher/main/applications.c | 13 +++++++------ launcher/main/gui.c | 23 ++++++++++------------- launcher/main/gui.h | 4 ++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cecfe75..4191cd02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Launcher: Added menu option to pre-compute all CRC32s (for cover art) - Launcher: Officially support name-based cover art (eg: `/covers/nes/game name.png`) - Launcher: Improved responsiveness when cover art/save preview is enabled +- Launcher: Added network status/details in wifi dialog # Retro-Go 1.42 (2024-06-05) diff --git a/launcher/main/applications.c b/launcher/main/applications.c index dff673b9..5fab7bcd 100644 --- a/launcher/main/applications.c +++ b/launcher/main/applications.c @@ -341,21 +341,22 @@ static void tab_refresh(tab_t *tab, const char *selected) if (file->folder != folder && strcmp(file->folder, folder) != 0) continue; - listbox_item_t *item = &tab->listbox.items[items_count++]; - if (file->type == RETRO_TYPE_FOLDER) { + listbox_item_t *item = &tab->listbox.items[items_count++]; snprintf(item->text, sizeof(item->text), "[%.40s]", file->name); - // snprintf(item->text, sizeof(item->text), "/[%.40s]/", file->name); + item->group = 1; + item->arg = file; } - else + else if (file->type == RETRO_TYPE_FILE) { + listbox_item_t *item = &tab->listbox.items[items_count++]; snprintf(item->text, sizeof(item->text), "%s", file->name); if ((ext = strrchr(item->text, '.'))) *ext = 0; + item->group = 2; + item->arg = file; } - - item->arg = file; } } diff --git a/launcher/main/gui.c b/launcher/main/gui.c index 350d3510..d24bfeb8 100644 --- a/launcher/main/gui.c +++ b/launcher/main/gui.c @@ -236,35 +236,32 @@ listbox_item_t *gui_get_selected_item(tab_t *tab) return NULL; } -static int list_comp_text_asc(const void *a, const void *b) +static int list_comp_text_asc(const listbox_item_t *a, const listbox_item_t *b) { - return strcasecmp(((listbox_item_t*)a)->text, ((listbox_item_t*)b)->text); + return a->group == b->group ? strcasecmp(a->text, b->text) : ((int)a->group - b->group); } -static int list_comp_text_desc(const void *a, const void *b) +static int list_comp_text_desc(const listbox_item_t *a, const listbox_item_t *b) { - return strcasecmp(((listbox_item_t*)b)->text, ((listbox_item_t*)a)->text); + return a->group == b->group ? strcasecmp(b->text, a->text) : ((int)a->group - b->group); } -static int list_comp_id_asc(const void *a, const void *b) +static int list_comp_id_asc(const listbox_item_t *a, const listbox_item_t *b) { - return ((listbox_item_t*)a)->order - ((listbox_item_t*)b)->order; + return a->group == b->group ? ((int)a->order - b->order) : ((int)a->group - b->group); } -static int list_comp_id_desc(const void *a, const void *b) +static int list_comp_id_desc(const listbox_item_t *a, const listbox_item_t *b) { - return ((listbox_item_t*)b)->order - ((listbox_item_t*)a)->order; + return a->group == b->group ? ((int)b->order - a->order) : ((int)a->group - b->group); } void gui_sort_list(tab_t *tab) { void *comp[] = {&list_comp_id_asc, &list_comp_id_desc, &list_comp_text_asc, &list_comp_text_desc}; - int sort_mode = tab->listbox.sort_mode - 1; + size_t sort_mode = tab->listbox.sort_mode - 1; - if (!tab->listbox.length) - return; - - if (sort_mode < 0 || sort_mode > 3) + if (!tab->listbox.length || sort_mode > RG_COUNT(comp) - 1) return; qsort((void*)tab->listbox.items, tab->listbox.length, sizeof(listbox_item_t), comp[sort_mode]); diff --git a/launcher/main/gui.h b/launcher/main/gui.h index 4bc3953f..ed3c1e7a 100644 --- a/launcher/main/gui.h +++ b/launcher/main/gui.h @@ -66,8 +66,8 @@ typedef struct { typedef struct { char text[92]; int16_t order; - uint8_t enabled; - uint8_t unused; + uint8_t group; + uint8_t unused; // icon, enabled void *arg; } listbox_item_t;