2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/internal/layouting/grid-locations.h>
21 #include <dali/integration-api/debug.h>
24 #include <dali-toolkit/devel-api/layouting/layout-item.h>
29 #if defined(DEBUG_ENABLED)
30 static Debug::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_AXIS" );
42 GridLocationsPtr GridLocations::New()
44 GridLocationsPtr gridAxis( new GridLocations() );
48 GridLocations::GridLocations()
53 GridLocations::~GridLocations(){}
55 void GridLocations::CalculateLocations( int numberOfColumns,
56 unsigned int availableWidth,
57 unsigned int availableHeight,
58 unsigned int numberOfCells,
59 unsigned int columnWidth,
60 unsigned int rowHeight )
64 // Calculate width and height of columns and rows.
66 // Calculate numbers of rows, round down result as later check for remainder.
67 unsigned int numberOfRows = numberOfCells/numberOfColumns;
68 // If number of cells not cleanly dividable by colums, add another row to house remainder cells.
69 numberOfRows += (numberOfCells%numberOfColumns)?1:0;
71 unsigned int maxColumnWidth = availableWidth / numberOfColumns;
75 // Column width supplied so use this unless exceeds available width.
76 columnWidth = std::min( columnWidth, maxColumnWidth );
80 // Column width not supplied so use calculated value
81 columnWidth = maxColumnWidth;
84 unsigned int maxRowHeight = availableHeight / numberOfRows;
88 // Column height supplied so use this unless exceeds available height.
89 rowHeight = std::min( rowHeight, maxRowHeight );
93 // Column height not supplied so use calculated value
94 rowHeight = maxRowHeight;
97 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "ColumWidth[%d] RowHeight[%d] NumberOfRows[%d] NumberOfColumns[%d]\n",
98 columnWidth, rowHeight, numberOfRows, numberOfColumns );
99 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Remainder[%d]\n", numberOfCells%numberOfColumns );
102 int y2 = y1 + rowHeight;
104 // Calculate start, end, top and bottom coordinate of each cell.
107 for( auto i = 0u; i < numberOfRows; i++ )
110 int x2 = x1 + columnWidth;
113 for( auto j = 0; j < numberOfColumns; j++ )
115 GridLocations::Cell cell( x1, x2, y1, y2 );
116 mLocations.push_back( cell );
117 // Calculate starting x and ending x position of each column
119 x2 = x2 + columnWidth;
122 // Calculate top y and bottom y position of each row.
127 #if defined(DEBUG_ENABLED)
128 std::ostringstream oss;
129 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GridLocations::CalculateLocations (%d)\n", numberOfCells );
130 for( auto i = 0u; i < numberOfCells; i++ )
132 DALI_LOG_STREAM( gLogFilter, Debug::Verbose,"x1:"<<mLocations[i].xStart<<" x2:"<<mLocations[i].xEnd<<" y1:"<<mLocations[i].yTop<<" y2:"<<mLocations[i].yBottom);
137 GridLocations::LocationVector GridLocations::GetLocations()
139 #if defined(DEBUG_ENABLED)
140 std::ostringstream oss;
141 auto itemCount = mLocations.size(); // mVerticalLocations mirrors this so same size.
142 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GridLocations::GetLocations for %u cells\n", itemCount );
143 for( auto i = 0u; i < itemCount; i++ )
145 DALI_LOG_STREAM( gLogFilter, Debug::Verbose,"x1:"<<mLocations[i].xStart<<" x2:"<<mLocations[i].xEnd<<" y1:"<<mLocations[i].yTop<<" y2:"<<mLocations[i].yBottom);
152 } // namespace Internal
154 } // namespace Toolkit