Tree View Node: don't add unnecessary widget height when adding child nodes

Now extra height is only added if the new best height (height with new node) exceeds the current height.
This should prevent the scrollbar from appearing even when it's obviously not needed.
This commit is contained in:
Charles Dang 2016-11-03 04:18:58 +11:00
parent d01bc02d56
commit 7fdb2c5092
2 changed files with 14 additions and 5 deletions

View file

@ -661,7 +661,9 @@ bool tscrollbar_container::content_resize_width(const int width_modification, co
DBG_GUI_L << LOG_HEADER << " current width " << content_grid_->get_width()
<< " wanted width " << new_width;
assert(new_width >= 0);
if(new_width < 0) {
return false;
}
if(static_cast<unsigned>(new_width) <= content_->get_width()) {
DBG_GUI_L << " width fits in container, test height.\n";
@ -711,7 +713,9 @@ bool tscrollbar_container::content_resize_height(const int height_modification,
DBG_GUI_L << LOG_HEADER << " current height " << content_grid_->get_height()
<< " wanted height " << new_height;
assert(new_height >= 0);
if(new_height < 0) {
return false;
}
if(static_cast<unsigned>(new_height) <= content_->get_height()) {
DBG_GUI_L << " height in container, resize allowed.\n";

View file

@ -152,15 +152,20 @@ ttree_view_node& ttree_view_node::add_child(
}
assert(tree_view().content_grid());
const int current_width = tree_view().content_grid()->get_width();
const tpoint current_size = tree_view().content_grid()->get_size();
// Calculate width modification.
// This increases tree width if the width of the new node is greater than the current width.
tpoint best_size = itor->get_best_size();
best_size.x += get_indentation_level() * tree_view().indentation_step_size_;
const unsigned width_modification = best_size.x > current_width ? best_size.x - current_width : 0;
const int width_modification = best_size.x > current_size.x ? best_size.x - current_size.x : 0;
// Calculate height modification.
const int height_modification = best_size.y;
// For this, we only increase height if the best size of the tree (that is, the size with the new node)
// is larger than its current size. This prevents the scrollbar being reserved even when there's obviously
// enough visual space.
const tpoint tree_best_size = tree_view().get_best_size();
const int height_modification = tree_best_size.y > current_size.y ? tree_best_size.y - current_size.y : 0;
assert(height_modification >= 0);
// Request new size.