BOOST_CHECK_EQUAL(w1->geometry(), SGRecti(0, 0, 125, 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) );
}
}
//------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE( boxlayout_insert_remove )
{
- sc::HBoxLayout hbox;
+ sc::BoxLayoutRef hbox( new sc::HBoxLayout );
- BOOST_CHECK_EQUAL(hbox.count(), 0);
- BOOST_CHECK(!hbox.itemAt(0));
- BOOST_CHECK(!hbox.takeAt(0));
+ BOOST_CHECK_EQUAL(hbox->count(), 0);
+ BOOST_CHECK(!hbox->itemAt(0));
+ BOOST_CHECK(!hbox->takeAt(0));
TestWidgetRef w1( new TestWidget( SGVec2i(16, 16),
SGVec2i(32, 32),
SGVec2i(9999, 32) ) ),
w2( new TestWidget(*w1) );
- hbox.addItem(w1);
- BOOST_CHECK_EQUAL(hbox.count(), 1);
- BOOST_CHECK_EQUAL(hbox.itemAt(0), w1);
-
- hbox.insertItem(0, w2);
- BOOST_CHECK_EQUAL(hbox.count(), 2);
- BOOST_CHECK_EQUAL(hbox.itemAt(0), w2);
- BOOST_CHECK_EQUAL(hbox.itemAt(1), w1);
-
- hbox.removeItem(w2);
- BOOST_CHECK_EQUAL(hbox.count(), 1);
- BOOST_CHECK_EQUAL(hbox.itemAt(0), w1);
-
- hbox.addItem(w2);
- BOOST_CHECK_EQUAL(hbox.count(), 2);
-
- hbox.clear();
- BOOST_CHECK_EQUAL(hbox.count(), 0);
+ hbox->addItem(w1);
+ BOOST_CHECK_EQUAL(hbox->count(), 1);
+ BOOST_CHECK_EQUAL(hbox->itemAt(0), w1);
+ BOOST_CHECK_EQUAL(w1->getParent(), hbox);
+
+ hbox->insertItem(0, w2);
+ BOOST_CHECK_EQUAL(hbox->count(), 2);
+ BOOST_CHECK_EQUAL(hbox->itemAt(0), w2);
+ BOOST_CHECK_EQUAL(hbox->itemAt(1), w1);
+ BOOST_CHECK_EQUAL(w2->getParent(), hbox);
+
+ hbox->removeItem(w2);
+ BOOST_CHECK_EQUAL(hbox->count(), 1);
+ BOOST_CHECK_EQUAL(hbox->itemAt(0), w1);
+ BOOST_CHECK( !w2->getParent() );
+
+ hbox->addItem(w2);
+ BOOST_CHECK_EQUAL(hbox->count(), 2);
+ BOOST_CHECK_EQUAL(w2->getParent(), hbox);
+
+ hbox->clear();
+ BOOST_CHECK_EQUAL(hbox->count(), 0);
+ BOOST_CHECK( !w1->getParent() );
+ BOOST_CHECK( !w2->getParent() );
}
//------------------------------------------------------------------------------
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));
}
//------------------------------------------------------------------------------
-BOOST_AUTO_TEST_CASE( nasal_layout )
+BOOST_AUTO_TEST_CASE( nasal_widget )
{
naContext c = naNewContext();
naRef me = naNewHash(c);
- sc::LayoutItemRef nasal_item( new sc::NasalWidget(me) );
+ sc::NasalWidgetRef w( new sc::NasalWidget(me) );
+
+ // Default layout sizes (no user set values)
+ BOOST_CHECK_EQUAL(w->minimumSize(), SGVec2i(16, 16));
+ BOOST_CHECK_EQUAL(w->sizeHint(), SGVec2i(32, 32));
+ BOOST_CHECK_EQUAL(w->maximumSize(), sc::LayoutItem::MAX_SIZE);
+
+ // Changed layout sizes
+ w->setLayoutMinimumSize( SGVec2i(2, 12) );
+ w->setLayoutSizeHint( SGVec2i(3, 13) );
+ w->setLayoutMaximumSize( SGVec2i(4, 14) );
+
+ BOOST_CHECK_EQUAL(w->minimumSize(), SGVec2i(2, 12));
+ BOOST_CHECK_EQUAL(w->sizeHint(), SGVec2i(3, 13));
+ BOOST_CHECK_EQUAL(w->maximumSize(), SGVec2i(4, 14));
+
+ // User set values (overwrite layout sizes)
+ w->setMinimumSize( SGVec2i(15, 16) );
+ w->setSizeHint( SGVec2i(17, 18) );
+ w->setMaximumSize( SGVec2i(19, 20) );
+
+ BOOST_CHECK_EQUAL(w->minimumSize(), SGVec2i(15, 16));
+ BOOST_CHECK_EQUAL(w->sizeHint(), SGVec2i(17, 18));
+ BOOST_CHECK_EQUAL(w->maximumSize(), SGVec2i(19, 20));
+
+ // Only vertical user set values (layout/default for horizontal hints)
+ w->setMinimumSize( SGVec2i(0, 21) );
+ w->setSizeHint( SGVec2i(0, 22) );
+ w->setMaximumSize( SGVec2i(SGLimits<int>::max(), 23) );
+
+ BOOST_CHECK_EQUAL(w->minimumSize(), SGVec2i(2, 21));
+ BOOST_CHECK_EQUAL(w->sizeHint(), SGVec2i(3, 22));
+ BOOST_CHECK_EQUAL(w->maximumSize(), SGVec2i(4, 23));
naFreeContext(c);
}