Tizen 2.1 base
[framework/osp/uifw.git] / inc / FUiVerticalBoxLayout.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file                FUiVerticalBoxLayout.h
20  * @brief               This is the header file for the %VerticalBoxLayout class.
21  *
22  * This header file contains the declarations of the %VerticalBoxLayout class.
23  */
24 #ifndef _FUI_VERTICAL_BOX_LAYOUT_H_
25 #define _FUI_VERTICAL_BOX_LAYOUT_H_
26
27 #include <FUiLayout.h>
28
29 namespace Tizen { namespace Ui
30 {
31 class Control;
32
33 /**
34  * @class       VerticalBoxLayout
35  * @brief       The vertical box layout positions the children of a container vertically.
36  *
37  * @since       2.0
38  *
39  * The %VerticalBoxLayout class defines the vertical box layout for a Container. The layout positions the children of the %Container vertically.
40  *
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>.
42  *
43  * @code
44 // Sample code for VerticalBoxLayoutSample.h
45 #include <FUi.h>
46
47 class VerticalBoxLayoutSample
48         : public Tizen::Ui::Controls::Form
49 {
50 public:
51         bool Initialize(void);
52         virtual result OnInitializing(void);
53 };
54  *      @endcode
55  *
56  *      @code
57 // Sample code for VerticalBoxLayoutSample.cpp
58 #include <FGraphics.h>
59
60 #include "VerticalBoxLayoutSample.h"
61
62 using namespace Tizen::Graphics;
63 using namespace Tizen::Ui;
64 using namespace Tizen::Ui::Controls;
65
66 bool
67 VerticalBoxLayoutSample::Initialize(void)
68 {
69         //Creates an instance of VerticalBoxLayout
70         VerticalBoxLayout formLayout;
71         formLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
72
73         // Applies the vertical box layout to the form
74         Construct(formLayout, FORM_STYLE_NORMAL);
75         return true;
76 }
77
78 result
79 VerticalBoxLayoutSample::OnInitializing(void)
80 {
81         result r = E_SUCCESS;
82
83         // Creates an instance of VerticalBoxLayout for the top panel
84         VerticalBoxLayout topPanelLayout;
85         topPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
86
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));
90         {
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);
96
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);
101
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);
106
107                 Button* pButton = new Button();
108                 pButton->Construct(Rectangle(0,0,150,80), "FIT TO PARENT");
109                 pTopPanel->AddControl(*pButton);
110
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);
117         }
118
119         // Adds the top panel to the form
120         AddControl(*pTopPanel);
121
122         // Creates an instance of VerticalBoxLayout for the bottom panel
123         VerticalBoxLayout bottomPanelLayout;
124         bottomPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
125
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));
129         {
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);
135
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);
140
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);
145
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);
153         }
154
155         // Adds the bottom panel to the form
156         AddControl(*pBottomPanel);
157
158         //Gets the layout of the form
159         VerticalBoxLayout* pFormLayout = dynamic_cast<VerticalBoxLayout*>(this->GetLayoutN());
160
161         // Sets relations between panels
162         pFormLayout->SetHorizontalFitPolicy(*pTopPanel, FIT_POLICY_PARENT);
163         pFormLayout->SetSpacing(*pBottomPanel, 50);
164         pFormLayout->SetHorizontalFitPolicy(*pBottomPanel, FIT_POLICY_PARENT);
165
166         return r;
167 }
168  * @endcode
169  *
170  */
171 class _OSP_EXPORT_ VerticalBoxLayout
172         : public Layout
173 {
174 public:
175         /**
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.
177          *
178          * @since               2.0
179          *
180          * @remarks     After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
181          */
182         VerticalBoxLayout(void);
183
184         /**
185          * This destructor overrides Tizen::Base::Object::~Object().
186          *
187          * @since               2.0
188          */
189         virtual ~VerticalBoxLayout(void);
190
191         /**
192          * Initializes this instance of %VerticalBoxLayout with the specified parameter.
193          *
194          * @since               2.0
195          *
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.
201          */
202         result Construct(VerticalDirection direction);
203
204         /**
205          * Gets the direction of the %VerticalBoxLayout.
206          *
207          * @since               2.0
208          *
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.
212          */
213         result GetDirection(VerticalDirection& direction) const;
214
215         /**
216          * Gets the type of the layout.
217          *
218          * @since       2.0
219          *
220          * @return      The layout type
221          */
222         virtual LayoutType GetLayoutType(void) const;
223
224         /**
225          * Sets the horizontal alignment of the specified control.
226          *
227          * @since               2.0
228          *
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.
236          */
237         result SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment);
238
239         /**
240          * Sets the space between the specified control and its predecessor.
241          *
242          * @since               2.0
243          *
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.
251          */
252         result SetSpacing(Control& childControl, int space);
253
254         /**
255          * Sets the horizontal margins of the specified control.
256          *
257          * @since               2.0
258          *
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.
267          */
268         result SetHorizontalMargin(Control& childControl, int left, int right);
269
270         /**
271          * Sets the width of the specified control with the fixed length.
272          *
273          * @since               2.0
274          *
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.
281          */
282         result SetWidth(Control& childControl, int width);
283
284         /**
285          * Sets the width of the specified control with the fitting policy.
286          *
287          * @since               2.0
288          *
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.
295          */
296         result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
297
298         /**
299          * Sets the height of the specified control with a fixed length.
300          *
301          * @since               2.0
302          *
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.
309          */
310         result SetHeight(Control& childControl, int height);
311
312         /**
313          * Sets the height of the specified control with the fitting policy.
314          *
315          * @since               2.0
316          *
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.
324          */
325         result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
326
327         /**
328          * Sets the weight of the specified control.
329          *
330          * @since               2.0
331          *
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.
339          */
340         result SetWeight(Control& childControl, float weight);
341
342 private:
343         //
344         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
345         //
346         VerticalBoxLayout(const VerticalBoxLayout& rhs);
347
348         //
349         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
350         //
351         VerticalBoxLayout& operator =(const VerticalBoxLayout& rhs);
352 }; // VerticalBoxLayout
353
354 }} // Tizen::Ui
355
356 #endif // _FUI_VERTICAL_BOX_LAYOUT_H_