Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
duclos-cavalcanti opened this issue May 20, 2021 · 1 comment
Open

Comments

@duclos-cavalcanti
Copy link

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
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants