Skip to content

Commit

Permalink
fix assertion failues on remove_row() for horizontal listboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Mar 22, 2016
1 parent bbc9569 commit f759649
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/gui/widgets/listbox.cpp
Expand Up @@ -62,8 +62,8 @@ tlistbox::tlistbox(const bool has_minimum,
const tgenerator_::tplacement placement,
const bool select)
: tscrollbar_container(2) // FIXME magic number
, generator_(
tgenerator_::build(has_minimum, has_maximum, placement, select))
, generator_(tgenerator_::build(has_minimum, has_maximum, placement, select))
, is_horizonal_(placement == tgenerator_::horizontal_list)
, list_builder_(NULL)
, callback_value_changed_(NULL)
, need_layout_(false)
Expand Down Expand Up @@ -104,18 +104,25 @@ void tlistbox::remove_row(const unsigned row, unsigned count)
}

int height_reduced = 0;
int width_reduced = 0;
//TODO: Fix this for horizinal listboxes
//Note the we have to use content_grid_ and cannot use "_list_grid" which is what generator_ uses.
int row_pos = generator_->item(row).get_y() - content_grid_->get_y();
int row_pos_y = is_horizonal_ ? -1 : generator_->item(row).get_y() - content_grid_->get_y();
int row_pos_x = is_horizonal_ ? -1 : 0;
for(; count; --count) {
if(generator_->item(row).get_visible() != tvisible::invisible) {
height_reduced += generator_->item(row).get_height();
if(is_horizonal_) {
width_reduced += generator_->item(row).get_width();
}
else {
height_reduced += generator_->item(row).get_height();
}
}
generator_->delete_item(row);
}

if(height_reduced != 0 && get_item_count() != 0) {
resize_content(0, -height_reduced, 0, row_pos);
if((height_reduced != 0 || width_reduced != 0) && get_item_count() != 0) {
resize_content(-width_reduced, -height_reduced, row_pos_x, row_pos_y);
} else {
update_content_size();
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/widgets/listbox.hpp
Expand Up @@ -285,6 +285,8 @@ class tlistbox : public tscrollbar_container
*/
tgenerator_* generator_;

const bool is_horizonal_;

/** Contains the builder for the new items. */
tbuilder_grid_const_ptr list_builder_;

Expand Down

0 comments on commit f759649

Please sign in to comment.