From acd03b27699da8690bbd9c53373ece99c97adb79 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Fri, 20 Feb 2026 16:59:56 +0200 Subject: [PATCH] UI: nested groups: fixes first and last IDs in a parent --- TODO.md | 7 ++++++- src/widget/dialogue.h | 6 +++--- src/widget/group.c | 33 ++++++++++++++++++++++++++------- src/widget/group.h | 5 +++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index 911c38c..13f44a3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,15 +1,20 @@ # TODO: +## Current: +- [ ] UI: vertical layout (needs for email in registration) +- [ ] Nested groups +- [ ] Create dynamic map of elements IDs and their pointers + ## Features: - [x] Search files - [x] Correct spacing in the search bar - [x] Finish registration -- [ ] UI: vertical layout (needs for email in registration) - [ ] Get rid of old notification mechanism - [ ] Privilege settings for files - [ ] Files removal - [ ] Encryption - [ ] UTF-8 support + ## Fixes: - [ ] Check and fix registration and login - [ ] Hotkeys for buttons diff --git a/src/widget/dialogue.h b/src/widget/dialogue.h index 895a120..f8b92c5 100644 --- a/src/widget/dialogue.h +++ b/src/widget/dialogue.h @@ -20,9 +20,9 @@ typedef struct { enum g_type type; } active; char text[DIALOGUE_TEXT]; - uint32_t is_initiated : 1; - uint32_t needs_update : 1; - uint32_t needs_destroy : 1; + bool is_initiated; + bool needs_update; + bool needs_destroy; coordinates_t *p_coordinates; enum d_color_scheme color_scheme; } dialogue_t; diff --git a/src/widget/group.c b/src/widget/group.c index 2a04bbc..71820d1 100644 --- a/src/widget/group.c +++ b/src/widget/group.c @@ -77,9 +77,17 @@ void group_default_callback(callback_args_t *args) { } } +union current_element { + group_t *group; + enum w_type type; +}; + group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, enum g_direction direction) { group_t *group = malloc(sizeof(group_t)); + union current_element current; + group->parent_group = NULL; + current.type = w_end; init_widget(&(group->w), w_parent, win, ""); /* count elements */ group->count = 0; @@ -111,7 +119,16 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, case w_group: elements[i].element = init_group(win, &(group->w), children[i].children, children[i].direction); - w = &(((input_t *)elements[i].element)->w); + w = &(((group_t *)elements[i].element)->w); + current.group = (group_t *)elements[i].element; + current.group->parent_group = group; + if (i == 0) { + group->first_id = current.group->first_id; + group->last_id = current.group->last_id; + } else { + group->last_id = current.group->last_id; + } + current.type = w_group; break; case w_input: elements[i].element = @@ -128,6 +145,14 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, w = &(((ui_progress_bar_t *)elements[i].element)->w); break; } + if (current.type != w_group) { + if (i == 0) { + group->first_id = w->id; + group->last_id = w->id; + } else { + group->last_id = w->id; + } + } /* set dimensions */ elements[i].id = w->id; if (direction == horizontal) { @@ -143,12 +168,6 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, if (group->w.x < w->x) group->w.x = w->x; } - if (i == 0) { - group->first_id = w->id; - group->last_id = w->id; - } else { - group->last_id = w->id; - } } if (direction == vertical) diff --git a/src/widget/group.h b/src/widget/group.h index 36e4c68..6f3deb5 100644 --- a/src/widget/group.h +++ b/src/widget/group.h @@ -13,7 +13,7 @@ typedef struct { uint32_t id; void *element; enum w_type type; - uint32_t is_default : 1; + bool is_default; } group_el_t; typedef struct group_el_init_t { @@ -26,12 +26,13 @@ typedef struct group_el_init_t { struct group_el_init_t *children; } group_el_init_t; -typedef struct { +typedef struct group_t{ widget_t w; group_el_t *elements; enum g_direction direction; uint32_t count; uint32_t first_id, last_id; + struct group_t *parent_group; } group_t; #define FIND_ACTIVE_ELEMENT(g, active_id, element_ptr, element_idx) \