[dali_1.4.16] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / linear-layout-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_LINEAR_LAYOUT_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_LINEAR_LAYOUT_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 #include <dali/public-api/common/intrusive-ptr.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
23 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Internal
30 {
31
32 class LinearLayout;
33 using LinearLayoutPtr = IntrusivePtr<LinearLayout>;
34
35 class LinearLayout final : public LayoutGroup
36 {
37 public:
38   /**
39    * Creates a pointer to a LinearLayout implementation.
40    */
41   static LinearLayoutPtr New();
42
43 public:
44   /**
45    * @brief Set the padding between cells in the layout
46    *
47    * @param[in] size The padding between cells.
48    */
49   void SetCellPadding( LayoutSize size );
50
51   /**
52    * @brief Get the padding between cells in the layout
53    *
54    * @return The padding between cells.
55    */
56   LayoutSize GetCellPadding() const;
57
58   /**
59    * @brief Set the orientation in the layout
60    *
61    * @param[in] orientation The orientation.
62    */
63   void SetOrientation( Dali::Toolkit::LinearLayout::Orientation orientation );
64
65   /**
66    * @brief Get the orientation in the layout
67    *
68    * @return The orientation.
69    */
70   Dali::Toolkit::LinearLayout::Orientation GetOrientation() const;
71
72   /**
73    * @brief Set the alignment in the layout
74    *
75    * @param[in] alignment The alignment.
76    */
77   void SetAlignment( unsigned int alignment );
78
79   /**
80    * @brief Get the alignment in the layout
81    *
82    * @return The alignment.
83    */
84   unsigned int GetAlignment() const;
85
86 protected:
87   /**
88    * Default Constructor
89    */
90   LinearLayout();
91
92   /**
93    * Destructor
94    */
95   virtual ~LinearLayout();
96
97   /**
98    * @copydoc LayoutItem::DoRegisterChildProperties()
99    */
100   virtual void DoRegisterChildProperties( const std::string& containerType ) override;
101
102   /**
103     * @copydoc LayoutItem::OnChildAdd
104     */
105   virtual void OnChildAdd( LayoutItem& child ) override;
106
107   /**
108    * @copydoc LayoutItem::OnMeasure
109    */
110   virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override;
111
112   /**
113    * @copydoc LayoutItem::OnLayout
114    */
115   virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override;
116
117 private:
118   LinearLayout( const LinearLayout& other ) = delete;
119   LinearLayout& operator=( const LinearLayout& other ) = delete;
120
121  /**
122   * Measure children for horizontal orientation
123   */
124   void MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
125
126  /**
127   * Apply a uniform height to the children
128   */
129   void ForceUniformHeight( int count, MeasureSpec widthMeasureSpec );
130
131  /**
132   * Layout the children horizontally
133   */
134   void LayoutHorizontal( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
135
136  /**
137   * Measure children for horizontal orientation
138   */
139   void MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
140
141  /**
142   * Apply a uniform width to the children
143   */
144   void ForceUniformWidth( int count, MeasureSpec heightMeasureSpec );
145
146  /**
147   * Layout the children vertically
148   */
149   void LayoutVertical( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
150
151 private:
152   LayoutSize mCellPadding;
153   Dali::Toolkit::LinearLayout::Orientation mOrientation;
154   unsigned int mAlignment;
155   LayoutLength mTotalLength;
156 };
157
158 } // namespace Internal
159
160 inline Internal::LinearLayout& GetImplementation( Dali::Toolkit::LinearLayout& handle )
161 {
162   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
163   BaseObject& object = handle.GetBaseObject();
164   return static_cast<Internal::LinearLayout&>( object );
165 }
166
167 inline const Internal::LinearLayout& GetImplementation( const Dali::Toolkit::LinearLayout& handle )
168 {
169   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
170   const BaseObject& object = handle.GetBaseObject();
171   return static_cast<const Internal::LinearLayout&>( object );
172 }
173
174 } // namespace Toolkit
175 } // namespace Dali
176
177 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LINEAR_LAYOUT_H