Make INDENTATION GREAT AGAIN!

This commit is contained in:
2025-10-18 18:22:10 +02:00
parent f5faf5ae8c
commit c7f218da30

74
box.c
View File

@@ -18,9 +18,12 @@
static void draw_rectangle(double x, double y, double width, double height); static void draw_rectangle(double x, double y, double width, double height);
static void draw_chart(struct box *, double x, double y, double width, double height); static void draw_chart(struct box *, double x, double y, double width,
static void draw_container(struct box *, double x, double y, double width, double height); double height);
static void draw_button(struct box *, double x, double y, double width, double height); static void draw_container(struct box *, double x, double y, double width,
double height);
static void draw_button(struct box *, double x, double y, double width,
double height);
void void
@@ -52,17 +55,17 @@ draw_rectangle(double fx, double fy, double fwidth, double fheight)
} }
for (size_t i = 1; i < h; i++) { for (size_t i = 1; i < h; i++) {
ui_char(x + w, y + i, '|'); ui_char(x + w, y + i, '|');
} }
/* horizontal borders */ /* horizontal borders */
for (size_t i = 1; i < w; i++) { for (size_t i = 1; i < w; i++) {
ui_char(x + i, y, '-'); ui_char(x + i, y, '-');
} }
for (size_t i = 1; i < w; i++) { for (size_t i = 1; i < w; i++) {
ui_char(x + i, y + h, '-'); ui_char(x + i, y + h, '-');
} }
} }
@@ -86,22 +89,23 @@ draw_chart(struct box *chart, double x, double y, double width, double height)
actual_diff = 0; actual_diff = 0;
for (size_t i = 0; i < width; i++) { for (size_t i = 0; i < width; i++) {
diff = (double)rand() / RAND_MAX - 0.6; diff = (double)rand() / RAND_MAX - 0.6;
actual_diff = (size_t)(height + y - price) - (size_t)(height + y - (price + diff)); actual_diff = (size_t)(height + y - price)
- (size_t)(height + y - (price + diff));
if (actual_diff > 0) { if (actual_diff > 0) {
color = UI_GREEN; color = UI_GREEN;
} else if (actual_diff == 0) { } else if (actual_diff == 0) {
color = UI_NONE; color = UI_NONE;
} else if (actual_diff < 0) { } else if (actual_diff < 0) {
color = UI_RED; color = UI_RED;
} }
ui_color_on(color); ui_color_on(color);
ui_char(x + i, height + y - price, c); ui_char(x + i, height + y - price, c);
ui_color_off(color); ui_color_off(color);
price += diff; price += diff;
} }
} }
@@ -124,32 +128,36 @@ draw_container(struct box *b, double x, double y, double width, double height)
switch (b->type) { switch (b->type) {
case BOX_VERTICAL: case BOX_VERTICAL:
length = height; length = height;
current = y; current = y;
break; break;
case BOX_HORIZONTAL: case BOX_HORIZONTAL:
length = width; length = width;
current = x; current = x;
break; break;
} }
total_fills = 0; total_fills = 0;
for (size_t i = 0; i < b->length; i++) { for (size_t i = 0; i < b->length; i++) {
total_fills += b->children[i]->fills; total_fills += b->children[i]->fills;
} }
pixels_per_fill = length / total_fills; pixels_per_fill = length / total_fills;
for (size_t i = 0; i < b->length; i++) { for (size_t i = 0; i < b->length; i++) {
child = b->children[i]; child = b->children[i];
length = child->fills * pixels_per_fill; length = child->fills * pixels_per_fill;
switch (b->type) { switch (b->type) {
case BOX_VERTICAL: draw_box(child, x, current, width, length); break; case BOX_VERTICAL:
case BOX_HORIZONTAL: draw_box(child, current, y, length, height); break; draw_box(child, x, current, width, length);
} break;
case BOX_HORIZONTAL:
draw_box(child, current, y, length, height);
break;
}
current += length; current += length;
} }
} }