Working product with sustainable legacies

This commit is contained in:
2025-10-18 20:44:30 +02:00
parent 65a1c9f159
commit a392132fa9
8 changed files with 178 additions and 54 deletions

61
box.c
View File

@@ -17,13 +17,14 @@
#include "util.h"
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_rectangle(unsigned int x, unsigned int y, unsigned int width,
unsigned int height);
static void draw_chart(struct box *, unsigned int x, unsigned int y,
unsigned int width, unsigned int height);
static void draw_container(struct box *, unsigned int x, unsigned int y,
unsigned int width, unsigned int height);
static void draw_button(struct box *, unsigned int x, unsigned int y,
unsigned int width, unsigned int height);
void
@@ -34,44 +35,41 @@ append_box(struct box *parent, struct box *child)
static void
draw_rectangle(double fx, double fy, double fwidth, double fheight)
draw_rectangle(unsigned int x, unsigned int y, unsigned int width,
unsigned int height)
{
size_t x = llround(fx);
size_t y = llround(fy);
size_t w = llround(fwidth) - 1;
size_t h = llround(fheight) - 1;
/* corners */
ui_char(x, y, '+');
ui_char(x, y + h, '+');
ui_char(x + w, y + h, '+');
ui_char(x + w, y, '+');
ui_char(x, y + height, '+');
ui_char(x + width, y + height, '+');
ui_char(x + width, y, '+');
/* vertical borders */
for (size_t i = 1; i < h; i++) {
for (size_t i = 1; i < height; i++) {
ui_char(x, y + i, '|');
}
for (size_t i = 1; i < h; i++) {
ui_char(x + w, y + i, '|');
for (size_t i = 1; i < height; i++) {
ui_char(x + width, y + i, '|');
}
/* horizontal borders */
for (size_t i = 1; i < w; i++) {
for (size_t i = 1; i < width; i++) {
ui_char(x + i, y, '-');
}
for (size_t i = 1; i < w; i++) {
ui_char(x + i, y + h, '-');
for (size_t i = 1; i < width; i++) {
ui_char(x + i, y + height, '-');
}
}
static void
draw_chart(struct box *chart, double x, double y, double width, double height)
draw_chart(struct box *chart, unsigned int x, unsigned int y,
unsigned int width, unsigned int height)
{
long int actual_diff;
double diff, price;
@@ -98,7 +96,8 @@ draw_chart(struct box *chart, double x, double y, double width, double height)
static void
draw_button(struct box *b, double x, double y, double width, double height)
draw_button(struct box *b, unsigned int x, unsigned int y, unsigned int width,
unsigned int height)
{
ui_color_on(b->color);
draw_rectangle(x, y, width, height);
@@ -108,10 +107,11 @@ draw_button(struct box *b, double x, double y, double width, double height)
static void
draw_container(struct box *b, double x, double y, double width, double height)
draw_container(struct box *b, unsigned int x, unsigned int y,
unsigned int width, unsigned int height)
{
double current, length, total_fills, pixels_per_fill;
struct box *child;
unsigned int current, i, length, total_fills, pixels_per_fill;
struct box *child;
switch (b->type) {
case BOX_VERTICAL:
@@ -125,13 +125,13 @@ draw_container(struct box *b, double x, double y, double width, double height)
}
total_fills = 0;
for (size_t i = 0; i < b->length; i++) {
for (i = 0; i < b->length; i++) {
total_fills += b->children[i]->fills;
}
pixels_per_fill = length / total_fills;
for (size_t i = 0; i < b->length; i++) {
for (i = 0; i < b->length; i++) {
child = b->children[i];
length = child->fills * pixels_per_fill;
@@ -206,7 +206,8 @@ new_vertical_box(void)
void
draw_box(struct box *b, double x, double y, double width, double height)
draw_box(struct box *b, unsigned int x, unsigned int y, unsigned int width,
unsigned int height)
{
switch (b->type) {
case BOX_BUTTON: