Merge HBoxLayout and VBoxLayout into LinearLayout.
[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   static LinearLayoutPtr New();
39
40 public:
41   void SetCellPadding( LayoutSize size );
42   LayoutSize GetCellPadding();
43   void SetOrientation( Dali::Toolkit::LinearLayout::Orientation orientation );
44   Dali::Toolkit::LinearLayout::Orientation GetOrientation();
45
46 protected:
47   LinearLayout();
48   virtual ~LinearLayout();
49
50   /**
51    * @copydoc LayoutItem::OnMeasure
52    */
53   virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override;
54
55   /**
56    * @copydoc LayoutItem::OnLayout
57    */
58   virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override;
59
60 private:
61   LinearLayout( const LinearLayout& other ) = delete;
62   LinearLayout& operator=( const LinearLayout& other ) = delete;
63
64  /**
65   * Measure children for horizontal orientation
66   */
67   void MeasureHorizontal( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
68
69  /**
70   * Apply a uniform height to the children
71   */
72   void ForceUniformHeight( int count, MeasureSpec widthMeasureSpec );
73
74  /**
75   * Layout the children horizontally
76   */
77   void LayoutHorizontal( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
78
79  /**
80   * Measure children for horizontal orientation
81   */
82   void MeasureVertical( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec );
83
84  /**
85   * Apply a uniform width to the children
86   */
87   void ForceUniformWidth( int count, MeasureSpec heightMeasureSpec );
88
89  /**
90   * Layout the children vertically
91   */
92   void LayoutVertical( LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b );
93
94 private:
95   LayoutSize mCellPadding;
96   Dali::Toolkit::LinearLayout::Orientation mOrientation;
97   LayoutLength mTotalLength;
98 };
99
100 } // namespace Internal
101
102 inline Internal::LinearLayout& GetImplementation( Dali::Toolkit::LinearLayout& handle )
103 {
104   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
105   BaseObject& object = handle.GetBaseObject();
106   return static_cast<Internal::LinearLayout&>( object );
107 }
108
109 inline const Internal::LinearLayout& GetImplementation( const Dali::Toolkit::LinearLayout& handle )
110 {
111   DALI_ASSERT_ALWAYS( handle && "LinearLayout handle is empty" );
112   const BaseObject& object = handle.GetBaseObject();
113   return static_cast<const Internal::LinearLayout&>( object );
114 }
115
116 } // namespace Toolkit
117 } // namespace Dali
118
119 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LINEAR_LAYOUT_H