Add size animation in layout measure phase.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / layouting / flex-layout-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_FLEX_LAYOUT_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_FLEX_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 //EXTERNAL INCLUDES
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/object/base-object.h>
23
24 //INTERNAL INCLUDES
25 #include <dali-toolkit/devel-api/layouting/flex-layout.h>
26 #include <dali-toolkit/devel-api/layouting/layout-group-impl.h>
27 #include <dali-toolkit/third-party/yoga/Yoga.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Internal
34 {
35
36 class FlexLayout;
37 using FlexLayoutPtr = IntrusivePtr<FlexLayout>;
38
39 class FlexLayout final : public LayoutGroup
40 {
41 public:
42   static FlexLayoutPtr New();
43
44 public:
45   /**
46    * @copydoc FlexLayout::SetFlexDirection
47    */
48   void SetFlexDirection( Dali::Toolkit::FlexLayout::FlexDirection flexDirection );
49
50   /**
51    * @copydoc FlexLayout::GetFlexDirection
52    */
53   Dali::Toolkit::FlexLayout::FlexDirection GetFlexDirection() const;
54
55   /**
56    * @copydoc FlexLayout::SetFlexJustification
57    */
58   void SetFlexJustification( Dali::Toolkit::FlexLayout::Justification flexJustification );
59
60   /**
61    * @copydoc FlexLayout::GetFlexJustification
62    */
63   Dali::Toolkit::FlexLayout::Justification GetFlexJustification() const;
64
65   /**
66    * @copydoc FlexLayout::SetFlexWrap
67    */
68   void SetFlexWrap( Dali::Toolkit::FlexLayout::WrapType wrap );
69
70   /**
71    * @copydoc FlexLayout::GetFlexWrap
72    */
73   Dali::Toolkit::FlexLayout::WrapType GetFlexWrap() const;
74
75   /**
76    * @copydoc FlexLayout::SetFlexAlignment
77    */
78   void SetFlexAlignment( Dali::Toolkit::FlexLayout::Alignment::Type flexAlignment );
79   /**
80    * @copydoc FlexLayout::GetFlexAlignment
81    */
82   Dali::Toolkit::FlexLayout::Alignment::Type GetFlexAlignment() const;
83
84   /**
85    * @copydoc FlexLayout::SetFlexItemsAlignment
86    */
87   void SetFlexItemsAlignment( Dali::Toolkit::FlexLayout::Alignment::Type flexAlignment );
88
89   /**
90    * @copydoc FlexLayout::GetFlexItemsAlignment
91    */
92   Dali::Toolkit::FlexLayout::Alignment::Type GetFlexItemsAlignment() const;
93
94 protected:
95   /**
96    * Constructor
97    */
98   FlexLayout();
99
100   /**
101    * Virtual destructor
102    */
103   virtual ~FlexLayout();
104
105   /**
106    * @copydoc LayoutItem::DoInitialize
107    */
108   virtual void DoInitialize() override;
109
110   /**
111    * @copydoc LayoutItem::DoRegisterChildProperties()
112    */
113   virtual void DoRegisterChildProperties( const std::string& containerType ) override;
114
115   /**
116    * @copydoc LayoutItem::OnChildAdd
117    */
118   virtual void OnChildAdd( LayoutItem& child ) override;
119
120   /**
121    * @copydoc LayoutItem::OnChildRemove
122    */
123   virtual void OnChildRemove( LayoutItem& child ) override;
124
125   /**
126    * @copydoc LayoutItem::OnMeasure
127    */
128   virtual void OnMeasure( MeasureSpec widthMeasureSpec, MeasureSpec heightMeasureSpec ) override;
129
130   /**
131    * @copydoc LayoutItem::OnLayout
132    */
133   virtual void OnLayout( bool changed, LayoutLength l, LayoutLength t, LayoutLength r, LayoutLength b ) override;
134
135 private:
136   FlexLayout( const FlexLayout& other ) = delete;
137   FlexLayout& operator=( const FlexLayout& other ) = delete;
138
139   static YGSize OnChildMeasure( YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode );
140   void SetChildrenStyle();
141
142 private:
143   YGNodeRef mRoot;
144 };
145
146 } // namespace Internal
147
148 inline Internal::FlexLayout& GetImplementation( Dali::Toolkit::FlexLayout& handle )
149 {
150   DALI_ASSERT_ALWAYS( handle && "FboxLayout handle is empty" );
151   BaseObject& object = handle.GetBaseObject();
152   return static_cast<Internal::FlexLayout&>( object );
153 }
154
155 inline const Internal::FlexLayout& GetImplementation( const Dali::Toolkit::FlexLayout& handle )
156 {
157   DALI_ASSERT_ALWAYS( handle && "FboxLayout handle is empty" );
158   const BaseObject& object = handle.GetBaseObject();
159   return static_cast<const Internal::FlexLayout&>( object );
160 }
161
162 } // namespace Toolkit
163 } // namespace Dali
164
165 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_FLEX_LAYOUT_H