summaryrefslogtreecommitdiff
path: root/ui.c
diff options
context:
space:
mode:
authorkatalx2026-01-28 23:29:37 -0500
committerkatalx2026-01-28 23:29:37 -0500
commitc971822bff00dc74e7038d8e0e9041d205e44a83 (patch)
tree836427cf1ff9e46e31a785d9a0d48068a7d60cf2 /ui.c
parent4144529a31d9c7543a3e1855ef53acaa8f1d0dce (diff)
only draw visible lines
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ui.c b/ui.c
index 6080f13..e4d2c30 100644
--- a/ui.c
+++ b/ui.c
@@ -158,7 +158,19 @@ ui_draw(Str input, int inpi, int seli, UiOpts o)
XSetFont(dsp, gc, freg->fid);
int y = 64;
- for (int i = 0; i < o.n; i++) {
+
+ int lines = (attr.height - 32) / 24;
+ int tline = lines / 2;
+ int bline = lines - tline;
+ int scroll = seli;
+ if (scroll > o.n - bline) scroll = o.n - bline;
+ if (scroll < tline) scroll = tline;
+ int top = scroll - tline;
+ int bot = scroll + bline;
+ if (top < 0) top = 0;
+ if (bot > o.n) bot = o.n;
+
+ for (int i = top; i < bot; i++) {
if (i == seli) {
int w = XTextWidth(freg, o.v[i].s, o.v[i].n);
XFillRectangle(dsp, win, gc,