2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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 The relative layout 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>.
50 // Sample code for RelativeLayoutSample.h
53 class RelativeLayoutSample
54 : public Tizen::Ui::Controls::Form
57 bool Initialize(void);
58 virtual result OnInitializing(void);
63 // Sample code for RelativeLayoutSample.cpp
64 #include <FGraphics.h>
66 #include "RelativeLayoutSample.h"
68 using namespace Tizen::Graphics;
69 using namespace Tizen::Ui;
70 using namespace Tizen::Ui::Controls;
73 RelativeLayoutSample::Initialize(void)
75 // Creates an instance of RelativeLayout
76 RelativeLayout relativeFormLayout;
77 relativeFormLayout.Construct();
79 // Applies the relative layout to the form
80 Construct(relativeFormLayout, FORM_STYLE_NORMAL);
85 RelativeLayoutSample::OnInitializing(void)
89 // Creates an instance of RelativeLayout for the top panel
90 RelativeLayout topPanelLayout;
91 topPanelLayout.Construct();
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));
97 // Creates instances of Button
98 Button* pUpButton = new Button();
99 pUpButton->Construct(Rectangle(0,0,200,100), "UP");
100 pTopRelativePanel->AddControl(*pUpButton);
102 Button* pMiddleButton = new Button();
103 pMiddleButton->Construct(Rectangle(0,0,200,100), "CENTER");
104 pTopRelativePanel->AddControl(*pMiddleButton);
106 Button* pDownButton = new Button();
107 pDownButton->Construct(Rectangle(0,0,200,100), "DOWN");
108 pTopRelativePanel->AddControl(*pDownButton);
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);
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);
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);
126 // Adds the top panel to the form
127 AddControl(*pTopRelativePanel);
129 // Creates an instance of RelativeLayout for the bottom panel
130 RelativeLayout bottomPanelLayout;
131 bottomPanelLayout.Construct();
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));
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);
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);
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);
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);
165 // Adds the bottom panel to the form
166 AddControl(*pBottomRelativePanel);
168 //Gets the layout of the form
169 RelativeLayout* pFormLayout = dynamic_cast<RelativeLayout*>(this->GetLayoutN());
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);
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);
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);
192 class _OSP_EXPORT_ RelativeLayout
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.
201 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
203 RelativeLayout(void);
206 * This destructor overrides Tizen::Base::Object::~Object().
210 virtual ~RelativeLayout(void);
213 * Initializes this instance of %RelativeLayout.
217 * @return An error code
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_SYSTEM A system error has occurred.
221 result Construct(void);
224 * Gets the type of the layout.
228 * @return The layout type
230 virtual LayoutType GetLayoutType(void) const;
233 * Sets the relation of the specified child control for the edge with other control.
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.
247 result SetRelation(Control& childControl, const Control& targetControl, RectangleEdgeRelation edgeRelation);
250 * Resets the relation of the specified control for the vertical edge.
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.
262 result ResetRelation(Control& childControl, RectangleEdgeType edgeType);
265 * Sets the specified control at the center of the parent control.
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.
278 result SetCenterAligned(Control& childControl, CenterAlignmentType alignment);
281 * Resets the center position of the specified control.
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.
293 result ResetCenterAligned(Control& childControl, CenterAlignmentType alignment);
296 * Sets the margins of the specified control.
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.
312 result SetMargin(Control& childControl, int left, int right, int top, int bottom);
315 * Sets the width of the specified control to the fixed size.
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.
327 result SetWidth(Control& childControl, int width);
330 * Sets the width of the specified control as per the fitting policy.
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.
342 result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
345 * Sets the height of the specified control to the fixed size.
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.
357 result SetHeight(Control& childControl, int height);
360 * Sets the height of the specified control as per the fitting policy.
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.
372 result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
376 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
378 RelativeLayout(const RelativeLayout& rhs);
381 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
383 RelativeLayout& operator =(const RelativeLayout& rhs);
389 #endif // _FUI_RELATIVE_LAYOUT_H_