Control impl layout code for Margin removed
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / grid-locations.h
1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_LOCATIONS_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_LOCATIONS_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 //EXTERNAL HEADERS
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <limits.h>
25
26 // INTERNAL HEADERS
27 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35
36 class GridLocations;
37 using GridLocationsPtr = IntrusivePtr<GridLocations>;
38
39 /* @brief This internal class houses the algorithm for computing the locations and size of cells.
40  *
41  * A Grid layout uses two instances of this class
42  * distinguished by the "horizontal" flag which is true for the horizontal axis and false
43  * for the vertical one.
44  */
45
46 class GridLocations : public RefObject
47 {
48
49 public:
50
51   static const int UNDEFINED = INT_MIN;
52
53   static const unsigned int HORIZONTAL = 0;
54   static const unsigned int VERTICAL = 1;
55
56   struct Cell
57   {
58     int xStart;
59     int xEnd;
60     int yTop;
61     int yBottom;
62
63     Cell( int x1, int x2, int y1, int y2): xStart(x1), xEnd(x2), yTop(y1), yBottom(y2){};
64   };
65
66   typedef std::vector< Cell > LocationVector;
67
68 public:
69
70   static GridLocationsPtr New();
71
72   /*
73    * Uses the given parameters to calculate the x,y coordinates of each cell and cell size.
74    */
75   void CalculateLocations( int numberOfColumns, unsigned int availableWidth,
76                            unsigned int availableHeight, unsigned int numberOfCells );
77
78   LocationVector GetLocations();
79
80 private:
81
82   GridLocations();
83   ~GridLocations();
84   GridLocations( const GridLocations& other ) = delete;
85   GridLocations& operator=( const GridLocations& other ) = delete;
86
87 private:
88
89   LocationVector mLocations;
90
91 };
92
93 } // namespace Internal
94 } // namespace Toolkit
95 } // namespace Dali
96
97 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_LOCATIONS_H