ref: aca0f958f91ee7adaaae77eb85c8ca9b8467da87
parent: be943b6d7827481d7e8e7458d36983f53082315f
author: spew <spew@palas>
date: Wed Jan 29 01:59:10 EST 2025
use maxlines and don't shadow nlines
--- a/guitest.c
+++ b/guitest.c
@@ -80,7 +80,6 @@
drawtext(Chan *chan, int resize)
{
Rectangle scrollcur, bodyr;
- int scrlines;
scrollr = screen->r;
scrollr.max.x = screen->r.min.x + Scrollwid + 1;
@@ -89,12 +88,6 @@
bodyr.min.y = screen->r.min.y;
bodyr.max = screen->r.max;
- scrollcur = scrollr;
- scrlines = Dy(screen->r)/display->defaultfont->height; // How many lines on the screen.
- scrollcur.min.y = screen->r.min.y + max(0, Dy(screen->r)*chan->curline/chan->nlines);
- scrollcur.max.y = scrollcur.min.y+Dy(screen->r)*scrlines/chan->nlines;
- scrollcur = insetrect(scrollcur, 1);
-
if(resize){
frclear(chan, 0);
frinit(chan, bodyr, display->defaultfont, screen, cols);
@@ -103,7 +96,13 @@
draw(screen, screen->r, cols[BACK], nil, ZP);
frinsert(chan, offset(chan->body, chan->curline), chan->body + chan->bodylen, 0);
draw(screen, scrollr, cols[BORD], nil, ZP);
+
+ scrollcur = scrollr;
+ scrollcur.min.y = screen->r.min.y + max(0, Dy(screen->r)*chan->curline/chan->totlines);
+ scrollcur.max.y = scrollcur.min.y+Dy(screen->r)*chan->maxlines/chan->totlines;
+ scrollcur = insetrect(scrollcur, 1);
draw(screen, scrollcur, cols[BACK], nil, ZP);
+
flushimage(display, 1);
}
@@ -110,7 +109,7 @@
void
setcurline(int y, Chan *chan)
{
- chan->curline = (y-scrollr.min.y)*chan->nlines/Dy(scrollr);
+ chan->curline = (y-scrollr.min.y)*chan->totlines/Dy(scrollr);
}
void
@@ -141,7 +140,7 @@
chan = emallocz(sizeof(*chan), 1);
chan->body = lorem;
chan->bodylen = runestrlen(chan->body);
- chan->nlines = lines(chan->body);
+ chan->totlines = lines(chan->body);
Alt a[NCHAN+1] = {
[MOUSE] = {mc->c, &m, CHANRCV},