commit b6195e0c13e72f0f6d9240fe913c9c9ee0c35c24
parent 69ab88ccd41b6ecccee54cef47feacfb3070bcc2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 22 Jul 2020 11:27:35 +0200
rework updatesidebar drawing and width calculation
Fixes an issue, to reproduce:
- Start sfeed_curses.
- Reload all with data that updates the counts so that it requires more space
(like new items for the longest feed).
- The width was not updated on reload (anymore).
Changes:
- Separate width calculation more clearly from drawing/format
(feed_row_format). It used to calculate when the pane width is 0, otherwise
use the available space.
- Call updategeom if the pane width changes, recalculating the items pane also.
It can now needlessly redraw the statusbar, but that doesn't matter much.
- Remove unneeded max width calculation when using the available pane width.
Diffstat:
M | sfeed_curses.c | | | 58 | ++++++++++++++++++++++++++++++++++++---------------------- |
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/sfeed_curses.c b/sfeed_curses.c
@@ -1256,6 +1256,29 @@ feeds_reloadall(void)
updatetitle();
}
+int
+getsidebarwidth(void)
+{
+ struct feed *feed;
+ static char text[1024];
+ int i, len, width = 0;
+
+ for (i = 0; i < nfeeds; i++) {
+ feed = &feeds[i];
+
+ snprintf(text, sizeof(text), "%s (%lu/%lu)",
+ feed->name, feed->totalnew, feed->total);
+ len = colw(text);
+ if (len > width)
+ width = len;
+
+ if (onlynew && feed->totalnew == 0)
+ continue;
+ }
+
+ return width;
+}
+
void
updatesidebar(int onlynew)
{
@@ -1263,15 +1286,17 @@ updatesidebar(int onlynew)
struct row *row;
struct feed *feed;
size_t i, nrows;
- int len, width;
+ int len, oldwidth;
p = &panes[PaneFeeds];
if (!p->rows)
p->rows = ecalloc(sizeof(p->rows[0]), nfeeds + 1);
+ oldwidth = p->width;
+ p->width = getsidebarwidth();
+
nrows = 0;
- width = 0;
for (i = 0; i < nfeeds; i++) {
feed = &feeds[i];
@@ -1280,24 +1305,18 @@ updatesidebar(int onlynew)
row->bold = (feed->totalnew > 0);
row->data = feed;
- len = colw(pane_row_text(p, row));
- if (len > width)
- width = len;
-
if (onlynew && feed->totalnew == 0)
continue;
nrows++;
}
+ p->nrows = nrows;
- if (p->width != width) {
- for (i = 0; i < PaneLast; i++)
- panes[i].dirty = 1;
- } else {
+ if (p->width != oldwidth)
+ updategeom();
+ else
p->dirty = 1;
- }
- p->nrows = nrows;
- p->width = width;
+
if (!p->nrows)
p->pos = 0;
else if (p->pos >= p->nrows)
@@ -1450,15 +1469,10 @@ feed_row_format(struct pane *p, struct row *row)
feed = (struct feed *)row->data;
- if (p->width) {
- len = snprintf(counts, sizeof(counts), "(%lu/%lu)",
- feed->totalnew, feed->total);
- utf8pad(bufw, sizeof(bufw), feed->name, p->width - len, ' ');
- snprintf(text, sizeof(text), "%s%s", bufw, counts);
- } else {
- snprintf(text, sizeof(text), "%s (%lu/%lu)",
- feed->name, feed->totalnew, feed->total);
- }
+ len = snprintf(counts, sizeof(counts), "(%lu/%lu)",
+ feed->totalnew, feed->total);
+ utf8pad(bufw, sizeof(bufw), feed->name, p->width - len, ' ');
+ snprintf(text, sizeof(text), "%s%s", bufw, counts);
return text;
}