UI: nested groups: fixes first and last IDs in a parent

This commit is contained in:
2026-02-20 16:59:56 +02:00
parent 8c765191fb
commit acd03b2769
4 changed files with 38 additions and 13 deletions
+3 -3
View File
@@ -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;
+26 -7
View File
@@ -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)
+3 -2
View File
@@ -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) \