robm / dzen

Dzen is a general purpose messaging, notification and menuing program for X11.
MIT License
606 stars 81 forks source link

Text Alignment with Different Fonts/Fonts that contain Icons #56

Open duclos-cavalcanti opened 3 years ago

duclos-cavalcanti commented 3 years ago

Hi,

Im pretty happy with dzen and its scriptable capabilties. Aside from a general menu-like program, I also use it as a statusbar. I have however struggled with alignment issues.

Im aware (at least I believe so) that ^p() and even ^p(_LEFT/_RIGHT/_CENTER) are calculated relative to the current cursor position on the dzen instance. So, this isnt necessarily the best option if one is aiming to have a bar with left, center and right aligned text/icons.

Im also aware of the undocumented ^ba($bar_width, _LEFT/_CENTER/_RIGHT) option. However, if I was to run

echo "^ba(1920,_LEFT)Left^ba(1920,_CENTER)Center" | dzen2 -w 1920 -ta l -p

Things don't go as planned. Its hard to know why or if I am using it incorrectly since there isnt much to read on. But it seems that this justification of text is always relative to the current cursor position.

Im also aware of textwidth, where one could sample the width in pixels of a given string with a given font. That way knowing the width of ones text, together with the usage of absolute positioning of pa(), it then becomes feasible a proper alignment of a statusbar.

However, using different fonts through fn(), especially nerd/patched/powerline fonts, I at least have not been successfully able to find pixelwidths of different texts that are patched with icons. It may well be due to the fact that textwidth may only accept X logical font description of fonts and apparently icon patched fonts do not fall into that configuration.

Therefore alignment ends up hard coded which is a bit of a bummer.

I was wondering if a veteran user or mantainer or anyone knows about undocumented features or solutions to properly align a dzen statusbar which contains different fonts and/or with icons, could enlighten me.

IsaacElenbaas commented 2 years ago

The issue is that Left moves the current position right. Left^pa(0;0)^ba(1920,_CENTER)Center gives you correct positioning, but ba still draws the background and overwrites Left once the positioning is correct. Left^pa(0;0)^ib(1)^ba(1920,_CENTER)Center works, but ib can't be reset until you somehow position yourself elsewhere (the ba is no longer in effect) for reasons unknown to me. If you're just using text (no rectangles or anything) you can just ^p(_LOCK_X) at the beginning instead of ^pa(0;0)ing everywhere.