aboutsummaryrefslogtreecommitdiff
path: root/libgui/gui.c
diff options
context:
space:
mode:
authorMarvin Borner2020-11-01 12:35:00 +0100
committerMarvin Borner2020-11-01 12:35:00 +0100
commitf40be8b5b6227775901a99946779661d0b4439e6 (patch)
tree34c28f138f4167de258ee18db44707aa4637a68d /libgui/gui.c
parente0d3b1671b3f94657d70223b51285ed287c882df (diff)
Added files demo and needed functions
Diffstat (limited to 'libgui/gui.c')
-rw-r--r--libgui/gui.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libgui/gui.c b/libgui/gui.c
index db7845a..7a47bc9 100644
--- a/libgui/gui.c
+++ b/libgui/gui.c
@@ -67,6 +67,38 @@ static void merge_elements(struct element *container)
}
}
+static void remove_childs(struct element *elem);
+static void remove_element(struct element *elem)
+{
+ if (!elem)
+ return;
+
+ remove_childs(elem);
+ free(elem->ctx->fb);
+ elem->ctx->fb = NULL;
+ free(elem->ctx);
+ elem->ctx = NULL;
+ free(elem->data);
+ elem->data = NULL;
+ free(elem);
+ elem = NULL;
+}
+
+static void remove_childs(struct element *elem)
+{
+ if (!elem || !elem->childs || !elem->childs->head)
+ return;
+
+ struct node *iterator = elem->childs->head;
+ while (iterator != NULL) {
+ struct element *child = iterator->data;
+ remove_element(child);
+ iterator = iterator->next;
+ }
+
+ list_destroy(elem->childs);
+}
+
static struct element *element_at(struct element *container, int x, int y)
{
if (!container || !container->childs || !container->childs->head)
@@ -250,6 +282,31 @@ struct element *gui_add_container(struct element *container, int x, int y, u32 w
return new_container;
}
+void gui_remove_childs(struct element *elem)
+{
+ remove_childs(elem);
+ elem->childs = list_new();
+ gui_sync_container(elem);
+ merge_elements(get_root(elem->window_id));
+ gfx_redraw_focused();
+}
+
+void gui_remove_element(struct element *elem)
+{
+ if (!elem)
+ return;
+
+ u32 id = elem->window_id;
+ struct element *root = get_root(id);
+ u8 is_root = root == elem;
+ remove_element(elem);
+ elem = NULL;
+ if (!is_root) {
+ merge_elements(get_root(id));
+ gfx_redraw_focused();
+ }
+}
+
// TODO: Split into small functions
void gui_event_loop(struct element *container)
{