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 FUiHorizontalBoxLayout.h
20 * @brief This is the header file for the %HorizontalBoxLayout class.
22 * This header file contains the declarations of the %HorizontalBoxLayout class.
25 #ifndef _FUI_HORIZONTAL_BOX_LAYOUT_H_
26 #define _FUI_HORIZONTAL_BOX_LAYOUT_H_
28 #include <FUiLayout.h>
30 namespace Tizen { namespace Ui
35 * @class HorizontalBoxLayout
36 * @brief The horizontal box layout positions the children of a container horizontally.
40 * The %HorizontalBoxLayout class defines the horizontal box layout for a Container. The layout positions the children of the %Container horizontally.
42 * 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>.
45 // Sample code for HorizontalBoxLayoutSample.h
48 class HorizontalBoxLayoutSample
49 : public Tizen::Ui::Controls::Form
52 bool Initialize(void);
53 virtual result OnInitializing(void);
58 // Sample code for HorizontalBoxLayoutSample.cpp
59 #include <FGraphics.h>
61 #include "HorizontalBoxLayoutSample.h"
63 using namespace Tizen::Ui::Controls;
64 using namespace Tizen::Ui;
65 using namespace Tizen::Graphics;
68 HorizontalBoxLayoutSample::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 HorizontalBoxLayoutSample::OnInitializing(void)
84 // Creates an instance of HorizontalBoxLayout for the top panel
85 HorizontalBoxLayout topPanelLayout;
86 topPanelLayout.Construct(HORIZONTAL_DIRECTION_RIGHTWARD);
88 // Creates an instance of Panel and applies it to the horizontal box layout
89 Panel* pTopPanel = new Panel();
90 pTopPanel->Construct(topPanelLayout, Rectangle(0, 0, GetClientAreaBounds().width, 450));
92 // Creates instances of Label and an instance of Button
93 Label* pLabel1 = new Label();
94 pLabel1->Construct(Rectangle(0,0,GetClientAreaBounds().width/4,100), L"TOP");
95 pLabel1->SetTextConfig(20, LABEL_TEXT_STYLE_NORMAL);
96 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
97 pTopPanel->AddControl(pLabel1);
99 Label* pLabel2 = new Label();
100 pLabel2->Construct(Rectangle(0,0,GetClientAreaBounds().width/4,100), L"MIDDLE");
101 pLabel2->SetTextConfig(20, LABEL_TEXT_STYLE_NORMAL);
102 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
103 pTopPanel->AddControl(pLabel2);
105 Label* pLabel3 = new Label();
106 pLabel3->Construct(Rectangle(0,0,GetClientAreaBounds().width/4,100), L"BOTTOM");
107 pLabel3->SetTextConfig(20, LABEL_TEXT_STYLE_NORMAL);
108 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
109 pTopPanel->AddControl(pLabel3);
111 Button* pButton = new Button();
112 pButton->Construct(Rectangle(0,0,GetClientAreaBounds().width/4 - 10,100), L"FIT\nTO\nPARENT");
113 pButton->SetTextSize(20);
114 pTopPanel->AddControl(pButton);
116 // Sets relations each label and button
117 topPanelLayout.SetVerticalAlignment(*pLabel1, LAYOUT_VERTICAL_ALIGN_TOP);
118 topPanelLayout.SetVerticalAlignment(*pLabel2, LAYOUT_VERTICAL_ALIGN_MIDDLE);
119 topPanelLayout.SetVerticalAlignment(*pLabel3, LAYOUT_VERTICAL_ALIGN_BOTTOM);
120 topPanelLayout.SetSpacing(*pButton, 10);
121 topPanelLayout.SetVerticalFitPolicy(*pButton, FIT_POLICY_PARENT);
123 // Adds the top panel to the form
124 AddControl(pTopPanel);
126 // Creates an instance of HorizontalBoxLayout for bottom panel
127 HorizontalBoxLayout bottomPanelLayout;
128 bottomPanelLayout.Construct(HORIZONTAL_DIRECTION_RIGHTWARD);
130 // Creates an instance of Panel and applies it to the horizontal box layout
131 Panel* pBottomPanel = new Panel();
132 pBottomPanel->Construct(bottomPanelLayout, Rectangle(0, 0, 400, 500));
134 // Creates instances of Label
135 Label* pLabel1 = new Label();
136 pLabel1->Construct(Rectangle(0,0,30,100), L"W\n1.0f");
137 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
138 pBottomPanel->AddControl(pLabel1);
140 Label* pLabel2 = new Label();
141 pLabel2->Construct(Rectangle(0,0,30,100), L"W\n2.0f");
142 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
143 pBottomPanel->AddControl(pLabel2);
145 Label* pLabel3 = new Label();
146 pLabel3->Construct(Rectangle(0,0,30,100), L"W\n3.0f");
147 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
148 pBottomPanel->AddControl(pLabel3);
150 // Sets relations each label
151 bottomPanelLayout.SetVerticalFitPolicy(*pLabel1, FIT_POLICY_PARENT);
152 bottomPanelLayout.SetVerticalFitPolicy(*pLabel2, FIT_POLICY_PARENT);
153 bottomPanelLayout.SetVerticalFitPolicy(*pLabel3, FIT_POLICY_PARENT);
154 bottomPanelLayout.SetWeight(*pLabel1, 1.0f);
155 bottomPanelLayout.SetWeight(*pLabel2, 2.0f);
156 bottomPanelLayout.SetWeight(*pLabel3, 3.0f);
159 // Adds the bottom panel to the form
160 AddControl(pBottomPanel);
162 //Gets the layout of the form
163 VerticalBoxLayout* pFormLayout = dynamic_cast<VerticalBoxLayout*>(this->GetLayoutN());
165 // Sets relations between panels
166 pFormLayout->SetHorizontalFitPolicy(*pTopPanel, FIT_POLICY_PARENT);
167 pFormLayout->SetSpacing(*pBottomPanel, 30);
168 pFormLayout->SetHorizontalFitPolicy(*pBottomPanel, FIT_POLICY_PARENT);
176 class _OSP_EXPORT_ HorizontalBoxLayout
181 * 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.
185 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
187 HorizontalBoxLayout(void);
190 * This destructor overrides Tizen::Base::Object::~Object().
194 virtual ~HorizontalBoxLayout(void);
197 * Initializes this instance of %HorizontalBoxLayout with the specified parameter.
201 * @return An error code
202 * @param[in] direction The direction in which the children are attached
203 * @exception E_SUCCESS The method is successful.
204 * @exception E_INVALID_ARG The specified input parameter is invalid.
205 * @exception E_SYSTEM A system error has occurred.
207 result Construct(HorizontalDirection direction);
210 * Gets the direction of %HorizontalBoxLayout.
214 * @return An error code
215 * @param[out] direction The direction in which the children are attached
216 * @exception E_SUCCESS The method is successful.
218 result GetDirection(HorizontalDirection& direction) const;
221 * Gets the type of the layout.
225 * @return The layout type
227 virtual LayoutType GetLayoutType(void) const;
230 * Sets the vertical alignment of the specified control.
234 * @return An error code
235 * @param[in] childControl The control for which the alignment is set
236 * @param[in] alignment The vertical alignment
237 * @exception E_SUCCESS The method is successful.
238 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
239 * @exception E_SYSTEM A system error has occurred.
240 * @remarks By default, the horizontal alignment is VERTICAL_ALIGN_TOP.
242 result SetVerticalAlignment(Control& childControl, LayoutVerticalAlignment alignment);
245 * Sets the space between the specified control and its predecessor.
249 * @return An error code
250 * @param[in] childControl The control for which the space is set
251 * @param[in] space The space
252 * @exception E_SUCCESS The method is successful.
253 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
254 * @exception E_SYSTEM A system error has occurred.
255 * @remarks By default, the spacing is set to @c 0.
257 result SetSpacing(Control& childControl, int space);
260 * Sets the space between the specified control and its predecessor.
264 * @return An error code
265 * @param[in] childControl The control for which the space is set
266 * @param[in] space The space
267 * @exception E_SUCCESS The method is successful.
268 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
269 * @exception E_SYSTEM A system error has occurred.
270 * @remarks By default, the spacing is set to @c 0.
272 result SetSpacing(Control& childControl, float space);
275 * Sets the vertical margins of the specified control.
279 * @return An error code
280 * @param[in] childControl The control for which the margins are set
281 * @param[in] top The top margin
282 * @param[in] bottom The bottom margin
283 * @exception E_SUCCESS The method is successful.
284 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
285 * @exception E_SYSTEM A system error has occurred.
286 * @remarks By default, the margins are set to @c 0.
288 result SetVerticalMargin(Control& childControl, int top, int bottom);
291 * Sets the vertical margins of the specified control.
295 * @return An error code
296 * @param[in] childControl The control for which the margins are set
297 * @param[in] top The top margin
298 * @param[in] bottom The bottom margin
299 * @exception E_SUCCESS The method is successful.
300 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
301 * @exception E_SYSTEM A system error has occurred.
302 * @remarks By default, the margins are set to @c 0.
304 result SetVerticalMargin(Control& childControl, float top, float bottom);
307 * Sets the width of the specified control with the fixed length.
311 * @return An error code
312 * @param[in] childControl The control for which the width is set
313 * @param[in] width The value of the width
314 * @exception E_SUCCESS The method is successful.
315 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
316 * @exception E_SYSTEM A system error has occurred.
318 result SetWidth(Control& childControl, int width);
321 * Sets the width of the specified control with the fixed length.
325 * @return An error code
326 * @param[in] childControl The control for which the width is set
327 * @param[in] width The value of the width
328 * @exception E_SUCCESS The method is successful.
329 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
330 * @exception E_SYSTEM A system error has occurred.
332 result SetWidth(Control& childControl, float width);
335 * Sets the width of the specified control with the fitting policy.
339 * @return An error code
340 * @param[in] childControl The control for which the width is set
341 * @param[in] policy The fitting policy for the width
342 * @exception E_SUCCESS The method is successful.
343 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
344 * @exception E_SYSTEM A system error has occurred.
345 * @remarks Setting FIT_POLICY_PARENT as @c policy does not cause the width of control to change.
347 result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
350 * Sets the height of the specified control with a fixed length.
354 * @return An error code
355 * @param[in] childControl The control for which the height is set
356 * @param[in] height The value of the height
357 * @exception E_SUCCESS The method is successful.
358 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
359 * @exception E_SYSTEM A system error has occurred.
361 result SetHeight(Control& childControl, int height);
364 * Sets the height of the specified control with a fixed length.
368 * @return An error code
369 * @param[in] childControl The control for which the height is set
370 * @param[in] height The value of the height
371 * @exception E_SUCCESS The method is successful.
372 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
373 * @exception E_SYSTEM A system error has occurred.
375 result SetHeight(Control& childControl, float height);
378 * Sets the height of the specified control with the fitting policy.
382 * @return An error code
383 * @param[in] childControl The control for which the height is set
384 * @param[in] policy The fitting policy for the height
385 * @exception E_SUCCESS The method is successful.
386 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
387 * @exception E_SYSTEM A system error has occurred.
389 result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
392 * Sets the weight of the specified control.
396 * @return An error code
397 * @param[in] childControl The control for which the weight is set
398 * @param[in] weight The weight that indicates how much extra space the control occupies in proportion to it, in the %HorizontalBoxLayout
399 * @exception E_SUCCESS The method is successful.
400 * @exception E_INVALID_ARG The specified @c childControl parameter is not a child of the container that owns the layout.
401 * @exception E_SYSTEM A system error has occurred.
402 * @remarks By default, the weight is set to @c 0.0f.
404 result SetWeight(Control& childControl, float weight);
408 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
410 HorizontalBoxLayout(const HorizontalBoxLayout& rhs);
413 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
415 HorizontalBoxLayout& operator =(const HorizontalBoxLayout& rhs);
416 }; // HorizontalBoxLayout
420 #endif // _FUI_HORIZONTAL_BOX_LAYOUT_H_