[nk] file picker part 2
This commit is contained in:
parent
b08aa06779
commit
a79882bfc8
|
@ -25,15 +25,17 @@
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
#include <lists/string_list.h>
|
#include <lists/string_list.h>
|
||||||
|
#include <lists/dir_list.h>
|
||||||
|
|
||||||
#include "../../menu_driver.h"
|
#include "../../menu_driver.h"
|
||||||
#include "../../menu_hash.h"
|
#include "../../menu_hash.h"
|
||||||
#include "../../frontend/frontend_driver.h"
|
#include "../../frontend/frontend_driver.h"
|
||||||
|
|
||||||
static bool assets_loaded;
|
static bool assets_loaded;
|
||||||
|
static char path[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
static file_list_t *drives;
|
static file_list_t *drives = NULL;
|
||||||
static file_list_t *files;
|
struct string_list *files = NULL;
|
||||||
|
|
||||||
struct icon_list {
|
struct icon_list {
|
||||||
struct nk_image disk;
|
struct nk_image disk;
|
||||||
|
@ -48,27 +50,32 @@ void load_icons(nk_menu_handle_t *nk)
|
||||||
fill_pathname_join(buf, nk->assets_directory,
|
fill_pathname_join(buf, nk->assets_directory,
|
||||||
"harddisk.png", sizeof(buf));
|
"harddisk.png", sizeof(buf));
|
||||||
icons.disk = nk_common_image_load(buf);
|
icons.disk = nk_common_image_load(buf);
|
||||||
|
fill_pathname_join(buf, nk->assets_directory,
|
||||||
|
"folder.png", sizeof(buf));
|
||||||
|
icons.folder = nk_common_image_load(buf);
|
||||||
|
fill_pathname_join(buf, nk->assets_directory,
|
||||||
|
"file.png", sizeof(buf));
|
||||||
|
icons.file = nk_common_image_load(buf);
|
||||||
|
|
||||||
assets_loaded = true;
|
assets_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
||||||
{
|
{
|
||||||
unsigned i;
|
|
||||||
video_shader_ctx_t shader_info;
|
|
||||||
struct nk_panel layout;
|
struct nk_panel layout;
|
||||||
struct nk_context *ctx = &nk->ctx;
|
struct nk_context *ctx = &nk->ctx;
|
||||||
const int id = NK_WND_FILE_PICKER;
|
const int id = NK_WND_FILE_PICKER;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
char buf[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
if (!drives)
|
if (!drives)
|
||||||
{
|
{
|
||||||
drives = (file_list_t*)calloc(1, sizeof(file_list_t));
|
drives = (file_list_t*)calloc(1, sizeof(file_list_t));
|
||||||
frontend_driver_parse_drive_list(drives);
|
frontend_driver_parse_drive_list(drives);
|
||||||
/* RARCH_LOG ("Drives: %s\n",drives->list[0].path); */
|
/* RARCH_LOG ("Drives: %s\n",drives->list[0].path); */
|
||||||
}
|
}
|
||||||
if (!files)
|
|
||||||
files = (file_list_t*)calloc(1, sizeof(file_list_t));
|
|
||||||
|
|
||||||
if (!assets_loaded)
|
if (!assets_loaded)
|
||||||
load_icons(nk);
|
load_icons(nk);
|
||||||
|
@ -78,10 +85,35 @@ void nk_wnd_file_picker(nk_menu_handle_t *nk)
|
||||||
NK_WINDOW_BORDER))
|
NK_WINDOW_BORDER))
|
||||||
{
|
{
|
||||||
nk_layout_row_dynamic(ctx, 30, 3);
|
nk_layout_row_dynamic(ctx, 30, 3);
|
||||||
for (int i = 0; i < drives->size; i++ )
|
for (i = 0; i < drives->size; i++)
|
||||||
{
|
{
|
||||||
nk_button_image_label(ctx, icons.disk, drives->list[i].path, NK_TEXT_CENTERED, NK_BUTTON_DEFAULT);
|
if(nk_button_image_label(ctx, icons.disk, drives->list[i].path,
|
||||||
|
NK_TEXT_CENTERED, NK_BUTTON_DEFAULT))
|
||||||
|
{
|
||||||
|
fill_pathname_join(path, drives->list[i].path,
|
||||||
|
"", sizeof(path));
|
||||||
|
/* RARCH_LOG("Current Path: %s\n", path); */
|
||||||
|
files = dir_list_new(path, NULL, true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
nk_layout_row_dynamic(ctx, 30, 1);
|
||||||
|
if (files)
|
||||||
|
for (i = 0; i < files->size; i++)
|
||||||
|
{
|
||||||
|
/* RARCH_LOG ("Drives: %s\n",files->elems[i].data); */
|
||||||
|
if (nk_button_image_label(ctx, path_is_directory(files->elems[i].data) ?
|
||||||
|
icons.folder : icons.file, path_basename(files->elems[i].data),
|
||||||
|
NK_TEXT_RIGHT, NK_BUTTON_DEFAULT))
|
||||||
|
{
|
||||||
|
fill_pathname_join(path, files->elems[i].data,
|
||||||
|
"", sizeof(path));
|
||||||
|
if (path_is_directory (path))
|
||||||
|
files = dir_list_new(path, NULL, true, true);
|
||||||
|
else
|
||||||
|
RARCH_LOG ("File: %s selected\n", path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/* save position and size to restore after context reset */
|
/* save position and size to restore after context reset */
|
||||||
nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
|
nk_wnd_set_state(nk, id, nk_window_get_position(ctx), nk_window_get_size(ctx));
|
||||||
|
|
Loading…
Reference in New Issue