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 FUiVerticalBoxLayout.h
20 * @brief This is the header file for the %VerticalBoxLayout class.
22 * This header file contains the declarations of the %VerticalBoxLayout class.
24 #ifndef _FUI_VERTICAL_BOX_LAYOUT_H_
25 #define _FUI_VERTICAL_BOX_LAYOUT_H_
27 #include <FUiLayout.h>
29 namespace Tizen { namespace Ui
34 * @class VerticalBoxLayout
35 * @brief The vertical box layout positions the children of a container vertically.
39 * The %VerticalBoxLayout class defines the vertical box layout for a Container. The layout positions the children of the %Container vertically.
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/single_dimensional_layout.htm">Vertical and Horizontal Box Layouts</a>.
43 * The following examples demonstrate how to use the %VerticalBoxLayout class.
45 // Sample code for VerticalBoxLayoutSample.h
48 class VerticalBoxLayoutSample
49 : public Tizen::Ui::Controls::Form
52 bool Initialize(void);
53 virtual result OnInitializing(void);
58 // Sample code for VerticalBoxLayoutSample.cpp
59 #include <FGraphics.h>
61 #include "VerticalBoxLayoutSample.h"
63 using namespace Tizen::Graphics;
64 using namespace Tizen::Ui;
65 using namespace Tizen::Ui::Controls;
68 VerticalBoxLayoutSample::Initialize(void)
70 //Creates an instance of VerticalBoxLayout
71 VerticalBoxLayout formLayout;
72 formLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
74 // Applies the vertical box layout to the form
75 Construct(formLayout, FORM_STYLE_NORMAL);
80 VerticalBoxLayoutSample::OnInitializing(void)
84 // Creates an instance of VerticalBoxLayout for the top panel
85 VerticalBoxLayout topPanelLayout;
86 topPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
88 // Creates an instance of Panel and applies it to the vertical box layout
89 Panel* pTopPanel = new Panel();
90 pTopPanel->Construct(topPanelLayout, Rectangle(0, 0, GetClientAreaBounds().width, 350));
92 // Creates instances of Label and a instance of Button
93 Label* pLabel1 = new Label();
94 pLabel1->Construct(Rectangle(0,0,150,80), L"RIGHT");
95 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
96 pTopPanel->AddControl(pLabel1);
98 Label* pLabel2 = new Label();
99 pLabel2->Construct(Rectangle(0,0,200,80), L"CENTER");
100 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
101 pTopPanel->AddControl(pLabel2);
103 Label* pLabel3 = new Label();
104 pLabel3->Construct(Rectangle(0,0,150,80), L"LEFT");
105 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
106 pTopPanel->AddControl(pLabel3);
108 Button* pButton = new Button();
109 pButton->Construct(Rectangle(0,0,150,80), "FIT TO PARENT");
110 pTopPanel->AddControl(pButton);
112 // Sets relations each label and button
113 topPanelLayout.SetHorizontalAlignment(*pLabel1, LAYOUT_HORIZONTAL_ALIGN_RIGHT);
114 topPanelLayout.SetHorizontalAlignment(*pLabel2, LAYOUT_HORIZONTAL_ALIGN_CENTER);
115 topPanelLayout.SetHorizontalAlignment(*pLabel3, LAYOUT_HORIZONTAL_ALIGN_LEFT);
116 topPanelLayout.SetSpacing(*pButton, 10);
117 topPanelLayout.SetHorizontalFitPolicy(*pButton, FIT_POLICY_PARENT);
120 // Adds the top panel to the form
121 AddControl(pTopPanel);
123 // Creates an instance of VerticalBoxLayout for the bottom panel
124 VerticalBoxLayout bottomPanelLayout;
125 bottomPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
127 // Creates an instance of Panel and applies it to the vertical box layout
128 Panel* pBottomPanel = new Panel();
129 pBottomPanel->Construct(bottomPanelLayout, Rectangle(0, 0, GetClientAreaBounds().width, 450));
131 // Creates instances of Label
132 Label* pLabel1 = new Label();
133 pLabel1->Construct(Rectangle(0,0,100,50), L"WEIGHT = 1.0f");
134 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
135 pBottomPanel->AddControl(pLabel1);
137 Label* pLabel2 = new Label();
138 pLabel2->Construct(Rectangle(0,0,100,50), L"WEIGHT = 2.0f");
139 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
140 pBottomPanel->AddControl(pLabel2);
142 Label* pLabel3 = new Label();
143 pLabel3->Construct(Rectangle(0,0,100,50), L"WEIGHT = 3.0f");
144 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
145 pBottomPanel->AddControl(pLabel3);
147 // Sets relations each label
148 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel1, FIT_POLICY_PARENT);
149 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel2, FIT_POLICY_PARENT);
150 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel3, FIT_POLICY_PARENT);
151 bottomPanelLayout.SetWeight(*pLabel1, 1.0f);
152 bottomPanelLayout.SetWeight(*pLabel2, 2.0f);
153 bottomPanelLayout.SetWeight(*pLabel3, 3.0f);
156 // Adds the bottom panel to the form
157 AddControl(pBottomPanel);
159 //Gets the layout of the form
160 VerticalBoxLayout* pFormLayout = dynamic_cast<VerticalBoxLayout*>(this->GetLayoutN());
162 // Sets relations between panels
163 pFormLayout->SetHorizontalFitPolicy(*pTopPanel, FIT_POLICY_PARENT);
164 pFormLayout->SetSpacing(*pBottomPanel, 50);
165 pFormLayout->SetHorizontalFitPolicy(*pBottomPanel, FIT_POLICY_PARENT);
172 class _OSP_EXPORT_ VerticalBoxLayout
177 * 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.
181 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
183 VerticalBoxLayout(void);
186 * This destructor overrides Tizen::Base::Object::~Object().
190 virtual ~VerticalBoxLayout(void);
193 * Initializes this instance of %VerticalBoxLayout with the specified parameter.
197 * @return An error code
198 * @param[in] direction The direction in which the children are attached
199 * @exception E_SUCCESS The method is successful.
200 * @exception E_INVALID_ARG The specified input parameter is invalid.
201 * @exception E_SYSTEM A system error has occurred.
203 result Construct(VerticalDirection direction);
206 * Gets the direction of %VerticalBoxLayout.
210 * @return An error code
211 * @param[out] direction The direction in which the children are attached
212 * @exception E_SUCCESS The method is successful.
214 result GetDirection(VerticalDirection& direction) const;
217 * Gets the type of the layout.
221 * @return The layout type
223 virtual LayoutType GetLayoutType(void) const;
226 * Sets the horizontal alignment of the specified control.
230 * @return An error code
231 * @param[in] childControl The control for which the alignment is set
232 * @param[in] alignment The horizontal alignment
233 * @exception E_SUCCESS The method is successful.
234 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
235 * @exception E_SYSTEM A system error has occurred.
236 * @remarks By default, the horizontal alignment is HORIZONTAL_ALIGNLEFT.
238 result SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment);
241 * Sets the space between the specified control and its predecessor.
245 * @return An error code
246 * @param[in] childControl The control for which the space is set
247 * @param[in] space The space
248 * @exception E_SUCCESS The method is successful.
249 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
250 * @exception E_SYSTEM A system error has occurred.
251 * @remarks By default, the spacing is set to @c 0.
253 result SetSpacing(Control& childControl, int space);
256 * Sets the space between a specified control and its predecessor.
260 * @return An error code
261 * @param[in] childControl The control for which the space is set
262 * @param[in] space The space
263 * @exception E_SUCCESS The method is successful.
264 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
265 * @exception E_SYSTEM A system error has occurred.
266 * @remarks By default, the spacing is set to @c 0.
268 result SetSpacing(Control& childControl, float space);
271 * Sets the horizontal margins of the specified control.
275 * @return An error code
276 * @param[in] childControl The control for which the margins are set
277 * @param[in] left The left margin
278 * @param[in] right The right margin
279 * @exception E_SUCCESS The method is successful.
280 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
281 * @exception E_SYSTEM A system error has occurred.
282 * @remarks By default, the margins are set to @c 0.
284 result SetHorizontalMargin(Control& childControl, int left, int right);
287 * Sets the horizontal margins of a specified control.
291 * @return An error code
292 * @param[in] childControl The control for which the margins are set
293 * @param[in] left The left margin
294 * @param[in] right The right margin
295 * @exception E_SUCCESS The method is successful.
296 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
297 * @exception E_SYSTEM A system error has occurred.
298 * @remarks By default, the margins are set to @c 0.
300 result SetHorizontalMargin(Control& childControl, float left, float right);
303 * Sets the width of the specified control with the fixed length.
307 * @return An error code
308 * @param[in] childControl The control for which the width is set
309 * @param[in] width The value of the width
310 * @exception E_SUCCESS The method is successful.
311 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
312 * @exception E_SYSTEM A system error has occurred.
314 result SetWidth(Control& childControl, int width);
317 * Sets the width of a specified control with the fixed length.
321 * @return An error code
322 * @param[in] childControl The control for which the width is set
323 * @param[in] width The value of the width
324 * @exception E_SUCCESS The method is successful.
325 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
326 * @exception E_SYSTEM A system error has occurred.
328 result SetWidth(Control& childControl, float width);
331 * Sets the width of the specified control with the fitting policy.
335 * @return An error code
336 * @param[in] childControl The control for which the width is set
337 * @param[in] policy The fitting policy for the width
338 * @exception E_SUCCESS The method is successful.
339 * @exception E_INVALID_ARG 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 with a fixed length.
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 @c childControl parameter is not a child of the container that owns the layout.
354 * @exception E_SYSTEM A system error has occurred.
356 result SetHeight(Control& childControl, int height);
359 * Sets the height of a specified control with a fixed length.
363 * @return An error code
364 * @param[in] childControl The control for which the height is set
365 * @param[in] height The value of the height
366 * @exception E_SUCCESS The method is successful.
367 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
368 * @exception E_SYSTEM A system error has occurred.
370 result SetHeight(Control& childControl, float height);
373 * Sets the height of the specified control with the fitting policy.
377 * @return An error code
378 * @param[in] childControl The control for which the height is set
379 * @param[in] policy The fitting policy for the height
380 * @exception E_SUCCESS The method is successful.
381 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
382 * @exception E_SYSTEM A system error has occurred.
383 * @remarks Setting FIT_POLICY_PARENT as @c policy does not cause the height of the control to change.
385 result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
388 * Sets the weight of the specified control.
392 * @return An error code
393 * @param[in] childControl The control for which the weight is set
394 * @param[in] weight The weight that indicates how much extra space the control occupies in proportion to it, in the %VerticalBoxLayout.
395 * @exception E_SUCCESS The method is successful.
396 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
397 * @exception E_SYSTEM A system error has occurred.
398 * @remarks By default, the weight is set to @c 0.0f.
400 result SetWeight(Control& childControl, float weight);
404 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
406 VerticalBoxLayout(const VerticalBoxLayout& rhs);
409 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
411 VerticalBoxLayout& operator =(const VerticalBoxLayout& rhs);
412 }; // VerticalBoxLayout
416 #endif // _FUI_VERTICAL_BOX_LAYOUT_H_