feat(tokens): Negative minimum length adds right padding (#2801)

* negative minimum length adds right padding

* missing else statement

* updated changelog
This commit is contained in:
Ashwin Rajesh 2022-08-25 08:36:38 +10:00 committed by GitHub
parent 6ccecbfca2
commit 7838241a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- `internal/fs`: Use `/` as a fallback if no mountpoints are specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2705`](https://github.com/polybar/polybar/pull/2705))
- `internal/backlight`: Detect backlight if none specified ([`#2572`](https://github.com/polybar/polybar/issues/2572), [`#2728`](https://github.com/polybar/polybar/pull/2728))
- Providing a negative min-width to a token adds right-padding ([`#2789`](https://github.com/polybar/polybar/issues/2789), [`#2801`](https://github.com/polybar/polybar/pull/2801)) by [@VanillaViking](https://github.com/VanillaViking).
### Fixed
- Waiting for double click interval on modules that don't have a double click action ([`#2663`](https://github.com/polybar/polybar/issues/2663), [`#2695`](https://github.com/polybar/polybar/pull/2695))

View File

@ -16,6 +16,7 @@ namespace drawtypes {
size_t max{0_z};
string suffix{""s};
bool zpad{false};
bool rpadding{false};
};
class label : public non_copyable_mixin {

View File

@ -86,7 +86,11 @@ namespace drawtypes {
if (tok.max != 0_z && string_util::char_len(repl) > tok.max) {
repl = string_util::utf8_truncate(std::move(repl), tok.max) + tok.suffix;
} else if (tok.min != 0_z && repl.length() < tok.min) {
repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' ');
if (tok.rpadding) {
repl.append(tok.min - repl.length(), ' ');
} else {
repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' ');
}
}
/*
@ -231,6 +235,10 @@ namespace drawtypes {
text = string_util::replace(text, token_str, token.token);
try {
if (token_str[pos + 1] == '-') {
token.rpadding = true;
pos++;
}
token.min = std::stoul(&token_str[pos + 1], nullptr, 10);
// When the number starts with 0 the string is 0-padded
token.zpad = token_str[pos + 1] == '0';