Skip to content

Commit

Permalink
change rendering of last page of wmi's, to prevent menu resize
Browse files Browse the repository at this point in the history
This commit makes the pager just show enough entries from the
previous page to ensure that we have a full page. When the number
of displayed entries is large, if we don't do this then the menu
can resize dramatically which is a bit jarring.
  • Loading branch information
cbeck88 committed Jun 29, 2014
1 parent fe3b5f4 commit 75f5076
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/wmi_pager.cpp
Expand Up @@ -120,15 +120,19 @@ void wmi_pager::get_items(const map_location& hex,
}
// ^ This loop terminates with first_displayed_index > 0, because foo_->size() > page_size or else we exited earlier, and we only decrease by (page_size-2) each time.

wmi_it start_range = foo_->begin();
std::advance(start_range, first_displayed_index); // <-- get an iterator to the start of our range. begin() + n doesn't work because map is not random access
//^ = foo_->begin() + first_displayed_index

if (first_displayed_index + page_size-1 >= foo_->size()) //if this can be the last page, then we won't put next page at the bottom.
{
foo_->get_items(hex, items, descriptions, start_range, foo_->end()); // display all of the remaining items
//The last page we treat differently -- we always want to display (page_size) entries, to prevent resizing the context menu, so count back from end.
wmi_it end_range = foo_->end(); // It doesn't really matter if we display some entries that appeared on the previous page by doing this.
wmi_it start_range = end_range;
std::advance(start_range, -(page_size-1));

foo_->get_items(hex, items, descriptions, start_range, end_range); // display all of the remaining items
return;
} else { //we are in a middle page
wmi_it start_range = foo_->begin();
std::advance(start_range, first_displayed_index); // <-- get an iterator to the start of our range. begin() + n doesn't work because map is not random access

wmi_it end_range = start_range;
std::advance(end_range, page_size-2);

Expand Down

0 comments on commit 75f5076

Please sign in to comment.