Fixes empty rows in the MP game list.

Upon removal of games the listbox was not properly updated, the next
call to invalidate_layout() "fixed" the problem. Since the number of
calls to invalidate_layout() is getting lower the issue became more
apparent.
This commit is contained in:
Mark de Wever 2010-02-21 11:05:28 +00:00
parent 47070c9400
commit e6ac5525f2
4 changed files with 86 additions and 1 deletions

View file

@ -22,6 +22,7 @@ Version 1.7.13+svn:
* User interface:
* Rewrote the sizing code of the tree view widget
* Don't show turn dialog once the level has ended
* Fix the empty games in the MP lobby game list
* Miscellaneous and bug fixes:
* Fix bug #15429 (Units created by WML can only get the Neutral alignment)

View file

@ -6,6 +6,8 @@ Version 1.7.13+svn:
* Language and i18n:
* Updated translations: Czech, Italian, Polish.
* User interface:
* The empty spots in the game list in the lobby are gone.
Version 1.7.13-1.8beta6:
* Campaigns:

View file

@ -16,8 +16,12 @@
#include "gui/widgets/listbox.hpp"
#include "gui/auxiliary/log.hpp"
#include "gui/widgets/window.hpp"
#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
namespace gui2 {
namespace {
@ -35,6 +39,7 @@ tlistbox::tlistbox(const bool has_minimum, const bool has_maximum,
, generator_(NULL)
, list_builder_(NULL)
, callback_value_changed_(NULL)
, need_layout_(false)
{
generator_ = tgenerator_::build(
has_minimum, has_maximum, placement, select);
@ -68,11 +73,15 @@ void tlistbox::remove_row(const unsigned row, unsigned count)
count = get_item_count();
}
unsigned height_reduced = 0;
for(; count; --count) {
height_reduced += generator_->item(row).get_height();
generator_->delete_item(row);
}
set_dirty();
if(height_reduced != 0) {
resize_content(0, -height_reduced);
}
}
void tlistbox::clear()
@ -253,6 +262,42 @@ void tlistbox::place(const tpoint& origin, const tpoint& size)
}
}
void tlistbox::resize_content(
const int width_modification
, const int height_modification)
{
DBG_GUI_L << LOG_HEADER << " current size " << content_grid()->get_size()
<< " width_modification " << width_modification
<< " height_modification " << height_modification
<< ".\n";
if(content_resize_request(width_modification, height_modification)) {
// Calculate new size.
tpoint size = content_grid()->get_size();
size.x += width_modification;
size.y += height_modification;
// Set new size.
content_grid()->set_size(size);
// Set status.
need_layout_ = true;
// If the content grows assume it "overwrites" the old content.
if(width_modification < 0 || height_modification < 0) {
set_dirty();
}
DBG_GUI_L << LOG_HEADER << " succeeded.\n";
} else {
DBG_GUI_L << LOG_HEADER << " failed.\n";
}
}
void tlistbox::layout_children()
{
layout_children(false);
}
void tlistbox::child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack)
{
@ -439,6 +484,16 @@ void tlistbox::set_content_size(const tpoint& origin, const tpoint& size)
content_grid()->place(origin, s);
}
void tlistbox::layout_children(const bool force)
{
if(need_layout_ || force) {
content_grid()->place(
content_grid()->get_origin()
, content_grid()->get_size());
need_layout_ = false;
}
}
const std::string& tlistbox::get_control_type() const
{
static const std::string type = "listbox";

View file

@ -197,6 +197,9 @@ public:
/** Inherited from tscrollbar_container. */
void place(const tpoint& origin, const tpoint& size);
/** Inherited from tscrollbar_container. */
void layout_children();
/** Inherited from tscrollbar_container. */
void child_populate_dirty_list(twindow& caller,
const std::vector<twidget*>& call_stack);
@ -274,6 +277,30 @@ private:
*/
void (*callback_value_changed_) (twidget*);
bool need_layout_;
/**
* Resizes the content.
*
* The resize either happens due to resizing the content or invalidate the
* layout of the window.
*
* @param width_modification The wanted modification to the width:
* * negative values reduce width.
* * zero leave width as is.
* * positive values increase width.
* @param height_modification The wanted modification to the height:
* * negative values reduce height.
* * zero leave height as is.
* * positive values increase height.
*/
void resize_content(
const int width_modification
, const int height_modification);
/** Layouts the children if needed. */
void layout_children(const bool force);
/** Inherited from tscrollbar_container. */
virtual void set_content_size(const tpoint& origin, const tpoint& size);