stew

a monorepo of some sort
git clone git://git.nsmpr.xyz/stew.git
Log | Files | Refs

commit 2afc12834989375e1f6342f9003467510ba47a8c
parent c9c2287e2cc6bed306e3a01f58387a6cd36e046e
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Sun, 15 Sep 2024 18:58:04 +0000

src/boxes: some tinkering

Diffstat:
Msrc/boxes/boxes.c | 29+++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/boxes/boxes.c b/src/boxes/boxes.c @@ -10,6 +10,7 @@ enum{ AlignLeft = 1, AlignCenter = 0, AlignRight = -1, + StringSizesSize = 256, }; typedef struct Box0 Box0; @@ -40,6 +41,8 @@ int colors[] ={ Image *plt[nelem(colors)]; int spw; +int stringsizes[StringSizesSize]; + Rune text[] = L"For whatever reason, it's hard to have text displayed \ on screen in organized manner. Yet text on screen remains the main form of \ interfacing the operator and the computer."; @@ -65,14 +68,20 @@ drawboxen(void) for(j = 0, i = 0; i < nelem(text); j++){ n = runestringfit(font, text + i, nelem(text) - i, Dx(screen->r)); if(n == 0) break; + m = 0; + if(n + i < nelem(text)) for(m = n; m >= 0; m--){ + if(text[i + m] == L' ') break; + if(text[i + m] == L'\0') break; + } + if(m > 0) n = m + 1; + else m = n; str[j] = text + i; - len[j] = n; - rs[j] = Rect(0, 0, runestringnwidth(font, str[j], len[j]), font->height); - // rs[j] = Rect(0, 0, Dx(screen->r), font->height); + len[j] = m; + rs[j] = Rect(0, 0, Dx(screen->r), font->height); i += n; } - + rs[j - 1].max.x = stringsizes[n]; m = arrangerects(rs, Dx(screen->r), rs, j); Box1 win = {screen->r, screen->clipr, plt[0], nil, nil, nil, 0, nil}; @@ -218,11 +227,12 @@ recttopt(Rectangle r, Point pt){ int runestringfit(Font *f, Rune *r, int n, int w){ - int y, i; - for(y = 0, i = 0; i < n; i++){ + int x, i; + for(x = 0, i = 0; i < n; i++){ if(r[i] == L'\0') break; - y += runestringnwidth(f, r + i, 1); - if(y > w) break; + if(i < StringSizesSize) stringsizes[i] = x; + x += runestringnwidth(f, r + i, 1); + if(x > w) break; } return i; } @@ -239,4 +249,4 @@ stringfit(Font *f, char *s, int n, int w){ } return i; } -*/ -\ No newline at end of file +*/