Make the selected item visible in listbox::layout_children()

The biggest change from this is that list boxes now keep the selected item
visible when you change the sorting option.

This change also keeps an add-on visible in the new add-on manager after
installing it, which is why I made this change in the first place.
This commit is contained in:
Jyrki Vesterinen 2017-01-19 21:24:57 +02:00
parent 801ef5ab2d
commit 4d65344986
3 changed files with 21 additions and 1 deletions

View file

@ -28,6 +28,9 @@ Version 1.13.6+dev:
* Lua API:
* New attributes in side proxy:
num_units, num_villages, total_upkeep, expenses, net_income
* User Interface:
* List boxes now keep the selected item visible when you change the sorting
option.
* Wesnoth Formula Engine:
* New str_upper and str_lower functions for case transformations
* WML Engine:

View file

@ -24,6 +24,10 @@ Version 1.13.6+dev:
* Language and i18n:
* Updated translations: British English, Czech, German, Portuguese (Brazil).
* User Interface:
* List boxes now keep the selected item visible when you change the sorting
option.
* Miscellaneous and bug fixes:
* Fixed severe lag/freeze on slow PCs (bug #25356)

View file

@ -690,10 +690,23 @@ void listbox::layout_children(const bool force)
assert(content_grid());
if(need_layout_ || force) {
const int selected_item = generator_->get_selected_item();
content_grid()->place(content_grid()->get_origin(),
content_grid()->get_size());
content_grid()->set_visible_rectangle(content_visible_area_);
const SDL_Rect& visible = content_visible_area_;
content_grid()->set_visible_rectangle(visible);
if(selected_item != -1) {
SDL_Rect rect = generator_->item(selected_item).get_rectangle();
rect.x = visible.x;
rect.w = visible.w;
show_content_rect(rect);
}
need_layout_ = false;
set_is_dirty(true);