changeset 3271:cbbaccde0f80

Updated #304: Fixed y position of icons and text
author unexist
date Sat, 30 Dec 2017 18:11:36 +0100
parents 67a7ad766b4f
children 60b19aa1a187
files src/subtle/panel.c src/subtle/text.c
diffstat 2 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/subtle/panel.c	Tue Dec 26 15:48:28 2017 +0100
+++ b/src/subtle/panel.c	Sat Dec 30 18:11:36 2017 +0100
@@ -12,6 +12,10 @@
 
 #include "subtle.h"
 
+#define STYLE_FONT_Y(S, F) \
+  ((subtle->ph - STYLE_HEIGHT((S))) - F->height) / 2 + \
+  F->y + STYLE_TOP((S)); 
+
 /* PanelDrawRect {{{ */
 static void
 PanelDrawRect(Drawable drawable,
@@ -394,10 +398,11 @@
             /* Set window background and border*/
             PanelDrawRect(drawable, p->x, p->width, s);
 
+            int y = STYLE_FONT_Y((*s), s->font);
+
             /* Render text parts */
             subTextRender(p->sublet->text, s->font, subtle->gcs.draw,
-              drawable, p->x + STYLE_LEFT((*s)), s->font->y +
-              STYLE_TOP((*s)), s->fg, s->icon, s->bg);
+              drawable, p->x + STYLE_LEFT((*s)), y, s->fg, s->icon, s->bg);
           }
         break; /* }}} */
       case SUB_PANEL_TITLE: /* {{{ */
@@ -421,8 +426,7 @@
                 /* Draw modes and title */
                 len = strlen(c->name);
                 x   = p->x + STYLE_LEFT(subtle->styles.title);
-                y   = subtle->styles.title.font->y +
-                  STYLE_TOP(subtle->styles.title);
+                y   = STYLE_FONT_Y(subtle->styles.title, subtle->styles.title.font);
 
                 subSharedDrawString(subtle->dpy, subtle->gcs.draw,
                   subtle->styles.title.font, drawable, x, y,
@@ -448,7 +452,7 @@
             /* View buttons */
             for(i = 0; i < subtle->views->ndata; i++)
               {
-                int x = 0;
+                int x = 0, y = 0;
                 SubView *v = VIEW(subtle->views->data[i]);
 
                 /* Skip dynamic views */
@@ -456,21 +460,19 @@
                     !(subtle->client_tags & v->tags))
                   continue;
 
+                /* Select style and calculate x and y offsets */
                 PanelViewStyle(v, i, (p->screen->viewid == i), &s);
 
+                x += STYLE_LEFT((s));
+                y  = STYLE_FONT_Y(s, s.font);
+
                 /* Set window background and border*/
                 PanelDrawRect(drawable, vx, v->width, &s);
 
-                x += STYLE_LEFT((s));
-
                 /* Draw view icon and/or text */
                 if(v->flags & SUB_VIEW_ICON)
                   {
-                    int y = 0, icony = 0;
-
-                    y     = s.font->y + STYLE_TOP((s));
-                    icony = v->icon->height > y ? s.margin.top :
-                      y - v->icon->height;
+                    int icony = (subtle->ph - v->icon->height) / 2;
 
                     subSharedDrawIcon(subtle->dpy, subtle->gcs.draw,
                       drawable, vx + x, icony, v->icon->width,
@@ -480,11 +482,12 @@
 
                 if(!(v->flags & SUB_VIEW_ICON_ONLY))
                   {
+                    /* Add space between icon and text */
                     if(v->flags & SUB_VIEW_ICON) x += v->icon->width + 3;
 
                     subSharedDrawString(subtle->dpy, subtle->gcs.draw,
-                      s.font, drawable, vx + x, s.font->y +
-                      STYLE_TOP((s)), s.fg, s.bg, v->name, strlen(v->name));
+                      s.font, drawable, vx + x, y,s.fg, s.bg, v->name,
+                      strlen(v->name));
                   }
 
                 vx += v->width;
--- a/src/subtle/text.c	Tue Dec 26 15:48:28 2017 +0100
+++ b/src/subtle/text.c	Sat Dec 30 18:11:36 2017 +0100
@@ -102,7 +102,7 @@
         }
     }
 
-  /* Mark other items a clean */
+  /* Mark other items as clean */
   for(; i < t->nitems; i++)
     ITEM(t->items[i])->flags |= SUB_TEXT_EMPTY;
 
@@ -160,10 +160,8 @@
         }
       else if(item->flags & (SUB_TEXT_BITMAP|SUB_TEXT_PIXMAP)) ///< Icons
         {
-          int icony = 0, dx = (0 == i) ? 0 : 3; ///< Add spacing when icon isn't first
-
-          icony = item->height > f->height ?
-            y - f->y - ((item->height - f->height) / 2): y - item->height;
+          int dx = (0 == i) ? 0 : 3; ///< Add spacing when icon isn't first
+          int icony = (subtle->ph - item->height) / 2;
 
           subSharedDrawIcon(subtle->dpy, gc, win, width + dx, icony,
             item->width, item->height, (-1 == item->color) ? icon : item->color,