Let listboxs update its contents when adding rows.
Before only remove reduced the size, now the adding also updates contents. This should reduce the number of layout updates.
This commit is contained in:
parent
ce773892a1
commit
1be5aebc28
3 changed files with 36 additions and 2 deletions
|
@ -55,6 +55,7 @@ Version 1.13.0-dev:
|
|||
* Made orb and minmap colors configurable by the game preferences.
|
||||
* Remove 'allow_new_game=no' entries from random map new game list
|
||||
* Fixed bug #22095: An assertion failure in the gamestate inspector.
|
||||
* Changed: A listbox can now update its size when rows are added.
|
||||
* WML engine:
|
||||
* Added customizable recall costs for unit types and individual units,
|
||||
using the new recall_cost attribute in [unit_type] and [unit].
|
||||
|
|
|
@ -66,8 +66,10 @@ tlistbox::tlistbox(const bool has_minimum,
|
|||
void tlistbox::add_row(const string_map& item, const int index)
|
||||
{
|
||||
assert(generator_);
|
||||
generator_->create_item(
|
||||
const tgrid& row = generator_->create_item(
|
||||
index, list_builder_, item, callback_list_item_clicked);
|
||||
|
||||
resize_content(row);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -75,8 +77,10 @@ tlistbox::add_row(const std::map<std::string /* widget id */, string_map>& data,
|
|||
const int index)
|
||||
{
|
||||
assert(generator_);
|
||||
generator_->create_item(
|
||||
const tgrid& row = generator_->create_item(
|
||||
index, list_builder_, data, callback_list_item_clicked);
|
||||
|
||||
resize_content(row);
|
||||
}
|
||||
|
||||
void tlistbox::remove_row(const unsigned row, unsigned count)
|
||||
|
@ -315,6 +319,26 @@ void tlistbox::resize_content(const int width_modification,
|
|||
}
|
||||
}
|
||||
|
||||
void tlistbox::resize_content(const twidget& row)
|
||||
{
|
||||
if(row.get_visible() == tvisible::invisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBG_GUI_L << LOG_HEADER << " current size " << content_grid()->get_size()
|
||||
<< " row size " << row.get_best_size() << ".\n";
|
||||
|
||||
const tpoint content = content_grid()->get_size();
|
||||
tpoint size = row.get_best_size();
|
||||
if(size.x < content.x) {
|
||||
size.x = 0;
|
||||
} else {
|
||||
size.x -= content.x;
|
||||
}
|
||||
|
||||
resize_content(size.x, size.y);
|
||||
}
|
||||
|
||||
void tlistbox::layout_children()
|
||||
{
|
||||
layout_children(false);
|
||||
|
|
|
@ -303,6 +303,15 @@ private:
|
|||
void resize_content(const int width_modification,
|
||||
const int height_modification);
|
||||
|
||||
/**
|
||||
* Resizes the content.
|
||||
*
|
||||
* The resize happens when a new row is added to the contents.
|
||||
*
|
||||
* @param row The new row added to the listbox.
|
||||
*/
|
||||
void resize_content(const twidget& row);
|
||||
|
||||
/** Layouts the children if needed. */
|
||||
void layout_children(const bool force);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue