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 ### 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/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)) - `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 ### 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)) - 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}; size_t max{0_z};
string suffix{""s}; string suffix{""s};
bool zpad{false}; bool zpad{false};
bool rpadding{false};
}; };
class label : public non_copyable_mixin { class label : public non_copyable_mixin {

View File

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