|
|
|
@ -63,7 +63,14 @@ jfileselect *jfileselect_create(void *parent)
|
|
|
|
|
fs->scroll = 0;
|
|
|
|
|
fs->visible_lines = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef FX9860G
|
|
|
|
|
fs->line_spacing = 1;
|
|
|
|
|
fs->scrollbar_width = 1;
|
|
|
|
|
#else
|
|
|
|
|
fs->line_spacing = 4;
|
|
|
|
|
fs->scrollbar_width = 2;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
fs->font = dfont_default();
|
|
|
|
|
fs->show_file_size = false;
|
|
|
|
|
|
|
|
|
@ -129,6 +136,11 @@ void jfileselect_set_line_spacing(jfileselect *fs, int line_spacing)
|
|
|
|
|
count_visible_lines(fs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void jfileselect_set_scrollbar_width(jfileselect *fs, int scrollbar_width)
|
|
|
|
|
{
|
|
|
|
|
fs->scrollbar_width = scrollbar_width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void jfileselect_set_show_file_size(jfileselect *fs, bool show_file_size)
|
|
|
|
|
{
|
|
|
|
|
fs->show_file_size = show_file_size;
|
|
|
|
@ -337,7 +349,7 @@ static void jfileselect_poly_csize(void *fs0)
|
|
|
|
|
jwidget *w = &fs->widget;
|
|
|
|
|
|
|
|
|
|
w->w = 128;
|
|
|
|
|
w->h = 6 * max(fs->font->line_height + fs->line_spacing, 0);
|
|
|
|
|
w->h = 3 * max(fs->font->line_height + fs->line_spacing, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void jfileselect_poly_layout(void *fs0)
|
|
|
|
@ -347,6 +359,23 @@ static void jfileselect_poly_layout(void *fs0)
|
|
|
|
|
fs->saveas_input->widget.w = jwidget_content_width(fs) - 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void generate_info_string(char *str, bool isfolder, int size)
|
|
|
|
|
{
|
|
|
|
|
#ifdef FX9860G
|
|
|
|
|
if(isfolder)
|
|
|
|
|
sprintf(str, "%d/", size);
|
|
|
|
|
else if(size < 10000) /* 10 kB */
|
|
|
|
|
sprintf(str, "%d", size);
|
|
|
|
|
else
|
|
|
|
|
sprintf(str, "%dk", size / 1000);
|
|
|
|
|
#else
|
|
|
|
|
if(isfolder)
|
|
|
|
|
sprintf(str, "%d entries", size);
|
|
|
|
|
else
|
|
|
|
|
sprintf(str, "%d B", size);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void jfileselect_poly_render(void *fs0, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
jfileselect *fs = fs0;
|
|
|
|
@ -355,9 +384,15 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
|
|
|
|
|
|
|
|
|
font_t const *old_font = dfont(fs->font);
|
|
|
|
|
int line_height = fs->font->line_height + fs->line_spacing;
|
|
|
|
|
int cw = jwidget_content_width(fs);
|
|
|
|
|
int cw = jwidget_content_width(fs) - 2 * fs->scrollbar_width;
|
|
|
|
|
int ch = jwidget_content_height(fs);
|
|
|
|
|
struct fileinfo *finfo = fs->entries;
|
|
|
|
|
|
|
|
|
|
bool scrollbar =
|
|
|
|
|
fs->entry_count > fs->visible_lines
|
|
|
|
|
&& fs->scrollbar_width > 0;
|
|
|
|
|
int entry_width = cw - (scrollbar ? 2 * fs->scrollbar_width : 0);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < fs->visible_lines && i < fs->entry_count; i++) {
|
|
|
|
|
bool selected = (fs->cursor == fs->scroll + i);
|
|
|
|
|
struct fileinfo *info = &finfo[fs->scroll + i];
|
|
|
|
@ -376,16 +411,29 @@ static void jfileselect_poly_render(void *fs0, int x, int y)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(selected)
|
|
|
|
|
drect(x, line_y, x + cw - 1, line_y + line_height - 1, C_BLACK);
|
|
|
|
|
if(selected) {
|
|
|
|
|
drect(x, line_y, x + entry_width - 1, line_y + line_height - 1,
|
|
|
|
|
C_BLACK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dprint(x+2, text_y, fg, "%s%s", info->name, isfolder ? "/" : "");
|
|
|
|
|
if(fs->show_file_size && info->size >= 0) {
|
|
|
|
|
dprint_opt(x + cw - 3, text_y, fg, C_NONE, DTEXT_RIGHT, DTEXT_TOP,
|
|
|
|
|
isfolder ? "%d entries" : "%d B", info->size);
|
|
|
|
|
char str[32];
|
|
|
|
|
generate_info_string(str, isfolder, info->size);
|
|
|
|
|
dtext_opt(x + entry_width - 3, text_y, fg, C_NONE, DTEXT_RIGHT,
|
|
|
|
|
DTEXT_TOP, str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(scrollbar) {
|
|
|
|
|
int sb_y = ch * fs->scroll / fs->entry_count;
|
|
|
|
|
int sb_h = ch * fs->visible_lines / fs->entry_count;
|
|
|
|
|
|
|
|
|
|
drect(x + cw - fs->scrollbar_width, y + sb_y,
|
|
|
|
|
x + cw - 1, y + sb_y + sb_h - 1,
|
|
|
|
|
C_BLACK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dfont(old_font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|