updates widget positions

This commit is contained in:
2025-12-02 17:11:27 +02:00
parent afbce332b3
commit 32b9628ff2
14 changed files with 108 additions and 48 deletions
+23 -13
View File
@@ -2,45 +2,55 @@
#include "button.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
group_t *init_group(group_el_t *children) {
group_t *init_group(WINDOW **win, uint32_t par_id, group_el_init_t *children,
enum g_direction direction) {
group_t *group = malloc(sizeof(group_t));
/* count elements */
uint32_t count = 0;
for (count = 0; children[count].type != w_end; count++)
for (; children[count].type != w_end; count++)
;
count++; /* TODO: improve counting */
group->elements = malloc(sizeof(group_el_t) * count);
memcpy(group->elements, children, sizeof(group_el_t) * count);
group->elements = calloc(count, sizeof(group_el_t));
group_el_t *elements = group->elements;
for (int i = 0; i < count; i++) {
elements[i].type = children[i].type;
}
/* init child elements */
for (int i = 0; group->elements[i].type != w_end; i++) {
group_el_t *el = &(group->elements)[i];
switch (el->type) {
for (int i = 0; elements[i].type != w_end; i++) {
switch (elements[i].type) {
case w_button:
el->element = init_button();
elements[i].element = init_button(win, par_id, children[i].label);
if (direction == horizontal) {
button_t *b = (button_t *)elements[i].element;
b->w.m_x = group->w.x;
b->w.m_y = group->w.m_y;
group->w.x += b->w.x + 1;
if (group->w.y < b->w.y)
group->w.y = b->w.y;
}
break;
case w_box:
case w_group:
case w_end:
group->w.x--;
break;
}
}
group->direction = horizontal; /* horizontal by default */
return group;
}
void draw_group(WINDOW *win, group_t *group, uint32_t cur_x, uint32_t cur_y) {
void draw_group(WINDOW *win, group_t *group) {
group_el_t *children = group->elements;
int32_t x_used = 0; /* used space */
for (int i = 0; children[i].type != w_end; i++) {
group_el_t *el = &children[i];
switch (el->type) {
case w_button:
x_used += draw_button(win, (button_t *)el->element, cur_x + x_used + 1 * i, cur_y);
draw_button((button_t *)el->element);
break;
case w_box:
case w_group: