optimise tree view a tiny bit

don't refresh all the time, wait for the data to be ready. waiting on
the data is not a good idea either, but it is better than to
continously refresh all the data
This commit is contained in:
2019-07-19 21:32:22 +02:00
parent af49931b49
commit a9f23fc278
7 changed files with 53 additions and 9 deletions

View File

@@ -17,6 +17,7 @@ void ncdc_treeitem_set_label(ncdc_treeitem_t i, wchar_t const *s);
void *ncdc_treeitem_tag(ncdc_treeitem_t i);
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t);
size_t ncdc_treeitem_size(ncdc_treeitem_t i);
void ncdc_treeitem_clear(ncdc_treeitem_t i);
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c);
void ncdc_treeitem_remove(ncdc_treeitem_t i, ncdc_treeitem_t c);

View File

@@ -50,7 +50,16 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac,
dc_unref(current_session);
current_session = dc_ref(s);
LOG(n, L"login: %ls: authentication successful, waiting for data...", av[1]);
LOG(n, L"login: %ls: authentication successful, waiting for ready from websocket...",
av[1]
);
while (!dc_session_is_ready(current_session))
;
LOG(n, L"login: %ls: ready", av[1]);
ncdc_mainwindow_update_guilds(n);
ret = true;
cleanup:

View File

@@ -21,6 +21,8 @@ bool ncdc_cmd_logout(ncdc_mainwindow_t n, size_t ac,
dc_unref(current_session);
current_session = NULL;
ncdc_mainwindow_update_guilds(n);
LOG(n, L"logout: successfully logged out");
error:

View File

@@ -397,7 +397,6 @@ void ncdc_mainwindow_refresh(ncdc_mainwindow_t n)
{
ncdc_textview_t v = 0;
ncdc_mainwindow_update_guilds(n);
ncdc_treeview_render(n->guildview, n->guilds, n->guilds_h, n->guilds_w);
wnoutrefresh(n->guilds);

View File

@@ -22,6 +22,19 @@ struct ncdc_treeitem_
void *tag;
};
struct ncdc_treeview_
{
dc_refable_t ref;
/* root element
*/
ncdc_treeitem_t root;
/* currently selected item
*/
ncdc_treeitem_t current;
};
static void ncdc_treeitem_free(ncdc_treeitem_t t)
{
return_if_true(t == NULL,);
@@ -63,6 +76,12 @@ ncdc_treeitem_t ncdc_treeitem_new_string(wchar_t const *s)
return t;
}
size_t ncdc_treeitem_size(ncdc_treeitem_t i)
{
return_if_true(i == NULL || i->children == NULL, 0);
return i->children->len;
}
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c)
{
return_if_true(i == NULL || c == NULL,);
@@ -132,13 +151,6 @@ ncdc_treeitem_render(ncdc_treeitem_t t, WINDOW *win,
return off;
}
struct ncdc_treeview_
{
dc_refable_t ref;
ncdc_treeitem_t root;
};
static void ncdc_treeview_free(ncdc_treeview_t t)
{
return_if_true(t == NULL,);
@@ -159,6 +171,8 @@ ncdc_treeview_t ncdc_treeview_new(void)
t->root = ncdc_treeitem_new();
goto_if_true(t->root == NULL, error);
t->current = t->root;
return dc_ref(t);
error: