2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiRelativeLayout.h
20 * @brief This is the header file for the %RelativeLayout class.
22 * This header file contains the declarations of the %RelativeLayout class.
25 #ifndef _FUI_RELATIVE_LAYOUT_H_
26 #define _FUI_RELATIVE_LAYOUT_H_
28 #include <FUiLayout.h>
30 namespace Tizen { namespace Ui
35 namespace Tizen { namespace Ui
39 * @class RelativeLayout
40 * @brief This class positions the children of a container in a manner that is relative to other children or its parent container.
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
47 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/relative_layout.htm">Relative Layout</a>.
49 * The following examples demonstrate how to use the %RelativeLayout class.
51 // Sample code for RelativeLayoutSample.h
54 class RelativeLayoutSample
55 : public Tizen::Ui::Controls::Form
58 bool Initialize(void);
59 virtual result OnInitializing(void);
64 // Sample code for RelativeLayoutSample.cpp
65 #include <FGraphics.h>
67 #include "RelativeLayoutSample.h"
69 using namespace Tizen::Graphics;
70 using namespace Tizen::Ui;
71 using namespace Tizen::Ui::Controls;
74 RelativeLayoutSample::Initialize(void)
76 // Creates an instance of RelativeLayout
77 RelativeLayout relativeFormLayout;
78 relativeFormLayout.Construct();
80 // Applies the relative layout to the form
81 Construct(relativeFormLayout, FORM_STYLE_NORMAL);
86 RelativeLayoutSample::OnInitializing(void)
90 // Creates an instance of RelativeLayout for the top panel
91 RelativeLayout topPanelLayout;
92 topPanelLayout.Construct();
94 // Creates an instance of Panel and applies it to the relative layout
95 Panel* pTopRelativePanel = new Panel();
96 pTopRelativePanel->Construct(topPanelLayout, Rectangle(0, 0, 300, 300));
98 // Creates instances of Button
99 Button* pUpButton = new Button();
100 pUpButton->Construct(Rectangle(0,0,200,100), "UP");
101 pTopRelativePanel->AddControl(pUpButton);
103 Button* pMiddleButton = new Button();
104 pMiddleButton->Construct(Rectangle(0,0,200,100), "CENTER");
105 pTopRelativePanel->AddControl(pMiddleButton);
107 Button* pDownButton = new Button();
108 pDownButton->Construct(Rectangle(0,0,200,100), "DOWN");
109 pTopRelativePanel->AddControl(pDownButton);
111 // Sets relations between the pUpButton and pMiddleButton
112 topPanelLayout.SetRelation(*pUpButton, pMiddleButton, RECT_EDGE_RELATION_LEFT_TO_LEFT);
113 topPanelLayout.SetRelation(*pUpButton, pMiddleButton, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
114 topPanelLayout.SetMargin(*pUpButton, 0, 0, 0, 10);
116 // Sets the middle button
117 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_HORIZONTAL);
118 topPanelLayout.SetCenterAligned(*pMiddleButton, CENTER_ALIGN_VERTICAL);
119 topPanelLayout.SetMargin(*pMiddleButton, 10, 10, 10, 10);
121 // Sets relations between the pDownButton and the pMiddleButton
122 topPanelLayout.SetRelation(*pDownButton, pMiddleButton, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
123 topPanelLayout.SetRelation(*pDownButton, pMiddleButton, RECT_EDGE_RELATION_TOP_TO_BOTTOM);
124 topPanelLayout.SetMargin(*pDownButton, 0, 0, 10, 0);
127 // Adds the top panel to the form
128 AddControl(pTopRelativePanel);
130 // Creates an instance of RelativeLayout for the bottom panel
131 RelativeLayout bottomPanelLayout;
132 bottomPanelLayout.Construct();
134 // Creates an instance of Panel and applies it to the relative layout
135 Panel* pBottomRelativePanel = new Panel();
136 pBottomRelativePanel->Construct(bottomPanelLayout, Rectangle(0, 0, 300, 300));
138 // Creates instances of Label
139 Label* pFixedLabel = new Label();
140 pFixedLabel->Construct(Rectangle(0, 0, 150, 80), L"FIXED");
141 pFixedLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_YELLOW));
142 pFixedLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
143 pBottomRelativePanel->AddControl(pFixedLabel);
145 Label* pScalableLabel = new Label();
146 pScalableLabel->Construct(Rectangle(0, 0, 150, 80), L"SCALABLE <=>");
147 pScalableLabel->SetBackgroundColor(Color::GetColor(COLOR_ID_BLUE));
148 pScalableLabel->SetTextColor(Color::GetColor(COLOR_ID_BLACK));
149 pBottomRelativePanel->AddControl(pScalableLabel);
151 // Sets relations between the fixed label and the panel
152 bottomPanelLayout.SetCenterAligned(*pFixedLabel, CENTER_ALIGN_VERTICAL);
153 bottomPanelLayout.SetRelation(*pFixedLabel, pBottomRelativePanel, RECT_EDGE_RELATION_LEFT_TO_LEFT);
154 bottomPanelLayout.SetRelation(*pFixedLabel, pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
155 bottomPanelLayout.SetMargin(*pFixedLabel, 30, 30, 30, 30);
157 // Sets relations between the scalable label and the panel
158 bottomPanelLayout.SetCenterAligned(*pScalableLabel, CENTER_ALIGN_VERTICAL);
159 bottomPanelLayout.SetRelation(*pScalableLabel, pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
160 bottomPanelLayout.SetRelation(*pScalableLabel, pFixedLabel, RECT_EDGE_RELATION_LEFT_TO_RIGHT);
161 bottomPanelLayout.SetRelation(*pScalableLabel, pBottomRelativePanel, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
162 bottomPanelLayout.SetRelation(*pScalableLabel, pBottomRelativePanel, RECT_EDGE_RELATION_TOP_TO_TOP);
163 bottomPanelLayout.SetMargin(*pScalableLabel, 30, 30, 30, 30);
166 // Adds the bottom panel to the form
167 AddControl(pBottomRelativePanel);
169 //Gets the layout of the form
170 RelativeLayout* pFormLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
172 // Sets relations of the top relative panel
173 pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
174 pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
175 pFormLayout->SetRelation(*pTopRelativePanel, this, RECT_EDGE_RELATION_TOP_TO_TOP);
177 // Sets relations of the bottom relative panel
178 pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_LEFT_TO_LEFT);
179 pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
180 pFormLayout->SetRelation(*pBottomRelativePanel, this, RECT_EDGE_RELATION_BOTTOM_TO_BOTTOM);
182 // Sets relations between the top relative panel and the bottom relative panel
183 pFormLayout->SetHorizontalFitPolicy(*pTopRelativePanel, FIT_POLICY_PARENT);
184 pFormLayout->SetHorizontalFitPolicy(*pBottomRelativePanel, FIT_POLICY_PARENT);
185 pFormLayout->SetVerticalFitPolicy(*pBottomRelativePanel, FIT_POLICY_FIXED);
186 pFormLayout->SetRelation(*pTopRelativePanel, pBottomRelativePanel, RECT_EDGE_RELATION_BOTTOM_TO_TOP);
193 class _OSP_EXPORT_ RelativeLayout
198 * 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.
202 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
204 RelativeLayout(void);
207 * This destructor overrides Tizen::Base::Object::~Object().
211 virtual ~RelativeLayout(void);
214 * Initializes this instance of %RelativeLayout.
218 * @return An error code
219 * @exception E_SUCCESS The method is successful.
220 * @exception E_SYSTEM A system error has occurred.
222 result Construct(void);
225 * Gets the type of the layout.
229 * @return The layout type
231 virtual LayoutType GetLayoutType(void) const;
234 * Sets the relation of the specified child control for the edge with other control.
236 * @brief <i> [Deprecated] </i>
237 * @deprecated This method is deprecated.
240 * @return An error code
241 * @param[in] childControl The control for which the relation is set
242 * @param[in] targetControl The target control @n
243 * It must be a parent or sibling.
244 * @param[in] edgeRelation The edge of the specified control to align with the edge of the target control
245 * @exception E_SUCCESS The method is successful.
246 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
247 * Either the specified @c childControl or the specified @c targetControl is not a child of the container that owns the layout.
248 * @exception E_SYSTEM A system error has occurred.
250 result SetRelation(Control& childControl, const Control& targetControl, RectangleEdgeRelation edgeRelation);
253 * Sets the relation of a specified child control for the edge with other control.
257 * @return An error code
258 * @param[in] childControl The control for which the relation is set
259 * @param[in] pTargetControl The target control @n
260 * It must be a parent or sibling.
261 * @param[in] edgeRelation The edge of the specified control to align with the edge of the target control
262 * @exception E_SUCCESS The method is successful.
263 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
264 * Either the specified @c childControl or the specified @c pTargetControl is not a child of the container that owns the layout.
265 * @exception E_SYSTEM A system error has occurred.
267 result SetRelation(Control& childControl, Control *pTargetControl, RectangleEdgeRelation edgeRelation);
270 * Resets the relation of the specified control for the vertical edge.
274 * @return An error code
275 * @param[in] childControl The control for which the relation is reset
276 * @param[in] edgeType The edge type of the specified control
277 * @exception E_SUCCESS The method is successful.
278 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
279 * The specified @c childControl parameter is not a child of the container that owns the layout.
280 * @exception E_SYSTEM A system error has occurred.
282 result ResetRelation(Control& childControl, RectangleEdgeType edgeType);
285 * Sets the specified control at the center of the parent control.
289 * @return An error code
290 * @param[in] childControl The control to center aligned
291 * @param[in] alignment The center alignment for a control either vertically or horizontally
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
294 * The specified @c childControl parameter is not a child of the container that owns the layout.
295 * @exception E_SYSTEM A system error has occurred.
296 * @remarks The relation value that is set to a child control is ignored when the center-alignment is applied to the control.
298 result SetCenterAligned(Control& childControl, CenterAlignmentType alignment);
301 * Resets the center position of the specified control.
305 * @return An error code
306 * @param[in] childControl The control to center aligned
307 * @param[in] alignment The center alignment for a control either vertically or horizontally
308 * @exception E_SUCCESS The method is successful.
309 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
310 * The specified @c childControl parameter is not a child of the container that owns the layout.
311 * @exception E_SYSTEM A system error has occurred.
313 result ResetCenterAligned(Control& childControl, CenterAlignmentType alignment);
316 * Sets the margins of the specified control.
320 * @return An error code
321 * @param[in] childControl The control for which the margins are set
322 * @param[in] left The left margin
323 * @param[in] right The right margin
324 * @param[in] top The top margin
325 * @param[in] bottom The bottom margin
326 * @exception E_SUCCESS The method is successful.
327 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
328 * The specified @c childControl parameter is not a child of the container that owns the layout.
329 * @exception E_SYSTEM A system error has occurred.
330 * @remarks By default, the margins are set to @c 0.
332 result SetMargin(Control& childControl, int left, int right, int top, int bottom);
335 * Sets the margins of a specified control.
339 * @return An error code
340 * @param[in] childControl The control for which the margins are set
341 * @param[in] left The left margin
342 * @param[in] right The right margin
343 * @param[in] top The top margin
344 * @param[in] bottom The bottom margin
345 * @exception E_SUCCESS The method is successful.
346 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
347 * The specified @c childControl parameter is not a child of the container that owns the layout.
348 * @exception E_SYSTEM A system error has occurred.
349 * @remarks By default, the margins are set to @c 0.
351 result SetMargin(Control& childControl, float left, float right, float top, float bottom);
354 * Sets the width of the specified control to the fixed size.
358 * @return An error code
359 * @param[in] childControl The control for which the width is set
360 * @param[in] width The value of the width
361 * @exception E_SUCCESS The method is successful.
362 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
363 * The specified @c childControl parameter is not a child of the container that owns the layout.
364 * @exception E_SYSTEM A system error has occurred.
366 result SetWidth(Control& childControl, int width);
369 * Sets the width of a specified control to the fixed size.
373 * @return An error code
374 * @param[in] childControl The control for which the width is set
375 * @param[in] width The value of the width
376 * @exception E_SUCCESS The method is successful.
377 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
378 * The specified @c childControl parameter is not a child of the container that owns the layout.
379 * @exception E_SYSTEM A system error has occurred.
381 result SetWidth(Control& childControl, float width);
384 * Sets the width of the specified control as per the fitting policy.
388 * @return An error code
389 * @param[in] childControl The control for which the width is set
390 * @param[in] policy The fitting policy for the width
391 * @exception E_SUCCESS The method is successful.
392 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
393 * The specified @c childControl parameter is not a child of the container that owns the layout.
394 * @exception E_SYSTEM A system error has occurred.
396 result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
399 * Sets the height of the specified control to the fixed size.
403 * @return An error code
404 * @param[in] childControl The control for which the height is set
405 * @param[in] height The value of the height
406 * @exception E_SUCCESS The method is successful.
407 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
408 * The specified @c childControl parameter is not a child of the container that owns the layout.
409 * @exception E_SYSTEM A system error has occurred.
411 result SetHeight(Control& childControl, int height);
414 * Sets the height of a specified control to the fixed size.
418 * @return An error code
419 * @param[in] childControl The control for which the height is set
420 * @param[in] height The value of the height
421 * @exception E_SUCCESS The method is successful.
422 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
423 * The specified @c childControl parameter is not a child of the container that owns the layout.
424 * @exception E_SYSTEM A system error has occurred.
426 result SetHeight(Control& childControl, float height);
429 * Sets the height of the specified control as per the fitting policy.
433 * @return An error code
434 * @param[in] childControl The control for which the height is set
435 * @param[in] policy The fitting policy for the height
436 * @exception E_SUCCESS The method is successful.
437 * @exception E_INVALID_ARG The specified input parameter is invalid. @n
438 * The specified @c childControl parameter is not a child of the container that owns the layout.
439 * @exception E_SYSTEM A system error has occurred.
441 result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
445 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
447 RelativeLayout(const RelativeLayout& rhs);
450 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
452 RelativeLayout& operator =(const RelativeLayout& rhs);
458 #endif // _FUI_RELATIVE_LAYOUT_H_