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:
parent
6ccecbfca2
commit
7838241a77
@ -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))
|
||||
|
@ -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 {
|
||||
|
@ -86,8 +86,12 @@ 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) {
|
||||
if (tok.rpadding) {
|
||||
repl.append(tok.min - repl.length(), ' ');
|
||||
} else {
|
||||
repl.insert(0_z, tok.min - repl.length(), tok.zpad ? '0' : ' ');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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';
|
||||
|
Loading…
Reference in New Issue
Block a user