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] =?UTF-8?q?particle/progress-bar:=20don=E2=80=99t=20add=20?= =?UTF-8?q?margins=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; }