libs/bfile: add a simple BFile listing test

This commit is contained in:
Lephenixnoir 2021-05-05 10:31:01 +02:00
parent 67999f260e
commit 742089704e
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
6 changed files with 102 additions and 0 deletions

View File

@ -37,6 +37,7 @@ set(SOURCES
src/gint/tlb.c
src/gint/topti.c
src/gint/usb.c
src/libs/bfile.c
src/libs/justui.c
src/libs/libimg.c
src/libs/memory.c
@ -82,6 +83,7 @@ set(ASSETS_fx
assets-fx/img/opt_gint_timers.png
assets-fx/img/opt_gint_tlb.png
assets-fx/img/opt_gint_usb.png
assets-fx/img/opt_libs_bfile.png
assets-fx/img/opt_libs_jui.png
assets-fx/img/opt_main.png
assets-fx/img/opt_mem.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -36,6 +36,7 @@ extern bopti_image_t
img_opt_gint_timers,
img_opt_gint_tlb,
img_opt_gint_usb,
img_opt_libs_bfile,
img_opt_libs_jui,
img_opt_main,
img_opt_mem,

View File

@ -23,4 +23,7 @@ void gintctl_libs_libimg(void);
/* gintctl_libs_justui(): Just User Interfaces */
void gintctl_libs_justui(void);
/* gintctl_libs_bfile(): BFile filesystem */
void gintctl_libs_bfile(void);
#endif /* GINTCTL_LIBS */

View File

@ -83,6 +83,8 @@ struct menu menu_libs = {
gintctl_libs_libimg, 0 },
{ "JustUI widgets",
gintctl_libs_justui, 0 },
{ "BFile filesystem",
gintctl_libs_bfile, 0 },
{ NULL, NULL, 0 },
}};

94
src/libs/bfile.c Normal file
View File

@ -0,0 +1,94 @@
#include <gint/gint.h>
#include <gint/bfile.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/stdio.h>
#include <gintctl/libs.h>
#include <gintctl/util.h>
#include <gintctl/assets.h>
#include <gintctl/widgets/gscreen.h>
#include <gintctl/widgets/gtable.h>
/* Names and file informations (allocated on the stack) */
static uint16_t (*test_names)[32][32];
static struct BFile_FileInfo *test_infos;
int explore_folder(uint16_t const *search, uint16_t names[32][32],
struct BFile_FileInfo infos[32])
{
/* Search descriptor */
int sd = 0;
/* Number of files found */
int found = 0;
int rc = BFile_FindFirst(search, &sd, names[found], &infos[found]);
if(rc < 0) return 0;
while(rc >= 0 && found < 32) {
found++;
rc = BFile_FindNext(sd, names[found], &infos[found]);
}
BFile_FindClose(sd);
return found;
}
static void table_gen(gtable *t, int row)
{
char c1[48]={0}, c2[16];
for(int i = 0; i < 32 && (*test_names)[row][i]; i++)
c1[i] = (*test_names)[row][i];
sprintf(c2, "%d", test_infos[row].file_size);
gtable_provide(t, c1, c2);
}
void gintctl_libs_bfile(void)
{
/* Data for 32 files, each with 32 characters in the name */
uint16_t names[32][32];
struct BFile_FileInfo infos[32];
test_names = &names;
test_infos = infos;
gtable *table = gtable_create(2, table_gen, NULL, NULL);
gtable_set_rows(table, 0);
gtable_set_column_titles(table, "Name", "Size");
gtable_set_column_sizes(table, 3, 1);
gtable_set_font(table, _(&font_mini, dfont_default()));
jwidget_set_margin(table, 0, 2, 1, 2);
gscreen *scr = gscreen_create2("BFile filesystem", &img_opt_libs_bfile,
"BFile access to storage memory", "@LIST;;;;;");
gscreen_add_tabs(scr, table, table);
jscene_set_focused_widget(scr->scene, table);
int key = 0;
while(key != KEY_EXIT) {
jevent e = jscene_run(scr->scene);
if(e.type == JSCENE_PAINT) {
dclear(C_WHITE);
jscene_render(scr->scene);
dupdate();
}
key = 0;
if(e.type == JSCENE_KEY && e.key.type == KEYEV_DOWN)
key = e.key.key;
if(key == KEY_F1) {
int rows = gint_world_switch(GINT_CALL(explore_folder,
u"\\\\fls0\\*", (void *)names, (void *)infos));
gtable_set_rows(table, rows);
}
}
test_names = NULL;
test_infos = NULL;
gscreen_destroy(scr);
}