Add an overload for set_row_shown.

Hiding one row at a time in the game_load dialog, when the filter
resulted in an empty set was slow. Every time a row was hidden the next
row was selected and its callback called. Directly after that the newly
selected row was hidden as well... The speedup is quite noticable.
This commit is contained in:
Mark de Wever 2009-12-20 20:46:35 +00:00
parent 39946e74aa
commit 866b6a8844
3 changed files with 46 additions and 0 deletions

View file

@ -10,6 +10,7 @@ Version 1.7.10+svn:
* Allow a gui2 timer delete itself in its callback
* Fix various bugs when a unit has more MP than its maximum
* Fix not redrawing a grid when set to hidden
* Add helper functions to show/hide rows in a listbox
Version 1.7.10-1.8beta3:
* Campaigns:

View file

@ -119,6 +119,37 @@ void tlistbox::set_row_shown(const unsigned row, const bool shown)
}
}
void tlistbox::set_row_shown(const std::vector<bool>& shown)
{
assert(generator_);
assert(shown.size() == get_item_count());
twindow *window = get_window();
assert(window);
const int selected_row = get_selected_row();
bool resize_needed;
{
twindow::tinvalidate_layout_blocker invalidate_layout_blocker(*window);
for(size_t i = 0; i < shown.size(); ++i) {
generator_->set_item_shown(i, shown[i]);
}
resize_needed = !content_resize_request();
}
if(resize_needed) {
window->invalidate_layout();
} else {
set_dirty();
}
if(selected_row != get_selected_row() && callback_value_changed_) {
callback_value_changed_(this);
}
}
const tgrid* tlistbox::get_row_grid(const unsigned row) const
{
assert(generator_);

View file

@ -107,6 +107,20 @@ public:
*/
void set_row_shown(const unsigned row, const bool shown);
/**
* Makes a row visible or invisible.
*
* Use this version if you want to show hide multiple items since it's
* optimized for that purpose, for one it calls the selection changed
* callback only once instead of serveral times.
*
* @param shown A vector with the show hide status for every
* row. The number of items in the vector must
* be equal to the number of items in the
* listbox.
*/
void set_row_shown(const std::vector<bool>& shown);
/**
* Returns the grid of the wanted row.
*