Further improve file_browser.c

-Adds visible boundary to file icon box;
-Adds a 'cancel' button that closes the file dialog;
-Adds a 'save' button that should be used for the save() routine defined by the user;
This commit is contained in:
crazyBaboon 2022-03-26 18:28:49 +00:00 committed by GitHub
parent ceee8839ab
commit a1df0c4f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
nk_bool file_browser_is_open;
struct icons { struct icons {
struct nk_image desktop; struct nk_image desktop;
struct nk_image home; struct nk_image home;
@ -325,6 +327,7 @@ file_browser_reload_directory_content(struct file_browser *browser, const char *
static void static void
file_browser_init(struct file_browser *browser, struct media *media) file_browser_init(struct file_browser *browser, struct media *media)
{ {
file_browser_is_open = nk_true;
memset(browser, 0, sizeof(*browser)); memset(browser, 0, sizeof(*browser));
browser->media = media; browser->media = media;
{ {
@ -373,8 +376,10 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
struct media *media = browser->media; struct media *media = browser->media;
struct nk_rect total_space; struct nk_rect total_space;
if (file_browser_is_open)
{
if (nk_begin(ctx, "File Browser", nk_rect(50, 50, 600, 400), if (nk_begin(ctx, "File Browser", nk_rect(50, 50, 600, 400),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_NO_SCROLLBAR|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{ {
static float ratio[] = {0.25f, NK_UNDEFINED}; static float ratio[] = {0.25f, NK_UNDEFINED};
@ -405,7 +410,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
/* window layout */ /* window layout */
total_space = nk_window_get_content_region(ctx); total_space = nk_window_get_content_region(ctx);
nk_layout_row(ctx, NK_DYNAMIC, total_space.h, 2, ratio); nk_layout_row(ctx, NK_DYNAMIC, total_space.h - 40, 2, ratio);
nk_group_begin(ctx, "Special", NK_WINDOW_NO_SCROLLBAR); nk_group_begin(ctx, "Special", NK_WINDOW_NO_SCROLLBAR);
{ {
@ -424,7 +429,7 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
} }
/* output directory content window */ /* output directory content window */
nk_group_begin(ctx, "Content", 0); nk_group_begin(ctx, "Content", NK_WINDOW_BORDER);
{ {
int index = -1; int index = -1;
size_t i = 0, j = 0; size_t i = 0, j = 0;
@ -478,8 +483,20 @@ file_browser_run(struct file_browser *browser, struct nk_context *ctx)
} }
nk_group_end(ctx); nk_group_end(ctx);
} }
nk_layout_row_dynamic(ctx, 30, 5);
nk_label(ctx,"",NK_TEXT_LEFT);
nk_label(ctx,"",NK_TEXT_LEFT);
nk_label(ctx,"",NK_TEXT_LEFT);
if(nk_button_label(ctx, "Cancel"))
{
fprintf(stdout, "File dialog has been closed!\n");
file_browser_is_open = nk_false;
}
if(nk_button_label(ctx, "Save"))
fprintf(stdout, "Insert routine to open/save the file!\n");
} }
nk_end(ctx); nk_end(ctx);
}
return ret; return ret;
} }