test_return_value = TET_PASS;
}
+int UtcDaliLayouting_GridLayout00(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline(" UtcDaliLayouting_GridLayout00 1 Column, 0 Items");
+
+ const auto NUMBER_OF_COLUMNS = 1;
+ const auto NUMBER_OF_ITEMS = 0;
+
+ tet_printf( "Testing %d columns with %d items\n", NUMBER_OF_COLUMNS, NUMBER_OF_ITEMS );
+
+ Stage stage = Stage::GetCurrent();
+
+ auto rootControl = Control::New();
+ auto absoluteLayout = AbsoluteLayout::New();
+ DevelControl::SetLayout( rootControl, absoluteLayout );
+ rootControl.SetName( "AbsoluteLayout" );
+ stage.Add( rootControl );
+
+ auto gridContainer = Control::New();
+ auto gridLayout = Grid::New();
+ gridLayout.SetNumberOfColumns( NUMBER_OF_COLUMNS );
+ gridContainer.SetName( "GridLayout");
+ DevelControl::SetLayout( gridContainer, gridLayout );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+ gridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+
+ rootControl.Add( gridContainer );
+
+ // Ensure layouting happens
+ application.SendNotification();
+ application.Render();
+
+ tet_printf( "Confirm number of columns is as set\n");
+ DALI_TEST_EQUALS( gridLayout.GetNumberOfColumns(), NUMBER_OF_COLUMNS, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliLayouting_GridLayout01(void)
{
ToolkitTestApplication application;
DALI_TEST_CHECK( gridLayoutCandidate );
END_TEST;
-}
\ No newline at end of file
+}
DetermineNumberOfColumns( availableContentWidth );
// Locations define the start, end,top and bottom of each cell.
- mLocations->CalculateLocations( mNumColumns, availableContentWidth.AsInteger(), availableContentHeight.AsInteger(), childCount, 0, 0 );
+ mLocations->CalculateLocations( mNumColumns, availableContentWidth.AsInteger(), availableContentHeight.AsInteger(), childCount );
SetMeasuredDimensions( ResolveSizeAndState( widthSize, widthMeasureSpec, MeasuredSize::State::MEASURED_SIZE_OK ),
void GridLocations::CalculateLocations( int numberOfColumns,
unsigned int availableWidth,
unsigned int availableHeight,
- unsigned int numberOfCells,
- unsigned int columnWidth,
- unsigned int rowHeight )
+ unsigned int numberOfCells )
{
DALI_ASSERT_DEBUG( numberOfColumns > 0 && "number of columns should be greater than 0" );
numberOfColumns = std::max ( numberOfColumns, 1 );
// If number of cells not cleanly dividable by colums, add another row to house remainder cells.
numberOfRows += (numberOfCells%numberOfColumns)?1:0;
- unsigned int maxColumnWidth = availableWidth / numberOfColumns;
+ // Safe as numberOfColumns is guaranteed to be > 0
+ unsigned int columnWidth = availableWidth / numberOfColumns;
- if( columnWidth > 0 )
- {
- // Column width supplied so use this unless exceeds available width.
- columnWidth = std::min( columnWidth, maxColumnWidth );
- }
- else
- {
- // Column width not supplied so use calculated value
- columnWidth = maxColumnWidth;
- }
+ unsigned int rowHeight = availableHeight;
- unsigned int maxRowHeight = availableHeight / numberOfRows;
-
- if( rowHeight > 0 )
- {
- // Column height supplied so use this unless exceeds available height.
- rowHeight = std::min( rowHeight, maxRowHeight );
- }
- else
+ if( numberOfRows > 0 )
{
- // Column height not supplied so use calculated value
- rowHeight = maxRowHeight;
+ rowHeight = availableHeight / numberOfRows;
}
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ColumWidth[%d] RowHeight[%d] NumberOfRows[%d] NumberOfColumns[%d]\n",
} // namespace Internal
} // namespace Toolkit
-} // namespace Dali
\ No newline at end of file
+} // namespace Dali
* Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
*/
void CalculateLocations( int numberOfColumns, unsigned int availableWidth,
- unsigned int availableHeight, unsigned int numberOfCells,
- unsigned int columnWidth, unsigned int rowHeight );
+ unsigned int availableHeight, unsigned int numberOfCells );
LocationVector GetLocations();
} // namespace Toolkit
} // namespace Dali
-#endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_LOCATIONS_H
\ No newline at end of file
+#endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_LOCATIONS_H