initial callback support

This commit is contained in:
2025-12-03 14:40:53 +02:00
parent 24f51eb22b
commit eee2bc0ccb
11 changed files with 63 additions and 63 deletions
+17 -10
View File
@@ -9,23 +9,25 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
group_t *group = malloc(sizeof(group_t));
/* count elements */
uint32_t count = 0;
for (; children[count].type != w_end; count++)
group->count = 0;
for (; children[group->count].type != w_end; group->count++)
;
group->elements = calloc(count, sizeof(group_el_t));
group->elements = calloc(group->count, sizeof(group_el_t));
group->w.w_parent = w_parent;
group_el_t *elements = group->elements;
for (int i = 0; i < count; i++) {
for (int i = 0; i < group->count; i++) {
elements[i].type = children[i].type;
}
/* init child elements */
for (int i = 0; elements[i].type != w_end; i++) {
uint32_t el_id = 0;
for (int i = 0; i < group->count; i++) {
switch (elements[i].type) {
case w_button:
elements[i].element = init_button(win, &(group->w), children[i].label);
if (direction == horizontal) {
button_t *b = (button_t *)elements[i].element;
el_id = b->w.id;
b->w.m_x = group->w.x;
b->w.m_y = group->w.m_y;
group->w.x += b->w.x + 1;
@@ -36,21 +38,26 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children,
case w_box:
case w_group:
case w_end:
group->w.x--;
break;
}
if (i == 0) {
group->first_id = el_id;
group->w_active_id = el_id;
} else {
group->last_id = el_id;
}
}
return group;
}
void draw_group(WINDOW *win, group_t *group) {
group_el_t *children = group->elements;
for (int i = 0; children[i].type != w_end; i++) {
for (int i = 0; i < group->count; i++) {
group_el_t *el = &children[i];
switch (el->type) {
case w_button:
draw_button((button_t *)el->element);
draw_button((button_t *)el->element, group->w_active_id);
break;
case w_box:
case w_group:
@@ -62,7 +69,7 @@ void draw_group(WINDOW *win, group_t *group) {
void destroy_group(group_t *group) {
group_el_t *children = group->elements;
for (int i = 0; children[i].type != w_end; i++) {
for (int i = 0; i < group->count; i++) {
group_el_t *el = &children[i];
switch (el->type) {
case w_button: