Updated ShortcutsWindow to properly ellipsize contents.

This commit is contained in:
Casey Langen 2016-07-08 20:39:13 -07:00
parent 65203c8fbc
commit a3c7a76b75

View File

@ -70,16 +70,45 @@ void ShortcutsWindow::Repaint() {
WINDOW* c = this->GetContent(); WINDOW* c = this->GetContent();
for (size_t i = 0; i < this->entries.size(); i++) { size_t remaining = this->GetContentWidth();
for (size_t i = 0; i < this->entries.size() && remaining > 0; i++) {
auto e = this->entries[i]; auto e = this->entries[i];
int64 keyAttrs = (e->key == this->activeKey) ? activeAttrs : normalAttrs; int64 keyAttrs = (e->key == this->activeKey) ? activeAttrs : normalAttrs;
wprintw(c, " "); wprintw(c, " ");
--remaining;
if (remaining == 0) {
continue;
}
std::string key = " " + e->key + " ";
std::string value = " " + e->description + " ";
size_t len = u8cols(key);
if (len > remaining) {
key = text::Ellipsize(key, remaining);
len = remaining;
}
wattron(c, keyAttrs); wattron(c, keyAttrs);
wprintw(c, " %s ", e->key.c_str()); wprintw(c, key.c_str());
wattroff(c, keyAttrs); wattroff(c, keyAttrs);
wprintw(c, " %s ", e->description.c_str()); remaining -= len;
if (remaining == 0) {
continue;
}
len = u8cols(value);
if (len > remaining) {
value = text::Ellipsize(value, remaining);
len = remaining;
}
wprintw(c, value.c_str());
remaining -= len;
} }
} }