Tizen 2.1 base
[framework/osp/uifw.git] / inc / FUiRelativeLayout.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiRelativeLayout.h
20  * @brief               This is the header file for the %RelativeLayout class.
21  *
22  * This header file contains the declarations of the %RelativeLayout class.
23  */
24
25 #ifndef _FUI_RELATIVE_LAYOUT_H_
26 #define _FUI_RELATIVE_LAYOUT_H_
27
28 #include <FUiLayout.h>
29
30 namespace Tizen { namespace Ui
31 {
32 class Control;
33 }}
34
35 namespace Tizen { namespace Ui
36 {
37
38 /**
39  * @class       RelativeLayout
40  * @brief       The relative layout positions the children of a container in a manner that is relative to other children or its parent container.
41  *
42  * @since       2.0
43  *
44  * The %RelativeLayout class defines the relative layout for a Container. The layout positions the children of the %Container relative to the
45  * Container or its other children. @n
46  *
47  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/relative_layout.htm">Relative Layout</a>.
48  *
49  * @code
50 // Sample code for RelativeLayoutSample.h
51 #include <FUi.h>
52
53 class RelativeLayoutSample
54         : public Tizen::Ui::Controls::Form
55 {
56 public:
57         bool Initialize(void);
58         virtual result OnInitializing(void);
59 };
60  *      @endcode
61  *
62  *      @code
63 // Sample code for RelativeLayoutSample.cpp
64 #include <FGraphics.h>
65
66 #include "RelativeLayoutSample.h"
67
68 using namespace Tizen::Graphics;
69 using namespace Tizen::Ui;
70 using namespace Tizen::Ui::Controls;
71
72 bool
73 RelativeLayoutSample::Initialize(void)
74 {
75         // Creates an instance of RelativeLayout
76         RelativeLayout relativeFormLayout;
77         relativeFormLayout.Construct();
78
79         // Applies the relative layout to the form
80         Construct(relativeFormLayout, FORM_STYLE_NORMAL);
81         return true;
82 }
83
84 result
85 RelativeLayoutSample::OnInitializing(void)
86 {
87         result r = E_SUCCESS;
88
89         // Creates an instance of RelativeLayout for the top panel
90         RelativeLayout topPanelLayout;
91         topPanelLayout.Construct();
92
93         // Creates an instance of Panel and applies it to the relative layout
94         Panel* pTopRelativePanel = new Panel();
95         pTopRelativePanel->Construct(topPanelLayout, Rectangle(0, 0, 300, 300));
96         {
97                 // Creates instances of Button
98                 Button* pUpButton = new Button();
99                 pUpButton->Construct(Rectangle(0,0,200,100), "UP");
100                 pTopRelativePanel->AddControl(*pUpButton);
101
102                 Button* pMiddleButton = new Button();
103                 pMiddleButton->Construct(Rectangle(0,0,200,100), "CENTER");
104                 pTopRelativePanel->AddControl(*pMiddleButton);
105
106                 Button* pDownButton = new Button();
107                 pDownButton->Construct(Rectangle(0,0,200,100), "DOWN");
108                 pTopRelativePanel->AddControl(*pDownButton);
109
110                 // Sets relations between the pUpButton and pMiddleButton
111                 topPanelLayout.SetRelation(*pUpButton, *pMiddleButton, RECT_EDGE_RELATION_LEFT_TO_LEFT);
112                 topPanelLayout.SetRelation(*pUpButton, *pMiddleButton, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
113                 topPanelLayout.SetMargin(*pUpButton, 0, 0, 0, 10);
114
115                 // Sets the middle button
116                 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_HORIZONTAL);
117                 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_VERTICAL);
118                 topPanelLayout.SetMargin(*pMiddleButton, 10, 10, 10, 10);
119
120                 // Sets relations between the pDownButton and the pMiddleButton
121                 topPanelLayout.SetRelation(*pDownButton, *pMiddleButton, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
122                 topPanelLayout.SetRelation(*pDownButton, *pMiddleButton, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
123                 topPanelLayout.SetMargin(*pDownButton, 0, 0, 10, 0);
124         }
125
126         // Adds the top panel to the form
127         AddControl(*pTopRelativePanel);
128
129         // Creates an instance of RelativeLayout for the bottom panel
130         RelativeLayout bottomPanelLayout;
131         bottomPanelLayout.Construct();
132
133         // Creates an instance of Panel and applies it to the relative layout
134         Panel* pBottomRelativePanel = new Panel();
135         pBottomRelativePanel->Construct(bottomPanelLayout, Rectangle(0, 0, 300, 300));
136         {
137                 // Creates instances of Label
138                 Label* pFixedLabel = new Label();
139                 pFixedLabel->Construct(Rectangle(0, 0, 150, 80), L"FIXED");
140                 pFixedLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_YELLOW));
141                 pFixedLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
142                 pBottomRelativePanel->AddControl(*pFixedLabel);
143
144                 Label* pScalableLabel = new Label();
145                 pScalableLabel->Construct(Rectangle(0, 0, 150, 80), L"SCALABLE <=>");
146                 pScalableLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_BLUE));
147                 pScalableLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
148                 pBottomRelativePanel->AddControl(*pScalableLabel);
149
150                 // Sets relations between the fixed label and the panel
151                 bottomPanelLayout.SetCenterAligned(*pFixedLabel, CENTER_ALIGN_VERTICAL);
152                 bottomPanelLayout.SetRelation(*pFixedLabel, *pBottomRelativePanel, RECT_EDGE_RELATION_LEFT_TO_LEFT);
153                 bottomPanelLayout.SetRelation(*pFixedLabel, *pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
154                 bottomPanelLayout.SetMargin(*pFixedLabel, 30, 30, 30, 30);
155
156                 // Sets relations between the scalable label and the panel
157                 bottomPanelLayout.SetCenterAligned(*pScalableLabel, CENTER_ALIGN_VERTICAL);
158                 bottomPanelLayout.SetRelation(*pScalableLabel, *pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
159                 bottomPanelLayout.SetRelation(*pScalableLabel, *pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
160                 bottomPanelLayout.SetRelation(*pScalableLabel, *pBottomRelativePanel, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
161                 bottomPanelLayout.SetRelation(*pScalableLabel, *pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
162                 bottomPanelLayout.SetMargin(*pScalableLabel, 30, 30, 30, 30);
163         }
164
165         // Adds the bottom panel to the form
166         AddControl(*pBottomRelativePanel);
167
168         //Gets the layout of the form
169         RelativeLayout* pFormLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
170
171         // Sets relations of the top relative panel
172         pFormLayout->SetRelation(*pTopRelativePanel, *this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
173         pFormLayout->SetRelation(*pTopRelativePanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
174         pFormLayout->SetRelation(*pTopRelativePanel, *this, RECT_EDGE_RELATION_TOP_TO_TOP);
175
176         // Sets relations of the bottom relative panel
177         pFormLayout->SetRelation(*pBottomRelativePanel, *this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
178         pFormLayout->SetRelation(*pBottomRelativePanel, *this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
179         pFormLayout->SetRelation(*pBottomRelativePanel, *this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
180
181         // Sets relations between the top relative panel and the bottom relative panel
182         pFormLayout->SetHorizontalFitPolicy(*pTopRelativePanel, FIT_POLICY_PARENT);
183         pFormLayout->SetHorizontalFitPolicy(*pBottomRelativePanel, FIT_POLICY_PARENT);
184         pFormLayout->SetVerticalFitPolicy(*pBottomRelativePanel, FIT_POLICY_FIXED);
185         pFormLayout->SetRelation(*pTopRelativePanel, *pBottomRelativePanel, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
186
187         return r;
188 }
189  * @endcode
190  *
191  */
192 class _OSP_EXPORT_ RelativeLayout
193         : public Layout
194 {
195 public:
196         /**
197          * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
198          *
199          * @since               2.0
200          *
201          * @remarks             After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
202          */
203         RelativeLayout(void);
204
205         /**
206          * This destructor overrides Tizen::Base::Object::~Object().
207          *
208          * @since               2.0
209          */
210         virtual ~RelativeLayout(void);
211
212         /**
213          * Initializes this instance of %RelativeLayout.
214          *
215          * @since               2.0
216          *
217          * @return              An error code
218          * @exception   E_SUCCESS                       The method is successful.
219          * @exception   E_SYSTEM                        A system error has occurred.
220          */
221         result Construct(void);
222
223         /**
224          * Gets the type of the layout.
225          *
226          * @since               2.0
227          *
228          * @return      The layout type
229          */
230         virtual LayoutType GetLayoutType(void) const;
231
232         /**
233          * Sets the relation of the specified child control for the edge with other control.
234          *
235          * @since               2.0
236          *
237          * @return              An error code
238          * @param[in]   childControl    The control for which the relation is set
239          * @param[in]   targetControl   The target control @n
240          *                                                              It must be a parent or sibling.
241          * @param[in]   edgeRelation    The edge of the specified control to be aligned with the edge of the target control
242          * @exception   E_SUCCESS               The method is successful.
243          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
244          *                                                              Either the specified @c childControl or the specified @c targetControl is not a child of the container that owns the layout.
245          * @exception   E_SYSTEM                A system error has occurred.
246          */
247         result SetRelation(Control& childControl, const Control& targetControl, RectangleEdgeRelation edgeRelation);
248
249         /**
250          * Resets the relation of the specified control for the vertical edge.
251          *
252          * @since               2.0
253          *
254          * @return              An error code
255          * @param[in]   childControl    The control for which the relation is reset
256          * @param[in]   edgeType                The edge type of the specified control
257          * @exception   E_SUCCESS               The method is successful.
258          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
259          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
260          * @exception   E_SYSTEM                A system error has occurred.
261          */
262         result ResetRelation(Control& childControl, RectangleEdgeType edgeType);
263
264         /**
265          * Sets the specified control at the center of the parent control.
266          *
267          * @since               2.0
268          *
269          * @return              An error code
270          * @param[in]   childControl    The control to be center aligned
271          * @param[in]   alignment               The center alignment for a control either vertically or horizontally
272          * @exception   E_SUCCESS               The method is successful.
273          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
274          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
275          * @exception   E_SYSTEM                A system error has occurred.
276          * @remarks             The relation value that is set to a child control is ignored when the center-alignment is applied to the control.
277          */
278         result SetCenterAligned(Control& childControl, CenterAlignmentType alignment);
279
280         /**
281          * Resets the center position of the specified control.
282          *
283          * @since               2.0
284          *
285          * @return              An error code
286          * @param[in]   childControl    The control to be center aligned
287          * @param[in]   alignment               The center alignment for a control either vertically or horizontally
288          * @exception   E_SUCCESS               The method is successful.
289          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
290          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
291          * @exception   E_SYSTEM                A system error has occurred.
292          */
293         result ResetCenterAligned(Control& childControl, CenterAlignmentType alignment);
294
295         /**
296          * Sets the margins of the specified control.
297          *
298          * @since               2.0
299          *
300          * @return              An error code
301          * @param[in]   childControl    The control for which the margins are set
302          * @param[in]   left                    The left margin
303          * @param[in]   right                   The right margin
304          * @param[in]   top                             The top margin
305          * @param[in]   bottom                  The bottom margin
306          * @exception   E_SUCCESS               The method is successful.
307          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
308          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
309          * @exception   E_SYSTEM                A system error has occurred.
310          * @remarks             By default, the margins are set to @c 0.
311          */
312         result SetMargin(Control& childControl, int left, int right, int top, int bottom);
313
314         /**
315          * Sets the width of the specified control to the fixed size.
316          *
317          * @since               2.0
318          *
319          * @return              An error code
320          * @param[in]   childControl    The control for which the width is set
321          * @param[in]   width                   The value of the width
322          * @exception   E_SUCCESS               The method is successful.
323          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
324          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
325          * @exception   E_SYSTEM                A system error has occurred.
326          */
327         result SetWidth(Control& childControl, int width);
328
329         /**
330          * Sets the width of the specified control as per the fitting policy.
331          *
332          * @since               2.0
333          *
334          * @return              An error code
335          * @param[in]   childControl    The control for which the width is set
336          * @param[in]   policy                  The fitting policy for the width
337          * @exception   E_SUCCESS               The method is successful.
338          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
339          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
340          * @exception   E_SYSTEM                A system error has occurred.
341          */
342         result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
343
344         /**
345          * Sets the height of the specified control to the fixed size.
346          *
347          * @since               2.0
348          *
349          * @return              An error code
350          * @param[in]   childControl    The control for which the height is set
351          * @param[in]   height                  The value of the height
352          * @exception   E_SUCCESS               The method is successful.
353          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
354          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
355          * @exception   E_SYSTEM                A system error has occurred.
356          */
357         result SetHeight(Control& childControl, int height);
358
359         /**
360          * Sets the height of the specified control as per the fitting policy.
361          *
362          * @since               2.0
363          *
364          * @return              An error code
365          * @param[in]   childControl    The control for which the height is set
366          * @param[in]   policy                  The fitting policy for the height
367          * @exception   E_SUCCESS               The method is successful.
368          * @exception   E_INVALID_ARG   The specified input parameter is invalid. @n
369          *                                                              The specified @c childControl parameter is not a child of the container that owns the layout.
370          * @exception   E_SYSTEM                A system error has occurred.
371          */
372         result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
373
374 private:
375         //
376         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
377         //
378         RelativeLayout(const RelativeLayout& rhs);
379
380         //
381         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
382         //
383         RelativeLayout& operator =(const RelativeLayout& rhs);
384
385 }; // RelativeLayout
386
387 }} // Tizen::Ui
388
389 #endif // _FUI_RELATIVE_LAYOUT_H_