fix(builder): Respect label-ellipsis option
This slightly changes the existing behavior of maxlen. Before with a maxlen of 4 'abcde' used to yield 'abcd...' now it yields 'a...'
This commit is contained in:
parent
973f925ad7
commit
7dc42f543f
@ -555,8 +555,21 @@ string builder::foreground_hex() {
|
|||||||
string builder::get_label_text(const label_t& label) {
|
string builder::get_label_text(const label_t& label) {
|
||||||
string text{label->get()};
|
string text{label->get()};
|
||||||
|
|
||||||
if (label->m_maxlen > 0 && string_util::char_len(text) > label->m_maxlen) {
|
size_t maxlen = label->m_maxlen;
|
||||||
text = string_util::utf8_truncate(std::move(text), label->m_maxlen) + "...";
|
|
||||||
|
if (maxlen > 0 && string_util::char_len(text) > maxlen ) {
|
||||||
|
if(label->m_ellipsis) {
|
||||||
|
if(maxlen < 3) {
|
||||||
|
throw application_error(sstream()
|
||||||
|
<< "Label has maxlen (" << maxlen
|
||||||
|
<< ") that is smaller than size of ellipsis(3)");
|
||||||
|
}
|
||||||
|
|
||||||
|
text = string_util::utf8_truncate(std::move(text), maxlen - 3) + "...";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
text = string_util::utf8_truncate(std::move(text), maxlen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
|
@ -44,6 +44,7 @@ class GetLabelTextTest :
|
|||||||
|
|
||||||
vector<pair<string, tuple<string, bool, int>>> get_label_text_list = {
|
vector<pair<string, tuple<string, bool, int>>> get_label_text_list = {
|
||||||
{"...", make_tuple("abcd", true, 3)},
|
{"...", make_tuple("abcd", true, 3)},
|
||||||
|
{"abc", make_tuple("abc", true, 3)},
|
||||||
{"abc", make_tuple("abcdefgh", false, 3)},
|
{"abc", make_tuple("abcdefgh", false, 3)},
|
||||||
{"a...", make_tuple("abcdefgh", true, 4)},
|
{"a...", make_tuple("abcdefgh", true, 4)},
|
||||||
{"abcd...", make_tuple("abcdefgh", true, 7)},
|
{"abcd...", make_tuple("abcdefgh", true, 7)},
|
||||||
|
Loading…
Reference in New Issue
Block a user