Skip to content

Instantly share code, notes, and snippets.

@vurtun
Last active July 26, 2021 19:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vurtun/6dc4e2b625a6c4c49765c2b257f436bc to your computer and use it in GitHub Desktop.
Save vurtun/6dc4e2b625a6c4c49765c2b257f436bc to your computer and use it in GitHub Desktop.
struct gui_bnd {int min, mid, max, ext;};
struct gui_box {
struct gui_bnd x;
struct gui_bnd y;
};
#define gui_box(x,y,w,h) (struct gui_box){{x,x+(w>>1),x+w,w},{y,y+(h>>1),y+h,h}}
#define gui_min_max(a,b) (struct gui_bnd){a,a+((b-a)>>1),b,b-a}
#define gui_min_ext(m,e) (struct gui_bnd){m,m+(e>>1),m+e,e}
#define gui_max_ext(m,e) (struct gui_bnd){m-e,m-(e>>1),m,e}
#define gui_mid_min(c,m) (struct gui_bnd){m,c,m+c-m,(m-c)<<1}
#define gui_mid_max(c,m) (struct gui_bnd){m-((m-c)<<1),c,m, (m-c)<<1}
#define gui_mid_ext(c,e) (struct gui_bnd){c-(e>>1),c,c+(e>>1),e}
int main(int argc, char **argv)
{
/* tab control */
struct gui_tab_ctl tab = {.box = menu.box, .sel = app->fs_sel};
tab.box.y = gui_min_max(menu.box.y.min + gap, pan->box.y.max - pad);
gui_tab_ctl_begin(ctx, &tab, pan, TAG_CNT);
{
/* tab header */
struct gui_tab_ctl_hdr hdr = {.box = tab.hdr};
gui_tab_hdr_begin(ctx, &tab, &hdr);
for (int i = 0; i < TAG_CNT; ++i) {
const struct app_view *fs = app->views + i;
const char *lbl = fs->act ? path_file(fs->path,0): "home";
gui_tab_hdr_slot(ctx, &tab, &hdr, hash_ptr(fs), lbl, 0);
}
gui_tab_hdr_end(ctx, &tab, &hdr);
/* tab body */
struct gui_panel bdy = {.box = tab.bdy};
gui_panel_begin(ctx, &bdy, &tab);
{
/* search */
struct gui_panel fnd = {.box = bdy.box};
fnd.box.y = gui_min_ext(bdy.box.y.min, ctx->cfg.item_size);
gui_search(app, fs, ctx, &fnd, &bdy);
/* table */
struct gui_panel tbl = {.box = bdy.box};
tbl.box.y = gui_min_max(fnd.box.y.max + ctx->cfg.gap[1], bdy.box.y.max);
gui_dir_tbl(app, &app->views[app->fs_sel], ctx, &tbl, &bdy);
}
gui_panel_end(ctx, &bdy);
}
gui_tab_ctl_end(ctx, &tab);
app->fs_sel = tab.sel;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment