fbar: give each section enough room to show its assertion count

Proportions are only a suggestion at this point but to be honest they
kind of always were.
This commit is contained in:
Lephenixnoir 2021-05-18 11:40:22 +02:00
parent ab754d9bdd
commit daa7ff43ca
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 26 additions and 5 deletions

View File

@ -2,6 +2,7 @@
#include <justui/jwidget-api.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
#include <gint/std/stdio.h>
/* Type identifier for fbar */
static int fbar_type_id = -1;
@ -128,7 +129,26 @@ static void fbar_poly_render(void *b0, int x, int y)
int assertions = st.passed + st.skipped + st.failed;
if(assertions == 0) assertions = 1;
guaranteeable_min = 10 * (!!st.passed + !!st.skipped + !!st.failed);
/* Try to guarantee each section the size of its text, +2 pixels */
int min_passed=0, min_skipped=0, min_failed=0;
char str[10];
if(st.passed) {
sprintf(str, "%d", st.passed);
dsize(str, NULL, &min_passed, NULL);
min_passed += 2;
}
if(st.skipped) {
sprintf(str, "%d", st.skipped);
dsize(str, NULL, &min_skipped, NULL);
min_skipped += 2;
}
if(st.failed) {
sprintf(str, "%d", st.failed);
dsize(str, NULL, &min_failed, NULL);
min_failed += 2;
}
guaranteeable_min = min_passed + min_skipped + min_failed;
guaranteed = (px.done > guaranteeable_min);
if(guaranteed) px.done -= guaranteeable_min;
@ -136,9 +156,9 @@ static void fbar_poly_render(void *b0, int x, int y)
px.skipped = (st.skipped * px.done) / assertions;
px.failed = px.done - px.passed - px.skipped;
if(guaranteed) {
if(st.passed) px.passed += 10;
if(st.skipped) px.skipped += 10;
if(st.failed) px.failed += 10;
px.passed += min_passed;
px.skipped += min_skipped;
px.failed += min_failed;
px.done += guaranteeable_min;
}

View File

@ -147,7 +147,8 @@ static void flist_poly_render(void *l0, int x, int base_y)
int bar_y = (l->top * area_h + l->rows/2) / l->rows;
int bar_h = (l->visible * area_h + l->rows/2) / l->rows;
drect(area_x, area_y, area_x+area_w-1, area_y+area_h-1, C_RGB(24,24,24));
drect(area_x, area_y, area_x+area_w-1, area_y+area_h-1,
C_RGB(24,24,24));
drect(area_x, area_y + bar_y, area_x + area_w - 1,
area_y + bar_y + bar_h, C_BLACK);
}