Fix to adjust the position of the partial Frame
[platform/framework/native/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  * The following examples demonstrate how to use the %VerticalBoxLayout class.
44  * @code
45 // Sample code for VerticalBoxLayoutSample.h
46 #include <FUi.h>
47
48 class VerticalBoxLayoutSample
49         : public Tizen::Ui::Controls::Form
50 {
51 public:
52         bool Initialize(void);
53         virtual result OnInitializing(void);
54 };
55  *      @endcode
56  *
57  *      @code
58 // Sample code for VerticalBoxLayoutSample.cpp
59 #include <FGraphics.h>
60
61 #include "VerticalBoxLayoutSample.h"
62
63 using namespace Tizen::Graphics;
64 using namespace Tizen::Ui;
65 using namespace Tizen::Ui::Controls;
66
67 bool
68 VerticalBoxLayoutSample::Initialize(void)
69 {
70         //Creates an instance of VerticalBoxLayout
71         VerticalBoxLayout formLayout;
72         formLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
73
74         // Applies the vertical box layout to the form
75         Construct(formLayout, FORM_STYLE_NORMAL);
76         return true;
77 }
78
79 result
80 VerticalBoxLayoutSample::OnInitializing(void)
81 {
82         result r = E_SUCCESS;
83
84         // Creates an instance of VerticalBoxLayout for the top panel
85         VerticalBoxLayout topPanelLayout;
86         topPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
87
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));
91         {
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);
97
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);
102
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);
107
108                 Button* pButton = new Button();
109                 pButton->Construct(Rectangle(0,0,150,80), "FIT TO PARENT");
110                 pTopPanel->AddControl(*pButton);
111
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);
118         }
119
120         // Adds the top panel to the form
121         AddControl(*pTopPanel);
122
123         // Creates an instance of VerticalBoxLayout for the bottom panel
124         VerticalBoxLayout bottomPanelLayout;
125         bottomPanelLayout.Construct(VERTICAL_DIRECTION_DOWNWARD);
126
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));
130         {
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);
136
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);
141
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);
146
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);
154         }
155
156         // Adds the bottom panel to the form
157         AddControl(*pBottomPanel);
158
159         //Gets the layout of the form
160         VerticalBoxLayout* pFormLayout = dynamic_cast<VerticalBoxLayout*>(this->GetLayoutN());
161
162         // Sets relations between panels
163         pFormLayout->SetHorizontalFitPolicy(*pTopPanel, FIT_POLICY_PARENT);
164         pFormLayout->SetSpacing(*pBottomPanel, 50);
165         pFormLayout->SetHorizontalFitPolicy(*pBottomPanel, FIT_POLICY_PARENT);
166
167         return r;
168 }
169  * @endcode
170  *
171  */
172 class _OSP_EXPORT_ VerticalBoxLayout
173         : public Layout
174 {
175 public:
176         /**
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.
178          *
179          * @since               2.0
180          *
181          * @remarks     After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
182          */
183         VerticalBoxLayout(void);
184
185         /**
186          * This destructor overrides Tizen::Base::Object::~Object().
187          *
188          * @since               2.0
189          */
190         virtual ~VerticalBoxLayout(void);
191
192         /**
193          * Initializes this instance of %VerticalBoxLayout with the specified parameter.
194          *
195          * @since               2.0
196          *
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.
202          */
203         result Construct(VerticalDirection direction);
204
205         /**
206          * Gets the direction of %VerticalBoxLayout.
207          *
208          * @since               2.0
209          *
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.
213          */
214         result GetDirection(VerticalDirection& direction) const;
215
216         /**
217          * Gets the type of the layout.
218          *
219          * @since       2.0
220          *
221          * @return      The layout type
222          */
223         virtual LayoutType GetLayoutType(void) const;
224
225         /**
226          * Sets the horizontal alignment of the specified control.
227          *
228          * @since               2.0
229          *
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.
237          */
238         result SetHorizontalAlignment(Control& childControl, LayoutHorizontalAlignment alignment);
239
240         /**
241          * Sets the space between the specified control and its predecessor.
242          *
243          * @since               2.0
244          *
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.
252          */
253         result SetSpacing(Control& childControl, int space);
254
255         /**
256          * Sets the space between the specified control and its predecessor.
257          *
258          * @since               2.1
259          *
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.
267          */
268         result SetSpacing(Control& childControl, float space);
269
270         /**
271          * Sets the horizontal margins of the specified control.
272          *
273          * @since               2.0
274          *
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.
283          */
284         result SetHorizontalMargin(Control& childControl, int left, int right);
285
286         /**
287          * Sets the horizontal margins of the specified control.
288          *
289          * @since               2.1
290          *
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.
299          */
300         result SetHorizontalMargin(Control& childControl, float left, float right);
301
302         /**
303          * Sets the width of the specified control with the fixed length.
304          *
305          * @since               2.0
306          *
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.
313          */
314         result SetWidth(Control& childControl, int width);
315
316         /**
317          * Sets the width of the specified control with the fixed length.
318          *
319          * @since               2.1
320          *
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.
327          */
328         result SetWidth(Control& childControl, float width);
329
330         /**
331          * Sets the width of the specified control with the fitting policy.
332          *
333          * @since               2.0
334          *
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.
341          */
342         result SetHorizontalFitPolicy(Control& childControl, FitPolicy policy);
343
344         /**
345          * Sets the height of the specified control with a fixed length.
346          *
347          * @since               2.0
348          *
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.
355          */
356         result SetHeight(Control& childControl, int height);
357
358         /**
359          * Sets the height of the specified control with a fixed length.
360          *
361          * @since               2.1
362          *
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.
369          */
370         result SetHeight(Control& childControl, float height);
371
372         /**
373          * Sets the height of the specified control with the fitting policy.
374          *
375          * @since               2.0
376          *
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.
384          */
385         result SetVerticalFitPolicy(Control& childControl, FitPolicy policy);
386
387         /**
388          * Sets the weight of the specified control.
389          *
390          * @since               2.0
391          *
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.
399          */
400         result SetWeight(Control& childControl, float weight);
401
402 private:
403         //
404         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
405         //
406         VerticalBoxLayout(const VerticalBoxLayout& rhs);
407
408         //
409         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
410         //
411         VerticalBoxLayout& operator =(const VerticalBoxLayout& rhs);
412 }; // VerticalBoxLayout
413
414 }} // Tizen::Ui
415
416 #endif // _FUI_VERTICAL_BOX_LAYOUT_H_