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 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>.
44 // Sample code for VerticalBoxLayoutSample.h
47 class VerticalBoxLayoutSample
48 : public Tizen::Ui::Controls::Form
51 bool Initialize(void);
52 virtual result OnInitializing(void);
57 // Sample code for VerticalBoxLayoutSample.cpp
58 #include <FGraphics.h>
60 #include "VerticalBoxLayoutSample.h"
62 using namespace Tizen::Graphics;
63 using namespace Tizen::Ui;
64 using namespace Tizen::Ui::Controls;
67 VerticalBoxLayoutSample::Initialize(void)
69 //Creates an instance of VerticalBoxLayout
70 VerticalBoxLayout formLayout;
71 formLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
73 // Applies the vertical box layout to the form
74 Construct(formLayout, FORM_STYLE_NORMAL);
79 VerticalBoxLayoutSample::OnInitializing(void)
83 // Creates an instance of VerticalBoxLayout for the top panel
84 VerticalBoxLayout topPanelLayout;
85 topPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
87 // Creates an instance of Panel and applies it to the vertical box layout
88 Panel* pTopPanel = new Panel();
89 pTopPanel->Construct(topPanelLayout, Rectangle(0, 0, GetClientAreaBounds().width, 350));
91 // Creates instances of Label and a instance of Button
92 Label* pLabel1 = new Label();
93 pLabel1->Construct(Rectangle(0,0,150,80), L"RIGHT");
94 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
95 pTopPanel->AddControl(*pLabel1);
97 Label* pLabel2 = new Label();
98 pLabel2->Construct(Rectangle(0,0,200,80), L"CENTER");
99 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
100 pTopPanel->AddControl(*pLabel2);
102 Label* pLabel3 = new Label();
103 pLabel3->Construct(Rectangle(0,0,150,80), L"LEFT");
104 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
105 pTopPanel->AddControl(*pLabel3);
107 Button* pButton = new Button();
108 pButton->Construct(Rectangle(0,0,150,80), "FIT TO PARENT");
109 pTopPanel->AddControl(*pButton);
111 // Sets relations each label and button
112 topPanelLayout.SetHorizontalAlignment(*pLabel1, LAYOUT_HORIZONTAL_ALIGN_RIGHT);
113 topPanelLayout.SetHorizontalAlignment(*pLabel2, LAYOUT_HORIZONTAL_ALIGN_CENTER);
114 topPanelLayout.SetHorizontalAlignment(*pLabel3, LAYOUT_HORIZONTAL_ALIGN_LEFT);
115 topPanelLayout.SetSpacing(*pButton, 10);
116 topPanelLayout.SetHorizontalFitPolicy(*pButton, FIT_POLICY_PARENT);
119 // Adds the top panel to the form
120 AddControl(*pTopPanel);
122 // Creates an instance of VerticalBoxLayout for the bottom panel
123 VerticalBoxLayout bottomPanelLayout;
124 bottomPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
126 // Creates an instance of Panel and applies it to the vertial box layout
127 Panel* pBottomPanel = new Panel();
128 pBottomPanel->Construct(bottomPanelLayout, Rectangle(0, 0, GetClientAreaBounds().width, 450));
130 // Creates instances of Label
131 Label* pLabel1 = new Label();
132 pLabel1->Construct(Rectangle(0,0,100,50), L"WEIGHT = 1.0f");
133 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
134 pBottomPanel->AddControl(*pLabel1);
136 Label* pLabel2 = new Label();
137 pLabel2->Construct(Rectangle(0,0,100,50), L"WEIGHT = 2.0f");
138 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
139 pBottomPanel->AddControl(*pLabel2);
141 Label* pLabel3 = new Label();
142 pLabel3->Construct(Rectangle(0,0,100,50), L"WEIGHT = 3.0f");
143 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
144 pBottomPanel->AddControl(*pLabel3);
146 // Sets relations each label
147 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel1, FIT_POLICY_PARENT);
148 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel2, FIT_POLICY_PARENT);
149 bottomPanelLayout.SetHorizontalFitPolicy(*pLabel3, FIT_POLICY_PARENT);
150 bottomPanelLayout.SetWeight(*pLabel1, 1.0f);
151 bottomPanelLayout.SetWeight(*pLabel2, 2.0f);
152 bottomPanelLayout.SetWeight(*pLabel3, 3.0f);
155 // Adds the bottom panel to the form
156 AddControl(*pBottomPanel);
158 //Gets the layout of the form
159 VerticalBoxLayout* pFormLayout = dynamic_cast<VerticalBoxLayout*>(this->GetLayoutN());
161 // Sets relations between panels
162 pFormLayout->SetHorizontalFitPolicy(*pTopPanel, FIT_POLICY_PARENT);
163 pFormLayout->SetSpacing(*pBottomPanel, 50);
164 pFormLayout->SetHorizontalFitPolicy(*pBottomPanel, FIT_POLICY_PARENT);
171 class _OSP_EXPORT_ VerticalBoxLayout
176 * 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.
180 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
182 VerticalBoxLayout(void);
185 * This destructor overrides Tizen::Base::Object::~Object().
189 virtual ~VerticalBoxLayout(void);
192 * Initializes this instance of %VerticalBoxLayout with the specified parameter.
196 * @return An error code
197 * @param[in] direction The direction in which the children are attached
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_INVALID_ARG The specified input parameter is invalid.
200 * @exception E_SYSTEM A system error has occurred.
202 result Construct(VerticalDirection direction);
205 * Gets the direction of the %VerticalBoxLayout.
209 * @return An error code
210 * @param[out] direction The direction in which the children are attached
211 * @exception E_SUCCESS The method is successful.
213 result GetDirection(VerticalDirection& direction) const;
216 * Gets the type of the layout.
220 * @return The layout type
222 virtual LayoutType GetLayoutType(void) const;
225 * Sets the horizontal alignment of the specified control.
229 * @return An error code
230 * @param[in] childControl The control for which the alignment is set
231 * @param[in] alignment The horizontal alignment
232 * @exception E_SUCCESS The method is successful.
233 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
234 * @exception E_SYSTEM A system error has occurred.
235 * @remarks By default, the horizontal alignment is HORIZONTAL_ALIGNLEFT.
237 result SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment);
240 * Sets the space between the specified control and its predecessor.
244 * @return An error code
245 * @param[in] childControl The control for which the space is set
246 * @param[in] space The space
247 * @exception E_SUCCESS The method is successful.
248 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
249 * @exception E_SYSTEM A system error has occurred.
250 * @remarks By default, the spacing is set to @c 0.
252 result SetSpacing(Control& childControl, int space);
255 * Sets the horizontal margins of the specified control.
259 * @return An error code
260 * @param[in] childControl The control for which the margins are set
261 * @param[in] left The left margin
262 * @param[in] right The right margin
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 margins are set to @c 0.
268 result SetHorizontalMargin(Control& childControl, int left, int right);
271 * Sets the width of the specified control with the fixed length.
275 * @return An error code
276 * @param[in] childControl The control for which the width is set
277 * @param[in] width The value of the width
278 * @exception E_SUCCESS The method is successful.
279 * @exception E_INVALID_ARG 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 SetWidth(Control& childControl, int width);
285 * Sets the width of the specified control with the fitting policy.
289 * @return An error code
290 * @param[in] childControl The control for which the width is set
291 * @param[in] policy The fitting policy for the width
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
294 * @exception E_SYSTEM A system error has occurred.
296 result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
299 * Sets the height of the specified control with a fixed length.
303 * @return An error code
304 * @param[in] childControl The control for which the height is set
305 * @param[in] height The value of the height
306 * @exception E_SUCCESS The method is successful.
307 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
308 * @exception E_SYSTEM A system error has occurred.
310 result SetHeight(Control& childControl, int height);
313 * Sets the height of the specified control with the fitting policy.
317 * @return An error code
318 * @param[in] childControl The control for which the height is set
319 * @param[in] policy The fitting policy for the height
320 * @exception E_SUCCESS The method is successful.
321 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
322 * @exception E_SYSTEM A system error has occurred.
323 * @remarks Setting FIT_POLICY_PARENT as @c policy does not cause the height of the control to change.
325 result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
328 * Sets the weight of the specified control.
332 * @return An error code
333 * @param[in] childControl The control for which the weight is set
334 * @param[in] weight The weight that indicates how much extra space the control occupies in proportion to it, in the %VerticalBoxLayout.
335 * @exception E_SUCCESS The method is successful.
336 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
337 * @exception E_SYSTEM A system error has occurred.
338 * @remarks By default, the weight is set to @c 0.0f.
340 result SetWeight(Control& childControl, float weight);
344 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
346 VerticalBoxLayout(const VerticalBoxLayout& rhs);
349 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
351 VerticalBoxLayout& operator =(const VerticalBoxLayout& rhs);
352 }; // VerticalBoxLayout
356 #endif // _FUI_VERTICAL_BOX_LAYOUT_H_