From ca43eb3016ef5ebe5cbdfe9bea2fbbb6410eeede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:56:01 +0200 Subject: [PATCH 1/6] =?UTF-8?q?particle/dynlist:=20don=E2=80=99t=20adjust?= =?UTF-8?q?=20spacing=20if=20all=20sub-items=20are=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, if all sub-items are zero-width, make sure *we* return a zero width, instead of a negative width. --- particles/dynlist.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/particles/dynlist.c b/particles/dynlist.c index 8c6319c..5b64dbe 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -1,6 +1,7 @@ #include "dynlist.h" #include +#include #define LOG_MODULE "dynlist" #include "../log.h" @@ -36,15 +37,24 @@ dynlist_begin_expose(struct exposable *exposable) const struct private *e = exposable->private; exposable->width = 0; + bool have_at_least_one = false; for (size_t i = 0; i < e->count; i++) { struct exposable *ee = e->exposables[i]; e->widths[i] = ee->begin_expose(ee); - exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + assert(e->widths[i] >= 0); + + if (e->widths[i] > 0) { + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + have_at_least_one = true; + } } - exposable->width -= e->left_spacing + e->right_spacing; + if (have_at_least_one) + exposable->width -= e->left_spacing + e->right_spacing; + else + assert(exposable->width == 0); return exposable->width; } From 73e1d328c3d81491d4ac214b269b8c6c1138b5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:57:19 +0200 Subject: [PATCH 2/6] =?UTF-8?q?particle/list:=20don=E2=80=99t=20adjust=20s?= =?UTF-8?q?pacing=20if=20all=20sub-items=20are=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, if all sub-items are zero-width, make sure *we* return a zero width, instead of a negative width. --- particles/list.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/particles/list.c b/particles/list.c index 9f03231..19ff15b 100644 --- a/particles/list.c +++ b/particles/list.c @@ -39,18 +39,29 @@ static int begin_expose(struct exposable *exposable) { const struct eprivate *e = exposable->private; + bool have_at_least_one = false; - exposable->width = exposable->particle->left_margin; + exposable->width = 0; for (size_t i = 0; i < e->count; i++) { struct exposable *ee = e->exposables[i]; e->widths[i] = ee->begin_expose(ee); - exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + assert(e->widths[i] >= 0); + + if (e->widths[i] > 0) { + exposable->width += e->left_spacing + e->widths[i] + e->right_spacing; + have_at_least_one = true; + } } - exposable->width -= e->left_spacing + e->right_spacing; - exposable->width += exposable->particle->right_margin; + if (have_at_least_one) { + exposable->width -= e->left_spacing + e->right_spacing; + exposable->width += exposable->particle->left_margin; + exposable->width += exposable->particle->right_margin; + } else + assert(exposable->width == 0); + return exposable->width; } From dab6428859057e870012dd01f4f131d56ccab2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:57:35 +0200 Subject: [PATCH 3/6] =?UTF-8?q?particle/map:=20don=E2=80=99t=20add=20margi?= =?UTF-8?q?ns=20if=20all=20sub-items=20are=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, if all sub-items are zero-width, make sure *we* return a zero width. --- particles/map.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/particles/map.c b/particles/map.c index e2d8c03..980bdd1 100644 --- a/particles/map.c +++ b/particles/map.c @@ -41,11 +41,13 @@ begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; - exposable->width = ( - exposable->particle->left_margin + - e->exposable->begin_expose(e->exposable) + - exposable->particle->right_margin); + int width = e->exposable->begin_expose(e->exposable); + assert(width >= 0); + if (width > 0) + width += exposable->particle->left_margin + exposable->particle->right_margin; + + exposable->width = width; return exposable->width; } From def90edde1d13f6876dd1fdc8670fffbe591c8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:58:07 +0200 Subject: [PATCH 4/6] =?UTF-8?q?particle/progress-bar:=20don=E2=80=99t=20ad?= =?UTF-8?q?d=20margins=20if=20all=20sub-items=20are=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, if all sub-items are zero-width, make sure *we* return a zero width. --- particles/progress-bar.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/particles/progress-bar.c b/particles/progress-bar.c index 52d1e74..7011feb 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -57,14 +57,27 @@ static int begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; + bool have_at_least_one = false; - /* Margins */ - exposable->width = exposable->particle->left_margin + - exposable->particle->right_margin; + exposable->width = 0; /* Sub-exposables */ - for (size_t i = 0; i < e->count; i++) - exposable->width += e->exposables[i]->begin_expose(e->exposables[i]); + for (size_t i = 0; i < e->count; i++) { + int width = e->exposables[i]->begin_expose(e->exposables[i]); + + assert(width >= 0); + if (width >= 0) { + exposable->width += width; + have_at_least_one = true; + } + } + + /* Margins */ + if (have_at_least_one) { + exposable->width = exposable->particle->left_margin + + exposable->particle->right_margin; + } else + assert(exposable->width == 0); return exposable->width; } From af0b7e57d8fdcc3abf9ce685d45104ee3efdd5e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:58:20 +0200 Subject: [PATCH 5/6] =?UTF-8?q?particle/ramp:=20don=E2=80=99t=20add=20marg?= =?UTF-8?q?ins=20if=20all=20sub-items=20are=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That is, if all sub-items are zero-width, make sure *we* return a zero width. --- particles/ramp.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/particles/ramp.c b/particles/ramp.c index 3fa2fc8..1d4cb59 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -37,11 +37,13 @@ begin_expose(struct exposable *exposable) { struct eprivate *e = exposable->private; - exposable->width = ( - exposable->particle->left_margin + - e->exposable->begin_expose(e->exposable) + - exposable->particle->right_margin); + int width = e->exposable->begin_expose(e->exposable); + assert(width >= 0); + if (width > 0) + width += exposable->particle->left_margin + exposable->particle->right_margin; + + exposable->width = width; return exposable->width; } From 7ca22a6dabab0c7daa0475e41e259a3eaf64f58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 25 Aug 2021 13:58:40 +0200 Subject: [PATCH 6/6] =?UTF-8?q?bar:=20don=E2=80=99t=20adjust=20spacing=20f?= =?UTF-8?q?or=20left/center/right=20widths=20if=20all=20exposables=20are?= =?UTF-8?q?=20zero-width?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bar/bar.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/bar/bar.c b/bar/bar.c index 21d95c5..b29936b 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -55,9 +55,16 @@ calculate_widths(const struct private *b, int *left, int *center, int *right) } /* No spacing on the edges (that's what the margins are for) */ - *left -= b->left_spacing + b->right_spacing; - *center -= b->left_spacing + b->right_spacing; - *right -= b->left_spacing + b->right_spacing; + if (*left > 0) + *left -= b->left_spacing + b->right_spacing; + if (*center > 0) + *center -= b->left_spacing + b->right_spacing; + if (*right > 0) + *right -= b->left_spacing + b->right_spacing; + + assert(*left >= 0); + assert(*center >= 0); + assert(*right >= 0); } static void @@ -99,6 +106,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->left.exps[i] = module_begin_expose(m); + assert(bar->left.exps[i]->width >= 0); } for (size_t i = 0; i < bar->center.count; i++) { @@ -107,6 +115,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->center.exps[i] = module_begin_expose(m); + assert(bar->center.exps[i]->width >= 0); } for (size_t i = 0; i < bar->right.count; i++) { @@ -115,6 +124,7 @@ expose(const struct bar *_bar) if (e != NULL) e->destroy(e); bar->right.exps[i] = module_begin_expose(m); + assert(bar->right.exps[i]->width >= 0); } int left_width, center_width, right_width; @@ -196,7 +206,8 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, for (size_t i = 0; i < bar->left.count; i++) { struct exposable *e = bar->left.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { @@ -212,7 +223,8 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, for (size_t i = 0; i < bar->center.count; i++) { struct exposable *e = bar->center.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) { @@ -224,15 +236,16 @@ on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, mx += e->width + bar->right_spacing; } - mx = bar->width - (right_width - + bar->left_spacing + + mx = bar->width - (right_width + + bar->left_spacing + bar->right_margin + bar->border.right_width); for (size_t i = 0; i < bar->right.count; i++) { struct exposable *e = bar->right.exps[i]; - if (e->width == 0) continue; + if (e->width == 0) + continue; mx += bar->left_spacing; if (x >= mx && x < mx + e->width) {