comparison nuklear_ui/blastem_nuklear.c @ 1554:87350caf6dab

Allow double click to open ROM in file browser
author Michael Pavone <pavone@retrodev.com>
date Thu, 29 Mar 2018 00:40:41 -0700
parents 723c00950f41
children d14490dee01f
comparison
equal deleted inserted replaced
1553:723c00950f41 1554:87350caf6dab
51 void view_file_browser(struct nk_context *context, uint8_t normal_open) 51 void view_file_browser(struct nk_context *context, uint8_t normal_open)
52 { 52 {
53 static char *current_path; 53 static char *current_path;
54 static dir_entry *entries; 54 static dir_entry *entries;
55 static size_t num_entries; 55 static size_t num_entries;
56 static uint32_t selected_entry; 56 static int32_t selected_entry = -1;
57 static char **ext_list; 57 static char **ext_list;
58 static uint32_t num_exts; 58 static uint32_t num_exts;
59 static uint8_t got_ext_list; 59 static uint8_t got_ext_list;
60 if (!current_path) { 60 if (!current_path) {
61 get_initial_browse_path(&current_path); 61 get_initial_browse_path(&current_path);
72 } 72 }
73 uint32_t width = render_width(); 73 uint32_t width = render_width();
74 uint32_t height = render_height(); 74 uint32_t height = render_height();
75 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) { 75 if (nk_begin(context, "Load ROM", nk_rect(0, 0, width, height), 0)) {
76 nk_layout_row_static(context, height - 100, width - 60, 1); 76 nk_layout_row_static(context, height - 100, width - 60, 1);
77 int32_t old_selected = selected_entry;
77 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) { 78 if (nk_group_begin(context, "Select ROM", NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
78 nk_layout_row_static(context, 28, width-100, 1); 79 nk_layout_row_static(context, 28, width-100, 1);
79 for (uint32_t i = 0; i < num_entries; i++) 80 for (int32_t i = 0; i < num_entries; i++)
80 { 81 {
81 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') { 82 if (entries[i].name[0] == '.' && entries[i].name[1] != '.') {
82 continue; 83 continue;
83 } 84 }
84 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) { 85 if (num_exts && !entries[i].is_dir && !path_matches_extensions(entries[i].name, ext_list, num_exts)) {
86 } 87 }
87 int selected = i == selected_entry; 88 int selected = i == selected_entry;
88 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected); 89 nk_selectable_label(context, entries[i].name, NK_TEXT_ALIGN_LEFT, &selected);
89 if (selected) { 90 if (selected) {
90 selected_entry = i; 91 selected_entry = i;
92 } else if (i == selected_entry) {
93 selected_entry = -1;
91 } 94 }
92 } 95 }
93 nk_group_end(context); 96 nk_group_end(context);
94 } 97 }
95 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2); 98 nk_layout_row_static(context, 52, width > 600 ? 300 : width / 2, 2);
96 if (nk_button_label(context, "Back")) { 99 if (nk_button_label(context, "Back")) {
97 pop_view(); 100 pop_view();
98 } 101 }
99 if (nk_button_label(context, "Open")) { 102 if (nk_button_label(context, "Open") || (old_selected >= 0 && selected_entry < 0)) {
103 if (selected_entry < 0) {
104 selected_entry = old_selected;
105 }
100 char *full_path = path_append(current_path, entries[selected_entry].name); 106 char *full_path = path_append(current_path, entries[selected_entry].name);
101 if (entries[selected_entry].is_dir) { 107 if (entries[selected_entry].is_dir) {
102 free(current_path); 108 free(current_path);
103 current_path = full_path; 109 current_path = full_path;
104 free_dir_list(entries, num_entries); 110 free_dir_list(entries, num_entries);
117 free(full_path); 123 free(full_path);
118 } 124 }
119 clear_view_stack(); 125 clear_view_stack();
120 current_view = view_play; 126 current_view = view_play;
121 } 127 }
128 selected_entry = -1;
122 } 129 }
123 nk_end(context); 130 nk_end(context);
124 } 131 }
125 } 132 }
126 133