comparison nuklear_ui/blastem_nuklear.c @ 1485:369da70ee2c2 nuklear_ui

Filter file list in Nuklear UI
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Nov 2017 18:33:36 -0800
parents d82af64c94d2
children a6881d0d76d0
comparison
equal deleted inserted replaced
1484:d82af64c94d2 1485:369da70ee2c2
8 #include "../render_sdl.h" 8 #include "../render_sdl.h"
9 #include "../util.h" 9 #include "../util.h"
10 #include "../paths.h" 10 #include "../paths.h"
11 #include "../saves.h" 11 #include "../saves.h"
12 #include "../blastem.h" 12 #include "../blastem.h"
13 #include "../config.h"
13 14
14 static struct nk_context *context; 15 static struct nk_context *context;
15 16
16 typedef void (*view_fun)(struct nk_context *); 17 typedef void (*view_fun)(struct nk_context *);
17 static view_fun current_view; 18 static view_fun current_view;
26 { 27 {
27 static char *current_path; 28 static char *current_path;
28 static dir_entry *entries; 29 static dir_entry *entries;
29 static size_t num_entries; 30 static size_t num_entries;
30 static uint32_t selected_entry; 31 static uint32_t selected_entry;
32 static char **ext_list;
33 static uint32_t num_exts;
34 static uint8_t got_ext_list;
31 if (!current_path) { 35 if (!current_path) {
32 get_initial_browse_path(&current_path); 36 get_initial_browse_path(&current_path);
33 } 37 }
34 if (!entries) { 38 if (!entries) {
35 entries = get_dir_list(current_path, &num_entries); 39 entries = get_dir_list(current_path, &num_entries);
36 if (entries) { 40 if (entries) {
37 sort_dir_list(entries, num_entries); 41 sort_dir_list(entries, num_entries);
38 } 42 }
43 }
44 if (!got_ext_list) {
45 ext_list = get_extension_list(config, &num_exts);
46 got_ext_list = 1;
39 } 47 }
40 uint32_t width = render_width(); 48 uint32_t width = render_width();
41 uint32_t height = render_height(); 49 uint32_t height = render_height();
42 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { 50 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) {
43 nk_layout_row_static(context, height - 100, width - 60, 1); 51 nk_layout_row_static(context, height - 100, width - 60, 1);
44 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { 52 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
45 nk_layout_row_static(context, 28, width-100, 1); 53 nk_layout_row_static(context, 28, width-100, 1);
46 for (uint32_t i = 0; i < num_entries; i++) 54 for (uint32_t i = 0; i < num_entries; i++)
47 { 55 {
56 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') {
57 continue;
58 }
59 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) {
60 continue;
61 }
48 int selected = i == selected_entry; 62 int selected = i == selected_entry;
49 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected); 63 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected);
50 if (selected) { 64 if (selected) {
51 selected_entry = i; 65 selected_entry = i;
52 } 66 }