canvas::BoxLayout: fix hfw layouting (fix updating size hint cache).

This commit is contained in:
Thomas Geymayer
2014-06-28 13:08:06 +02:00
parent 10d0be013e
commit 38b766f845
4 changed files with 30 additions and 15 deletions

View File

@@ -394,13 +394,16 @@ namespace canvas
data.layout_item->minimumSize().x(),
data.layout_item->maximumSize().x() );
int d = data.layout_item->minimumHeightForWidth(w) - data.min_size;
data.min_size += d;
_layout_data.min_size += d;
data.min_size = data.mhfw(w);
data.size_hint = data.hfw(w);
d = data.layout_item->heightForWidth(w) - data.size_hint;
data.size_hint += d;
_layout_data.size_hint += d;
// Update size hints for layouting with difference to size hints
// calculated by using the size hints provided (without trading
// height for width)
_layout_data.min_size += data.min_size
- data.layout_item->minimumSize().y();
_layout_data.size_hint += data.size_hint
- data.layout_item->sizeHint().y();
}
}
}

View File

@@ -124,7 +124,11 @@ namespace canvas
SG_LOG( SG_GUI,
SG_DEBUG,
"Layout::distribute(" << num_children << " items)" );
"Layout::distribute(" << space.size << "px for "
<< num_children << " items, s.t."
<< " min=" << space.min_size
<< ", hint=" << space.size_hint
<< ", max=" << space.max_size << ")" );
if( space.size < space.min_size )
{

View File

@@ -108,14 +108,14 @@ namespace canvas
void NasalWidget::setHeightForWidthFunc(const HeightForWidthFunc& func)
{
_height_for_width = func;
invalidateParent();
invalidate();
}
//----------------------------------------------------------------------------
void NasalWidget::setMinimumHeightForWidthFunc(const HeightForWidthFunc& func)
{
_min_height_for_width = func;
invalidateParent();
invalidate();
}
//----------------------------------------------------------------------------
@@ -127,7 +127,7 @@ namespace canvas
_size_hint = s;
// TODO just invalidate size_hint? Probably not a performance issue...
invalidateParent();
invalidate();
}
//----------------------------------------------------------------------------
@@ -137,7 +137,7 @@ namespace canvas
return;
_min_size = s;
invalidateParent();
invalidate();
}
//----------------------------------------------------------------------------
@@ -147,7 +147,7 @@ namespace canvas
return;
_max_size = s;
invalidateParent();
invalidate();
}
//----------------------------------------------------------------------------

View File

@@ -395,9 +395,17 @@ BOOST_AUTO_TEST_CASE( boxlayout_hfw )
vbox.setGeometry(SGRecti(0, 0, 50, 122));
BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 50, 44));
BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 49, 50, 70));
BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 124, 50, 56));
BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 50, 25));
BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 30, 50, 51));
BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 86, 50, 36));
// Same geometry as before -> should get same widget geometry
// (check internal size hint cache updates correctly)
vbox.setGeometry(SGRecti(0, 0, 24, 122));
BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 24, 33));
BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(0, 38, 24, 47));
BOOST_CHECK_EQUAL(w_no_hfw->geometry(), SGRecti(0, 90, 24, 32));
}
//------------------------------------------------------------------------------