From 1a30e2898c2ae383c53333e08c8070a0b65661f0 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 7 Jan 2025 23:23:04 +0100 Subject: [PATCH] add sidebar --- mizunara/application.h | 10 +++++++++- mizunara/window.c | 41 +++++++++++++++++++++++++++++++++++++++++ mizunara/window.h | 7 +++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/mizunara/application.h b/mizunara/application.h index 7fd12bc..25e00d2 100644 --- a/mizunara/application.h +++ b/mizunara/application.h @@ -39,7 +39,15 @@ extern "C" { * main window data */ typedef struct MainWindow { - int a; + /* + * sidebar default directories + */ + UiList *default_dirs; + + /* + * sidebar xdg user directories + */ + UiList *user_dirs; } MainWindow; /* diff --git a/mizunara/window.c b/mizunara/window.c index 1c627f9..a03e13c 100644 --- a/mizunara/window.c +++ b/mizunara/window.c @@ -37,6 +37,7 @@ UiObject* window_create(const char *url) { // create window data object MainWindow *wdata = ui_malloc(obj->ctx, sizeof(MainWindow)); memset(wdata, 0, sizeof(MainWindow)); + windowdata_init(obj->ctx, wdata); obj->window = wdata; // create browser document @@ -44,5 +45,45 @@ UiObject* window_create(const char *url) { FileBrowser *browser = filebrowser_new(url); ui_attach_document(obj->ctx, browser); + // add UI + ui_sidebar0(obj) { + UiSubList sublists[] = { + { .value = wdata->default_dirs, .userdata = window_sidebar_default_dirs_item }, + { .value = wdata->user_dirs, .userdata = window_sidebar_user_dirs_item, .separator = TRUE } + }; + ui_sourcelist(obj, .sublists = sublists, .numsublists = 2, .getvalue = window_sidebar_getvalue); + } + + return obj; } + + +void windowdata_init(UiContext *ctx, MainWindow *win) { + win->default_dirs = ui_list_new(ctx, NULL); + win->user_dirs = ui_list_new(ctx, NULL); + + // TODO: init lists + ui_list_append(win->default_dirs, "Test"); + ui_list_append(win->user_dirs, "Test"); +} + +/* + * callback for ui_sourcelist + * + * sublist_userdata: sublist identifier (sidebar_list_default_dirs, sidebar_list_user_dirs) + */ +void window_sidebar_getvalue(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item) { + ui_sublist_getvalue_func getvalue = sublist_userdata; + getvalue(NULL, rowdata, index, item); +} + +void window_sidebar_default_dirs_item(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item) { + item->icon = strdup("user-home-symbolic"); + item->label = strdup("Home"); +} + +void window_sidebar_user_dirs_item(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item) { + item->icon = strdup("folder-documents-symbolic"); + item->label = strdup("Documents"); +} diff --git a/mizunara/window.h b/mizunara/window.h index 20ee458..a5b46bf 100644 --- a/mizunara/window.h +++ b/mizunara/window.h @@ -37,6 +37,13 @@ extern "C" { UiObject* window_create(const char *url); +void windowdata_init(UiContext *ctx, MainWindow *win); + +void window_sidebar_getvalue(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item); + +void window_sidebar_default_dirs_item(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item); +void window_sidebar_user_dirs_item(void *sublist_userdata, void *rowdata, int index, UiSubListItem *item); + #ifdef __cplusplus } -- 2.43.5