[hackers] [libsl] improve lrpad || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sun, 5 Apr 2020 17:27:02 +0200 (CEST)

commit f33024dd2dbb6471cb2c5c41f901fc19e4c133a8
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Sun Apr 5 17:26:59 2020 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sun Apr 5 17:26:59 2020 +0200

    improve lrpad

diff --git a/x11/drw.c b/x11/drw.c
index faabe51..6f10331 100644
--- a/x11/drw.c
+++ b/x11/drw.c
_AT_@ -162,21 +162,25 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
         const char *text, int invert)
 {
         char buf[256];
- int i, tx, ty, th, len, olen;
+ int i, tx, ty, th, len, olen, render = x || y || w || h;
         unsigned int texw, texh;
 
- /* TODO: lpad */
-
- XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
- XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
+ if (!render) {
+ w = ~w;
+ } else {
+ XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
+ XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
+ x += lpad;
+ w -= lpad;
+ }
 
         olen = strlen(text);
         drw_font_getexts(drw->fonts, text, olen, &texw, &texh);
         th = drw->fonts->ascent + drw->fonts->descent;
         ty = y + (h / 2) - (th / 2) + drw->fonts->ascent;
- tx = x + (h / 2);
+ tx = x;
         /* shorten text if necessary */
- for (len = MIN(olen, sizeof buf); len && (texw > w - texh || w < texh); len--)
+ for (len = MIN(olen, sizeof buf); len && texw > w; len--)
                 drw_font_getexts(drw->fonts, text, len, &texw, &texh);
         if (!len)
                 return x;
_AT_@ -190,7 +194,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
         else
                 XDrawString(drw->dpy, drw->drawable, drw->gc, tx, ty, buf, len);
 
- return x + w;
+ x += texw;
+ w -= texw;
+
+ return x + (render ? w : 0);
 }
 
 void
_AT_@ -228,10 +235,10 @@ drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w,
                 if (h)
                         *h = r.height;
         } else {
- if (h)
- *h = font->ascent + font->descent;
                 if (w)
                         *w = XTextWidth(font->xfont, text, len);
+ if (h)
+ *h = font->ascent + font->descent;
         }
 }
 
Received on Sun Apr 05 2020 - 17:27:02 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 05 2020 - 17:36:43 CEST