Actor's position and size is not updated after DevelControl::SetLayout.
[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::OnMeasure
99    */
100   virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override;
101
102   /**
103    * @copydoc LayoutItem::OnLayout
104    */
105   virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override;
106
107 private:
108   LinearLayout( const LinearLayout& other ) = delete;
109   LinearLayout& operator=( const LinearLayout& other ) = delete;
110
111  /**
112   * Measure children for horizontal orientation
113   */
114   void MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
115
116  /**
117   * Apply a uniform height to the children
118   */
119   void ForceUniformHeight( int count, MeasureSpec widthMeasureSpec );
120
121  /**
122   * Layout the children horizontally
123   */
124   void LayoutHorizontal( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
125
126  /**
127   * Measure children for horizontal orientation
128   */
129   void MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
130
131  /**
132   * Apply a uniform width to the children
133   */
134   void ForceUniformWidth( int count, MeasureSpec heightMeasureSpec );
135
136  /**
137   * Layout the children vertically
138   */
139   void LayoutVertical( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
140
141 private:
142   LayoutSize mCellPadding;
143   Dali::Toolkit::LinearLayout::Orientation mOrientation;
144   unsigned int mAlignment;
145   LayoutLength mTotalLength;
146 };
147
148 } // namespace Internal
149
150 inline Internal::LinearLayout& GetImplementation( Dali::Toolkit::LinearLayout& handle )
151 {
152   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
153   BaseObject& object = handle.GetBaseObject();
154   return static_cast<Internal::LinearLayout&>( object );
155 }
156
157 inline const Internal::LinearLayout& GetImplementation( const Dali::Toolkit::LinearLayout& handle )
158 {
159   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
160   const BaseObject& object = handle.GetBaseObject();
161   return static_cast<const Internal::LinearLayout&>( object );
162 }
163
164 } // namespace Toolkit
165 } // namespace Dali
166
167 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LINEAR_LAYOUT_H