Merge "Do not substarct outline width in text-controller" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / grid-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_GRID_IMPL_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/object/base-object.h>
23
24 // INTERNAL_HEADERS
25 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
26 #include <dali-toolkit/devel-api/layouting/grid.h>
27 #include <dali-toolkit/internal/layouting/grid-locations.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35
36 class Grid;
37 using GridPtr = IntrusivePtr<Grid>;
38
39 class Grid final : public LayoutGroup
40 {
41 public:
42
43   /**
44    * Creates a pointer to an Internal Grid
45    */
46   static GridPtr New();
47
48   /**
49    * Set grid's the number of columns
50    * @param[in] columns number of columns
51    */
52   void SetNumberOfColumns( int columns );
53
54   /**
55    * Get number of columns, -1 would indicate AUTO_FIT
56    * which means the number has not been set but will be calculated.
57    * @return the number of columns set
58    */
59   int GetNumberOfColumns() const;
60
61   // Movable but not copyable
62   Grid( const Grid& other ) = delete;
63   Grid& operator=( const Grid& other ) = delete;
64   Grid( Grid && ) = default;
65   Grid& operator=( Grid && ) = default;
66
67 protected:
68
69   /**
70    * Default Constructor
71    */
72   Grid();
73
74   /**
75    * Destructor
76    */
77   ~Grid();
78
79   /**
80    * @copydoc LayoutItem::OnMeasure
81    */
82   virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override;
83
84   /**
85    * @copydoc LayoutItem::OnLayout
86    */
87   virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override;
88
89 private:
90
91   /**
92    * @brief
93    * For the given availableSpace, calculate or retreive the number of required columns.
94    * @param[in] availableSpace the space available for a child in each column.
95    */
96   void DetermineNumberOfColumns( LayoutLength availableSpace );
97
98 private:
99
100   GridLocationsPtr mLocations;
101
102   LayoutLength mTotalHeight;
103   LayoutLength mTotalWidth;
104
105   const int AUTO_FIT = -1;
106
107   int mNumColumns;
108   int mNumRows;
109
110   int mRequestedColumnWidth;
111   int mRequestedNumColumns;
112 };
113
114 } // namespace Internal
115
116 inline Internal::Grid& GetImplementation( Dali::Toolkit::Grid& handle )
117 {
118   DALI_ASSERT_ALWAYS( handle && "Grid handle is empty" );
119   BaseObject& object = handle.GetBaseObject();
120   return static_cast<Internal::Grid&>( object );
121 }
122
123 inline const Internal::Grid& GetImplementation( const Dali::Toolkit::Grid& handle )
124 {
125   DALI_ASSERT_ALWAYS( handle && "Grid handle is empty" );
126   const BaseObject& object = handle.GetBaseObject();
127   return static_cast<const Internal::Grid&>( object );
128 }
129
130 } // namespace Toolkit
131 } // namespace Dali
132
133 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTINGInner