canvas::BoxLayout: set stretch factor by item.
This commit is contained in:
parent
a5e99ea996
commit
9709cfe20d
@ -152,6 +152,24 @@ namespace canvas
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool BoxLayout::setStretchFactor(const LayoutItemRef& item, int stretch)
|
||||||
|
{
|
||||||
|
for( LayoutItems::iterator it = _layout_items.begin();
|
||||||
|
it != _layout_items.end();
|
||||||
|
++it )
|
||||||
|
{
|
||||||
|
if( item == it->layout_item )
|
||||||
|
{
|
||||||
|
it->stretch = std::max(0, stretch);
|
||||||
|
invalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
int BoxLayout::stretch(size_t index) const
|
int BoxLayout::stretch(size_t index) const
|
||||||
{
|
{
|
||||||
|
@ -66,6 +66,14 @@ namespace canvas
|
|||||||
*/
|
*/
|
||||||
void setStretch(size_t index, int stretch);
|
void setStretch(size_t index, int stretch);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the stretch factor of the given @a item to @a stretch, if it exists
|
||||||
|
* in this layout.
|
||||||
|
*
|
||||||
|
* @return true, if the @a item was found in the layout
|
||||||
|
*/
|
||||||
|
bool setStretchFactor(const LayoutItemRef& item, int stretch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the stretch factor of the item at position @a index
|
* Get the stretch factor of the item at position @a index
|
||||||
*/
|
*/
|
||||||
|
@ -216,6 +216,15 @@ BOOST_AUTO_TEST_CASE( horizontal_layout )
|
|||||||
|
|
||||||
BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 125, 32));
|
BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 125, 32));
|
||||||
BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(130, 0, 126, 32));
|
BOOST_CHECK_EQUAL(w2->geometry(), SGRecti(130, 0, 126, 32));
|
||||||
|
|
||||||
|
BOOST_REQUIRE( hbox.setStretchFactor(w1, 2) );
|
||||||
|
BOOST_REQUIRE( hbox.setStretchFactor(w2, 3) );
|
||||||
|
BOOST_CHECK_EQUAL(hbox.stretch(0), 2);
|
||||||
|
BOOST_CHECK_EQUAL(hbox.stretch(1), 3);
|
||||||
|
|
||||||
|
hbox.removeItem(w1);
|
||||||
|
|
||||||
|
BOOST_CHECK( !hbox.setStretchFactor(w1, 0) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user