eww icon indicating copy to clipboard operation
eww copied to clipboard

[FEATURE] Function to add digit or space padding to a value

Open MostHated opened this issue 2 years ago • 1 comments

Description of the requested feature

It would be helpful to have a function to easily add digit or space padding to a value to help keep interval displayed values from "popping" their position.

Ex:

CPU: 7.5%
CPU: 12.5%
         ^--- shifts position due to the newly displayed digit

Proposed configuration syntax

padleft(value, replacement_char, digits_to_pad)

Just as a quick example:

Using a 0 as padding:

padleft(round(EWW_CPU.avg, 1), "0", 5)

(label :text "CPU: ") (label :text "${padleft(round(EWW_CPU.avg, 1), '0', 5)}")

CPU: 007.5
CPU: 012.5
CPU: 100.0

Using a space as padding:

padleft(round(EWW_CPU.avg, 1), ' ', 5)

(label :text "CPU: ") (label :text "${padleft(round(EWW_CPU.avg, 1), ' ', 5)}")

CPU:   7.5
CPU:  12.5
CPU: 100.0

Additional context

No response

MostHated avatar Apr 23 '22 21:04 MostHated

For now can't you just do it with regexs ?

replace("000${round(EWW_CPU.avg, 1)}", "^.*([0-9]{3}\.[0-9]$)", "\\1")

viandoxdev avatar Apr 24 '22 11:04 viandoxdev

As a note for anyone that stumbles upon this: When you want to use spaces for padding you need another character before them because (label) strips leading whitespace. You can't split your text into multiple (label) widgets as in the OP. You need to also account for an additional space if you want to keep one between your text and the value.

(label :text {replace("CPU:      ${round(EWW_CPU.avg, 1)}%", " *([0-9. ]{6})", "\\1")})
CPU:   7.5%
CPU:  12.5%
CPU: 100.0%

(1 space + 3 digits/padding + 1 dot + 1 digit = 6 characters)

Although the whole concept of padding with characters (and spaces in particular) only makes sense with a monospace font, I'm still in favor of a dedicated character padding function.

Daxtorim avatar Nov 17 '22 15:11 Daxtorim

Yes please! This s such an importnt feature! Meanwhile I found a hacky way to get it to work without the need of a visible character. It still needs a space for each digit like the kind people above figured out, but you can put a "hair space" infront instead of a visible character, so you can use your seperate labels or whatever for prefixing. Works like a charm and it only occupies like 1 or 2 pixels. You can find the "hair space" here: https://empty-character.com/ I also copied it here inside the quotes: " ". This should be sufficient until the feature gets implemented

fov95 avatar Apr 24 '23 17:04 fov95