[NUI] Add NUI-Layout 2nd patch (#294)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Layouting / LayoutGroup.cs
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// LayoutGroup class providing container functionality.
25     /// </summary>
26     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class LayoutGroup : LayoutGroupWrapper
29     {
30         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public LayoutGroup() : base(new LayoutGroupWrapperImpl())
33         {
34             // Initialize delegates of LayoutItem
35             LayoutItemInitialize(layoutGroupWrapperImpl);
36
37             layoutGroupWrapperImpl.OnMeasure = new LayoutGroupWrapperImpl.OnMeasureDelegate(OnMeasure);
38             layoutGroupWrapperImpl.OnLayout = new LayoutGroupWrapperImpl.OnLayoutDelegate(OnLayout);
39             layoutGroupWrapperImpl.OnSizeChanged = new LayoutGroupWrapperImpl.OnSizeChangedDelegate(OnSizeChanged);
40             layoutGroupWrapperImpl.OnChildAdd = new LayoutGroupWrapperImpl.OnChildAddDelegate(OnChildAdd);
41             layoutGroupWrapperImpl.OnChildRemove = new LayoutGroupWrapperImpl.OnChildRemoveDelegate(OnChildRemove);
42             layoutGroupWrapperImpl.DoInitialize = new LayoutGroupWrapperImpl.DoInitializeDelegate(DoInitialize);
43             layoutGroupWrapperImpl.DoRegisterChildProperties = new LayoutGroupWrapperImpl.DoRegisterChildPropertiesDelegate(DoRegisterChildProperties);
44             layoutGroupWrapperImpl.MeasureChildren = new LayoutGroupWrapperImpl.MeasureChildrenDelegate(MeasureChildren);
45             layoutGroupWrapperImpl.MeasureChild = new LayoutGroupWrapperImpl.MeasureChildDelegate(MeasureChild);
46             layoutGroupWrapperImpl.MeasureChildWithMargins = new LayoutGroupWrapperImpl.MeasureChildWithMarginsDelegate(MeasureChildWithMargins);
47         }
48
49         /// <summary>
50         /// Remove all layout children.<br />
51         /// </summary>
52         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public void RemoveAll()
55         {
56             layoutGroupWrapperImpl.RemoveAll();
57         }
58
59         /// <summary>
60         /// Get the child layout id of the given child.<br />
61         /// </summary>
62         /// <param name="child">The given Layout child.</param>
63         internal uint GetChildId(LayoutItemWrapperImpl child)
64         {
65             return layoutGroupWrapperImpl.GetChildId(child);
66         }
67
68         /// <summary>
69         /// Calculate the right measure spec for this child.
70         /// Does the hard part of MeasureChildren: figuring out the MeasureSpec to
71         /// pass to a particular child. This method figures out the right MeasureSpec
72         /// for one dimension (height or width) of one child view.<br />
73         /// </summary>
74         /// <param name="measureSpec">The requirements for this view.</param>
75         /// <param name="padding">The padding of this view for the current dimension and margins, if applicable.</param>
76         /// <param name="childDimension"> How big the child wants to be in the current dimension.</param>
77         /// <returns>a MeasureSpec for the child.</returns>
78         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public static LayoutMeasureSpec GetChildMeasureSpec(LayoutMeasureSpec measureSpec, LayoutLength padding, LayoutLength childDimension)
81         {
82             return LayoutGroupWrapperImpl.GetChildMeasureSpec(measureSpec, padding, childDimension);
83         }
84
85         /// <summary>
86         /// Measure the layout and its content to determine the measured width and the measured height.<br />
87         /// If this method is overridden, it is the subclass's responsibility to make
88         /// sure the measured height and width are at least the layout's minimum height
89         /// and width. <br />
90         /// </summary>
91         /// <param name="widthMeasureSpec">horizontal space requirements as imposed by the parent.</param>
92         /// <param name="heightMeasureSpec">vertical space requirements as imposed by the parent.</param>
93         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
94         [EditorBrowsable(EditorBrowsableState.Never)]
95         protected virtual void OnMeasure(LayoutMeasureSpec widthMeasureSpec, LayoutMeasureSpec heightMeasureSpec)
96         {
97             SetMeasuredDimensions(new MeasuredSize(LayoutItemWrapperImpl.GetDefaultSize(layoutItemWrapperImpl.GetSuggestedMinimumWidth(), widthMeasureSpec)),
98                                    new MeasuredSize(LayoutItemWrapperImpl.GetDefaultSize(layoutItemWrapperImpl.GetSuggestedMinimumHeight(), heightMeasureSpec)));
99         }
100
101         /// <summary>
102         /// Called from Layout() when this layout should assign a size and position to each of its children.<br />
103         /// Derived classes with children should override this method and call Layout() on each of their children.<br />
104         /// </summary>
105         /// <param name="changed">This is a new size or position for this layout.</param>
106         /// <param name="left">Left position, relative to parent.</param>
107         /// <param name="top"> Top position, relative to parent.</param>
108         /// <param name="right">Right position, relative to parent.</param>
109         /// <param name="bottom">Bottom position, relative to parent.</param>
110         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
111         [EditorBrowsable(EditorBrowsableState.Never)]
112         protected virtual void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
113         {
114
115         }
116
117         /// <summary>
118         /// Virtual method to inform derived classes when the layout size changed.<br />
119         /// </summary>
120         /// <param name="newSize">The new size of the layout.</param>
121         /// <param name="oldSize">The old size of the layout.</param>
122         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
123         [EditorBrowsable(EditorBrowsableState.Never)]
124         protected virtual void OnSizeChanged(LayoutSize newSize, LayoutSize oldSize)
125         {
126
127         }
128
129         /// <summary>
130         /// Callback when child is added to container.<br />
131         /// Derived classes can use this to set their own child properties on the child layout's owner.<br />
132         /// </summary>
133         /// <param name="child">The Layout child.</param>
134         internal virtual void OnChildAdd(LayoutItemWrapperImpl child)
135         {
136         }
137
138         /// <summary>
139         /// Callback when child is removed from container.<br />
140         /// </summary>
141         /// <param name="child">The Layout child.</param>
142         internal virtual void OnChildRemove(LayoutItemWrapperImpl child)
143         {
144         }
145
146         /// <summary>
147         /// Second stage initialization method for deriving classes to override.<br />
148         /// </summary>
149         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
150         [EditorBrowsable(EditorBrowsableState.Never)]
151         protected virtual void DoInitialize()
152         {
153         }
154
155         /// <summary>
156         /// Method for derived classes to implement in order to register child property types with the container.<br />
157         /// </summary>
158         /// <param name="containerType">The fully qualified typename of the container.</param>
159         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         protected virtual void DoRegisterChildProperties(string containerType)
162         {
163         }
164
165         /// <summary>
166         /// Ask all of the children of this view to measure themselves, taking into
167         /// account both the MeasureSpec requirements for this view and its padding.<br />
168         /// The heavy lifting is done in GetChildMeasureSpec.<br />
169         /// </summary>
170         /// <param name="widthMeasureSpec">The width requirements for this view.</param>
171         /// <param name="heightMeasureSpec">The height requirements for this view.</param>
172         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         protected virtual void MeasureChildren(LayoutMeasureSpec widthMeasureSpec, LayoutMeasureSpec heightMeasureSpec)
175         {
176             layoutGroupWrapperImpl.MeasureChildrenNative(widthMeasureSpec, heightMeasureSpec);
177         }
178
179         /// <summary>
180         /// Ask one of the children of this view to measure itself, taking into
181         /// account both the MeasureSpec requirements for this view and its padding.<br />
182         /// The heavy lifting is done in GetChildMeasureSpec.<br />
183         /// </summary>
184         /// <param name="child">The child to measure.</param>
185         /// <param name="parentWidthMeasureSpec">The width requirements for this view.</param>
186         /// <param name="parentHeightMeasureSpec">The height requirements for this view.</param>
187         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
188         [EditorBrowsable(EditorBrowsableState.Never)]
189         protected virtual void MeasureChild(LayoutItem child, LayoutMeasureSpec parentWidthMeasureSpec, LayoutMeasureSpec parentHeightMeasureSpec)
190         {
191             layoutGroupWrapperImpl.MeasureChildNative(child, parentWidthMeasureSpec, parentHeightMeasureSpec);
192         }
193
194         /// <summary>
195         /// Ask one of the children of this view to measure itself, taking into
196         /// account both the MeasureSpec requirements for this view and its padding.<br />
197         /// and margins. The child must have MarginLayoutParams The heavy lifting is
198         /// done in GetChildMeasureSpec.<br />
199         /// </summary>
200         /// <param name="child">The child to measure.</param>
201         /// <param name="parentWidthMeasureSpec">The width requirements for this view.</param>
202         /// <param name="widthUsed">Extra space that has been used up by the parent horizontally (possibly by other children of the parent).</param>
203         /// <param name="parentHeightMeasureSpec">The height requirements for this view.</param>
204         /// <param name="heightUsed">Extra space that has been used up by the parent vertically (possibly by other children of the parent).</param>
205         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         protected virtual void MeasureChildWithMargins(LayoutItem child, LayoutMeasureSpec parentWidthMeasureSpec, LayoutLength widthUsed, LayoutMeasureSpec parentHeightMeasureSpec, LayoutLength heightUsed)
208         {
209             layoutGroupWrapperImpl.MeasureChildWithMarginsNative(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
210         }
211     }
212 }