diff --git a/box.c b/box.c index 3d17b10..d5f23b6 100644 --- a/box.c +++ b/box.c @@ -18,9 +18,12 @@ 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_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); +static void draw_chart(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 @@ -52,17 +55,17 @@ draw_rectangle(double fx, double fy, double fwidth, double fheight) } for (size_t i = 1; i < h; i++) { - ui_char(x + w, y + i, '|'); + ui_char(x + w, y + i, '|'); } /* horizontal borders */ 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++) { - 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; for (size_t i = 0; i < width; i++) { - diff = (double)rand() / RAND_MAX - 0.6; - actual_diff = (size_t)(height + y - price) - (size_t)(height + y - (price + diff)); + diff = (double)rand() / RAND_MAX - 0.6; + actual_diff = (size_t)(height + y - price) + - (size_t)(height + y - (price + diff)); - if (actual_diff > 0) { - color = UI_GREEN; - } else if (actual_diff == 0) { - color = UI_NONE; - } else if (actual_diff < 0) { - color = UI_RED; - } + if (actual_diff > 0) { + color = UI_GREEN; + } else if (actual_diff == 0) { + color = UI_NONE; + } else if (actual_diff < 0) { + color = UI_RED; + } - ui_color_on(color); - ui_char(x + i, height + y - price, c); - ui_color_off(color); + ui_color_on(color); + ui_char(x + i, height + y - price, c); + 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) { case BOX_VERTICAL: - length = height; - current = y; - break; + length = height; + current = y; + break; case BOX_HORIZONTAL: - length = width; - current = x; - break; + length = width; + current = x; + break; } total_fills = 0; 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; for (size_t i = 0; i < b->length; i++) { - child = b->children[i]; - length = child->fills * pixels_per_fill; + child = b->children[i]; + length = child->fills * pixels_per_fill; - switch (b->type) { - case BOX_VERTICAL: draw_box(child, x, current, width, length); break; - case BOX_HORIZONTAL: draw_box(child, current, y, length, height); break; - } + switch (b->type) { + case BOX_VERTICAL: + draw_box(child, x, current, width, length); + break; + case BOX_HORIZONTAL: + draw_box(child, current, y, length, height); + break; + } - current += length; + current += length; } }