Fixed a couple weird bugs in ScrollAdapterBase that could cause redraw

issues when switching between non-empty and empty lists.
This commit is contained in:
casey langen 2020-04-11 00:45:37 -07:00
parent 528597bf5f
commit 16895eaa1d

View File

@ -112,20 +112,23 @@ size_t ScrollAdapterBase::GetVisibleItems(
void ScrollAdapterBase::DrawPage(ScrollableWindow* scrollable, size_t index, ScrollPosition& result) {
WINDOW* window = scrollable->GetContent();
if (!scrollable->IsVisible() || !window || this->height == 0 || this->width == 0 || this->GetEntryCount() == 0) {
if (!scrollable->IsVisible() || !window || this->height == 0 || this->width == 0) {
return;
}
werase(window);
if (index >= GetEntryCount()) {
index = GetEntryCount() - 1;
std::deque<EntryPtr> visible;
size_t drawnLines = 0;
size_t topIndex = 0;
size_t count = GetEntryCount();
if (count > 0) {
if (index >= count) {
index = count - 1;
}
std::deque<EntryPtr> visible;
size_t topIndex = GetVisibleItems(scrollable, index, visible);
size_t drawnLines = 0;
topIndex = GetVisibleItems(scrollable, index, visible);
for (size_t e = 0; e < visible.size(); e++) {
EntryPtr entry = visible.at(e);
@ -168,9 +171,10 @@ void ScrollAdapterBase::DrawPage(ScrollableWindow* scrollable, size_t index, Scr
++drawnLines;
}
}
}
result.visibleEntryCount = visible.size();
result.firstVisibleEntryIndex = topIndex;
result.lineCount = drawnLines;
result.totalEntries = GetEntryCount();
result.totalEntries = count;
}