Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI
feat: optimise folder reads, hovere on filepicker
nusaturn492f1a427639
diff --git a/kit/intern/kit_filebrowser_intern.h b/kit/intern/kit_filebrowser_intern.hindex bd02730..748fdf8 100644--- a/kit/intern/kit_filebrowser_intern.h+++ b/kit/intern/kit_filebrowser_intern.h@@ -67,6 +67,8 @@ typedef struct FBEntry {bool hidden, link, sel;long long size;time_t mtime;+ /* draw_data: filled the first time the row is drawn (fb_entry_details) */+ bool has_details;int icon;char date[40];char size_str[16];@@ -107,6 +109,7 @@ typedef struct FBData {FBFilter *filters; /* the selected one is filter_dd's value */int nfilters;bool scroller_hot; /* pointer over the list's scroller */+ struct tm today, yesterday; /* for "Today" / "Yesterday" dates, from the last read *//* folder_history.cc */char *back[FB_HISTORY], *fwd[FB_HISTORY];@@ -168,7 +171,7 @@ void fb_os_read_system(FBData *f); /* System and Volumes places *//* kit_filelist.c */FBEntry *fb_entry_add(FBData *f, const char *name);-void fb_entry_finish(FBEntry *e);+void fb_entry_details(const FBData *f, FBEntry *e); /* icon, date and size strings, cached */void fb_entries_free(FBData *f);void fb_read_dir(FBData *f);void fb_filter_sort(FBData *f);diff --git a/kit/intern/kit_filebrowser_posix.c b/kit/intern/kit_filebrowser_posix.cindex 1b6715f..0c20e9f 100644--- a/kit/intern/kit_filebrowser_posix.c+++ b/kit/intern/kit_filebrowser_posix.c@@ -104,7 +104,6 @@ bool fb_os_read_dir(FBData *f)e->kind = (ok && S_ISDIR(st.st_mode)) ? FB_KIND_DIR : FB_KIND_FILE;e->size = (ok || lok) ? (long long)use->st_size : 0;e->mtime = (ok || lok) ? use->st_mtime : 0;- fb_entry_finish(e);}closedir(d);return true;diff --git a/kit/intern/kit_filebrowser_win32.c b/kit/intern/kit_filebrowser_win32.cindex 79cd8ef..3d8300e 100644--- a/kit/intern/kit_filebrowser_win32.c+++ b/kit/intern/kit_filebrowser_win32.c@@ -108,7 +108,6 @@ bool fb_os_read_dir(FBData *f)e->link = (fd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0;e->size = ((long long)fd.nFileSizeHigh << 32) | fd.nFileSizeLow;e->mtime = filetime_to_time(fd.ftLastWriteTime);- fb_entry_finish(e);} while (FindNextFileW(h, &fd));FindClose(h);return true;diff --git a/kit/intern/kit_filelist.c b/kit/intern/kit_filelist.cindex 9d86341..627093b 100644--- a/kit/intern/kit_filelist.c+++ b/kit/intern/kit_filelist.c@@ -102,16 +102,15 @@ static const char *file_icon_name(const char *name)* \{ *//* date_string::datetime with "Today" / "Yesterday" */-static void format_datetime(time_t t, char *buf, size_t size)+static void format_datetime(const FBData *f, time_t t, char *buf, size_t size){- struct tm tm, today, yesterday;+ struct tm tm;fb_os_localtime(t, &tm);- fb_os_localtime(time(NULL), &today);- fb_os_localtime(time(NULL) - 86400, &yesterday);char hm[16];strftime(hm, sizeof(hm), "%H:%M", &tm);- const bool is_today = tm.tm_year == today.tm_year && tm.tm_yday == today.tm_yday;- const bool is_yesterday = tm.tm_year == yesterday.tm_year && tm.tm_yday == yesterday.tm_yday;+ const bool is_today = tm.tm_year == f->today.tm_year && tm.tm_yday == f->today.tm_yday;+ const bool is_yesterday = tm.tm_year == f->yesterday.tm_year &&+ tm.tm_yday == f->yesterday.tm_yday;if (is_today || is_yesterday) {snprintf(buf, size, "%s %s", is_today ? "Today" : "Yesterday", hm);}@@ -132,20 +131,25 @@ FBEntry *fb_entry_add(FBData *f, const char *name)return e;}-/* filelist_geticon_file_type_ex + filelist_get_details_column_string */-void fb_entry_finish(FBEntry *e)+/* filelist_geticon_file_type_ex + filelist_get_details_column_string: computed when the row is+ * first drawn and kept in the entry, like Blender's FileDirEntry draw_data. */+void fb_entry_details(const FBData *f, FBEntry *e){static const char *const kind_icons[] = {NULL, "FILE_FOLDER", "FILE_PARENT"};+ if (e->has_details) {+ return;+ }const char *icon = e->kind == FB_KIND_FILE ? file_icon_name(e->name) :(e->kind == FB_KIND_DIR && e->link) ? "FOLDER_REDIRECT" :kind_icons[e->kind];e->icon = bk_icons_lookup(icon);if (e->kind != FB_KIND_PARENT) {- format_datetime(e->mtime, e->date, sizeof(e->date));+ format_datetime(f, e->mtime, e->date, sizeof(e->date));}if (e->kind == FB_KIND_FILE) {BLI_str_format_byte_unit(e->size_str, e->size, true);}+ e->has_details = true;}void fb_entries_free(FBData *f)@@ -163,10 +167,10 @@ void fb_read_dir(FBData *f){fb_entries_free(f);f->error[0] = '\0';+ fb_os_localtime(time(NULL), &f->today);+ fb_os_localtime(time(NULL) - 86400, &f->yesterday);if (!fb_os_path_is_root(f->dir)) {- FBEntry *e = fb_entry_add(f, "..");- e->kind = FB_KIND_PARENT;- fb_entry_finish(e);+ fb_entry_add(f, "..")->kind = FB_KIND_PARENT;}if (!fb_os_read_dir(f)) {snprintf(f->error, sizeof(f->error), "Cannot open directory");@@ -303,23 +307,24 @@ static bool matches_filter(const FBData *f, const FBEntry *e)return any;}-static bool entry_visible(const FBData *f, const FBEntry *e)+/* `pat` is the search as "*search*" (filter_search), or NULL without one. */+static bool entry_visible(const FBData *f, const FBEntry *e, const char *pat){- char pat[300];- snprintf(pat, sizeof(pat), "*%s*", f->search); /* filter_search is matched as "*search*" */return e->kind == FB_KIND_PARENT ||((!e->hidden || fb_show_hidden(f)) && /* is_hidden_dot_filename */(f->mode != FB_MODE_DIRECTORY || e->kind == FB_KIND_DIR) &&- (!f->search[0] || glob_match(pat, e->name)) && matches_filter(f, e));+ (!pat || glob_match(pat, e->name)) && matches_filter(f, e));}void fb_filter_sort(FBData *f){+ char pat[300];+ snprintf(pat, sizeof(pat), "*%s*", f->search);free(f->vis);f->vis = (int *)malloc(sizeof(int) * (size_t)(f->nall > 0 ? f->nall : 1));f->nvis = 0;for (int i = 0; i < f->nall; i++) {- const bool shown = entry_visible(f, &f->all[i]);+ const bool shown = entry_visible(f, &f->all[i], f->search[0] ? pat : NULL);f->all[i].sel &= shown;if (shown) {f->vis[f->nvis++] = i;diff --git a/kit/intern/kit_filelist_view.c b/kit/intern/kit_filelist_view.cindex ac893e0..6030707 100644--- a/kit/intern/kit_filelist_view.c+++ b/kit/intern/kit_filelist_view.c@@ -178,8 +178,9 @@ static void draw_background(const BKNode *n, const FBLayout *l, int first, int rstatic void draw_row(const BKNode *n, const FBLayout *l, int i){- const FBEntry *e = fb_vis_entry(FB(n), i);+ FBEntry *e = fb_vis_entry(FB(n), i);const BKRect t = tile_rect(n, l, i);+ fb_entry_details(FB(n), e);const bool editing = n->edit && i == n->rename_row;const int padx = (int)(0.1f * u());if (!editing) {@@ -464,26 +465,61 @@ static int list_release(BKNode *n, BKEvent *e)return 1;}-static int list_move(BKNode *n, BKEvent *e)+/* The left edge of the strip the scroller can cover (widened, plus its margin). */+static int scroller_edge(const BKNode *n)+{+ return n->x + n->w - (int)(0.45f * u() + 2 * bk_px()) - (int)(0.3f * u());+}++/* Redraw one row's band (hover changes), clipped to the view so the header is kept. */+static void dirty_row(BKNode *n, const FBLayout *l, int i)+{+ BKContext *ctx = bk_ctx(n);+ const BKRect v = view_rect(n, l);+ const int y = tile_rect(n, l, i).ymin - l->border_y;+ if (ctx && i >= 0) {+ bk_ctx_dirty_rect(ctx, (BKRect){n->x, BK_MAX(y, v.ymin), n->x + n->w,+ BK_MIN(y + l->item_h, v.ymax)});+ }+}++static void dirty_scroller(BKNode *n, const FBLayout *l)+{+ BKContext *ctx = bk_ctx(n);+ const BKRect v = view_rect(n, l);+ if (ctx) {+ bk_ctx_dirty_rect(ctx, (BKRect){scroller_edge(n), v.ymin, v.xmax, v.ymax});+ }+}++/* Hover: only the rows and the scroller that change are redrawn. */+static void set_hover(BKNode *n, const FBLayout *l, int hot, bool on_scroller){FBData *f = FB(n);- const FBLayout l = list_layout(n);- const int edge = n->x + n->w - (int)(0.45f * u() + 2 * bk_px()) - (int)(0.3f * u());- const bool on_scroller = has_scroller(n, &l) && e->y >= n->y + l.header_h && e->x >= edge;- const int hot = on_scroller ? -1 : row_at(n, &l, e->y);- if (hot != n->hot || on_scroller != f->scroller_hot) {+ if (hot != n->hot) {+ dirty_row(n, l, n->hot);+ dirty_row(n, l, hot);n->hot = hot;+ }+ if (on_scroller != f->scroller_hot) {+ dirty_scroller(n, l);f->scroller_hot = on_scroller;- bk_invalidate(n);}+}++static int list_move(BKNode *n, BKEvent *e)+{+ const FBLayout l = list_layout(n);+ const bool on_scroller = has_scroller(n, &l) && e->y >= n->y + l.header_h &&+ e->x >= scroller_edge(n);+ set_hover(n, &l, on_scroller ? -1 : row_at(n, &l, e->y), on_scroller);return 0;}static int list_leave(BKNode *n){- n->hot = -1;- FB(n)->scroller_hot = false;- bk_invalidate(n);+ const FBLayout l = list_layout(n);+ set_hover(n, &l, -1, false);return 0;}@@ -495,8 +531,8 @@ static int list_wheel(BKNode *n, BKEvent *e)return 0;}n->scroll = ns;+ bk_invalidate(n); /* first, so the hover rows below merge into it (one region) */list_move(n, e);- bk_invalidate(n);return 1;}