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 FUiGridLayout.h
20 * @brief This is the header file for the %GridLayout class.
22 * This header file contains the declarations of the %GridLayout class.
25 #ifndef _FUI_GRID_LAYOUT_H_
26 #define _FUI_GRID_LAYOUT_H_
28 #include <FUiLayout.h>
30 namespace Tizen { namespace Ui
36 * @brief The grid layout positions the children of a container in a rectangular grid.
40 * The %GridLayout class defines the grid layout for a Container. The layout positions the children of the %Container in a rectangular grid.
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/grid_layout.htm">Grid Layout</a>.
45 // Sample code for GridLayoutSample.h
48 class GridLayoutSample
49 : public Tizen::Ui::Controls::Form
52 bool Initialize(void);
53 virtual result OnInitializing(void);
58 // Sample code for GridLayoutSample.cpp
59 #include <FGraphics.h>
61 #include "GridLayoutSample.h"
63 using namespace Tizen::Graphics;
64 using namespace Tizen::Ui;
65 using namespace Tizen::Ui::Controls;
68 GridLayoutSample::Initialize(void)
70 Construct(FORM_STYLE_NORMAL);
75 GridLayoutSample::OnInitializing(void)
79 // Creates an instance of GridLayout
80 GridLayout gridPanelLayout;
81 gridPanelLayout.Construct(2, 3);
83 // Creates an instance of Panel and applies it to grid layout
84 Panel* pPanel = new Panel();
85 pPanel->Construct(gridPanelLayout, Rectangle((GetClientAreaBounds().width - 440)/2, (GetClientAreaBounds().height - 700)/2, 440, 700));
87 // Creates instances of Label and an instanceo of Button
88 Label* pLabel1 = new Label();
89 pLabel1->Construct(Rectangle(0, 0, 100, 200), L"Label1\n(0, 0)");
90 pLabel1->SetBackgroundColor(Color(0x00, 0x10, 0x80, 0xFF));
91 pPanel->AddControl(*pLabel1);
93 Label* pLabel2 = new Label();
94 pLabel2->Construct(Rectangle(0, 0, 100, 200), L"Label2\n(0, 1)");
95 pLabel2->SetBackgroundColor(Color(0x00, 0x20, 0xA0, 0xFF));
96 pPanel->AddControl(*pLabel2);
98 Label* pLabel3 = new Label();
99 pLabel3->Construct(Rectangle(0, 0, 100, 200), L"Label3\n(0, 2)");
100 pLabel3->SetBackgroundColor(Color(0x00, 0x30, 0xC0, 0xFF));
101 pPanel->AddControl(*pLabel3);
103 Label* pLabel4 = new Label();
104 pLabel4->Construct(Rectangle(0, 0, 100, 200), L"Label4\n(1, 0)");
105 pLabel4->SetBackgroundColor(Color(0x00, 0x40, 0xE0, 0xFF));
106 pPanel->AddControl(*pLabel4);
108 Button* pButton = new Button();
109 pButton->Construct(Rectangle(0, 0, 100, 200), L"Button\n(1, 1)");
110 pPanel->AddControl(*pButton);
112 // Sets position to each label and button in grid layout
113 gridPanelLayout.SetPosition(*pLabel1, 0, 0, 1, 1);
114 gridPanelLayout.SetPosition(*pLabel2, 0, 1, 1, 1);
115 gridPanelLayout.SetPosition(*pLabel3, 0, 2, 1, 1);
116 gridPanelLayout.SetPosition(*pLabel4, 1, 0, 1, 1);
117 gridPanelLayout.SetPosition(*pButton, 1, 1, 1, 2);
119 // Sets stretchability each label and button in grid layout
120 gridPanelLayout.SetColumnStretchable(0, true);
121 gridPanelLayout.SetColumnStretchable(1, true);
122 gridPanelLayout.SetColumnStretchable(2, true);
123 gridPanelLayout.SetRowStretchable(1, true);
126 gridPanelLayout.SetColumnSpacing(1, 10);
127 gridPanelLayout.SetRowSpacing(1, 10);
130 // Adds the top panel to the form
139 class _OSP_EXPORT_ GridLayout
144 * 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.
148 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
153 * This destructor overrides Tizen::Base::Object::~Object().
157 virtual ~GridLayout(void);
160 * Initializes this instance of %GridLayout with the specified parameters.
164 * @return An error code
165 * @param[in] rowCount The number of rows
166 * @param[in] columnCount The number of columns
167 * @exception E_SUCCESS The method is successful.
168 * @exception E_INVALID_ARG The specified index is out of range. @n
169 * Either @c rowCount or @c columnCount is @c 0 or negative.
170 * @exception E_SYSTEM A system error has occurred.
172 result Construct(int rowCount, int columnCount);
175 * Gets the type of the layout.
179 * @return The layout type
181 virtual LayoutType GetLayoutType(void) const;
184 * Gets the number of rows in a grid layout.
188 * @return The number of rows
189 * @exception E_SUCCESS The method is successful.
190 * @remarks The specific error code can be accessed using the GetLastResult() method.
192 int GetRowCount(void) const;
195 * Gets the number of columns in a grid layout.
199 * @return The number of columns
200 * @exception E_SUCCESS The method is successful.
201 * @remarks The specific error code can be accessed using the GetLastResult() method.
203 int GetColumnCount(void) const;
206 * Sets the stretching ability of the specified column.
210 * @return An error code
211 * @param[in] columnIndex The column index
212 * @param[in] stretchable Set to @c true to make the column stretchable, @n
214 * @exception E_SUCCESS The method is successful.
215 * @exception E_OUT_OF_RANGE The specified index is out of range.
216 * @exception E_SYSTEM A system error has occurred.
218 result SetColumnStretchable(int columnIndex, bool stretchable);
221 * Sets the shrinking ability of the specified column.
225 * @return An error code
226 * @param[in] columnIndex The column index
227 * @param[in] shrinkable Set to @c true to make the column shrinkable, @n
229 * @exception E_SUCCESS The method is successful.
230 * @exception E_OUT_OF_RANGE The specified index is out of range.
231 * @exception E_SYSTEM A system error has occurred.
233 result SetColumnShrinkable(int columnIndex, bool shrinkable);
236 * Sets the collapsibility of a column.
240 * @return An error code
241 * @param[in] columnIndex The column index
242 * @param[in] collapsed Set to @c true to make the column collapsible, @n
244 * @exception E_SUCCESS The method is successful.
245 * @exception E_OUT_OF_RANGE The specified index is out of range.
246 * @exception E_SYSTEM A system error has occurred.
248 result SetColumnCollapsed(int columnIndex, bool collapsed);
251 * Sets the stretching ability of all the columns.
255 * @return An error code
256 * @param[in] stretchable Set to @c true to set all columns as stretchable, @n
258 * @exception E_SUCCESS The method is successful.
259 * @exception E_SYSTEM A system error has occurred.
261 result SetAllColumnsStretchable(bool stretchable);
264 * Sets the shrinking ability of all the columns.
268 * @return An error code
269 * @param[in] shrinkable Set to @c true to set all columns as shrinkable, @n
271 * @exception E_SUCCESS The method is successful.
272 * @exception E_SYSTEM A system error has occurred.
274 result SetAllColumnsShrinkable(bool shrinkable);
277 * Sets the space before the specified column index.
281 * @return An error code
282 * @param[in] columnIndex The column index
283 * @param[in] space An @c int representing the space
284 * @exception E_SUCCESS The method is successful.
285 * @exception E_INVALID_ARG The specified input parameter is invalid.
286 * @exception E_OUT_OF_RANGE The specified index is out of range.
287 * @exception E_SYSTEM A system error has occurred.
288 * @remarks This method does not perform any operation if the value of @c columnIndex is 0.
289 * @remarks The column spacing cannot be applied to the first column.
291 result SetColumnSpacing(int columnIndex, int space);
294 * Sets the space before the specified column index.
298 * @return An error code
299 * @param[in] columnIndex The column index
300 * @param[in] space An @c int representing the space
301 * @exception E_SUCCESS The method is successful.
302 * @exception E_INVALID_ARG The specified input parameter is invalid.
303 * @exception E_OUT_OF_RANGE The specified index is out of range.
304 * @exception E_SYSTEM A system error has occurred.
305 * @remarks This method does not perform any operation if the value of @c columnIndex is 0.
306 * @remarks The column spacing cannot be applied to the first column.
308 result SetColumnSpacing(int columnIndex, float space);
311 * Sets the stretching ability of the specified row.
315 * @return An error code
316 * @param[in] rowIndex The row index
317 * @param[in] stretchable Set to @c true to make the row stretchable, @n
319 * @exception E_SUCCESS The method is successful.
320 * @exception E_OUT_OF_RANGE The specified index is out of range.
321 * @exception E_SYSTEM A system error has occurred.
323 result SetRowStretchable(int rowIndex, bool stretchable);
326 * Sets the shrinking ability of the specified row.
330 * @return An error code
331 * @param[in] rowIndex The row index
332 * @param[in] shrinkable Set to @c true to make the row shrinkable, @n
334 * @exception E_SUCCESS The method is successful.
335 * @exception E_OUT_OF_RANGE The specified index is out of range.
336 * @exception E_SYSTEM A system error has occurred.
338 result SetRowShrinkable(int rowIndex, bool shrinkable);
341 * Sets the collapsibility of the specified row.
345 * @return An error code
346 * @param[in] rowIndex The row index
347 * @param[in] collapsed Set to @c true to make the row as collapsible, @n
349 * @exception E_SUCCESS The method is successful.
350 * @exception E_OUT_OF_RANGE The specified index is out of range.
351 * @exception E_SYSTEM A system error has occurred.
353 result SetRowCollapsed(int rowIndex, bool collapsed);
356 * Sets the stretching ability of all the rows.
360 * @return An error code
361 * @param[in] stretchable Set to @c true to set all the rows as stretchable, @n
363 * @exception E_SUCCESS The method is successful.
364 * @exception E_SYSTEM A system error has occurred.
366 result SetAllRowsStretchable(bool stretchable);
369 * Sets the shrinking ability of all the rows.
373 * @return An error code
374 * @param[in] shrinkable Set to @c true to set all the rows as shrinkable, @n
376 * @exception E_SUCCESS The method is successful.
377 * @exception E_SYSTEM A system error has occurred.
379 result SetAllRowsShrinkable(bool shrinkable);
382 * Sets the space before the specified column index.
386 * @return An error code
387 * @param[in] rowIndex The row index
388 * @param[in] space An @c int representing the space
389 * @exception E_SUCCESS The method is successful.
390 * @exception E_INVALID_ARG The specified input parameter is invalid.
391 * @exception E_OUT_OF_RANGE The specified index is out of range.
392 * @exception E_SYSTEM A system error has occurred.
393 * @remarks This method does not perform any operation if the value of @c rowIndex is @c 0.
394 * @remarks The row spacing cannot be applied to the first column.
396 result SetRowSpacing(int rowIndex, int space);
399 * Sets the space before the specified column index.
403 * @return An error code
404 * @param[in] rowIndex The row index
405 * @param[in] space An @c int representing the space
406 * @exception E_SUCCESS The method is successful.
407 * @exception E_INVALID_ARG The specified input parameter is invalid.
408 * @exception E_OUT_OF_RANGE The specified index is out of range.
409 * @exception E_SYSTEM A system error has occurred.
410 * @remarks This method does not perform any operation if the value of @c rowIndex is @c 0.
411 * @remarks The row spacing cannot be applied to the first column.
413 result SetRowSpacing(int rowIndex, float space);
416 * Sets the position and span of the control. @n
417 * Adds the control at the specified position.
421 * @return An error code
422 * @param[in] childControl The control for which the position is set
423 * @param[in] rowStartIndex The row index
424 * @param[in] columnStartIndex The column index
425 * @param[in] rowSpan The row span specifies the total number of cells in a row that are to be merged into a cell
426 * @param[in] columnSpan The column span specifies the total number of cells in a column that are to be merged into a cell
427 * @exception E_SUCCESS The method is successful.
428 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
429 * - A specified input parameter is invalid. @n
430 * - Either @c rowSpan or @c columnSpan is @c 0 or negative. @n
431 * - The specified @c childControl parameter is not a child of the container that owns the layout. @n
432 * - The specified span has tried to include a cell, which is already included in another span.
433 * @exception E_OUT_OF_RANGE The specified index is out of range, or @n
434 * the calculated range of the cell is out of the grid.
435 * @exception E_SYSTEM A system error has occurred.
437 result SetPosition(Control& childControl, int rowStartIndex, int columnStartIndex, int rowSpan, int columnSpan);
440 * Sets the horizontal alignment and the vertical alignment.
444 * @return An error code
445 * @param[in] childControl The control for which the alignment is set
446 * @param[in] horizontalAlignment The horizontal alignment
447 * @param[in] verticalAlignment The vertical alignment
448 * @exception E_SUCCESS The method is successful.
449 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
450 * The specified @c childControl parameter is not a child of the container that owns the layout.
451 * @exception E_SYSTEM A system error has occurred.
452 * @remarks By default, the value of @c horizontalAlignment is HORIZONTAL_ALIGN_LEFT and the value of @c verticalAlignment is
453 * VERTICAL_ALIGN_TOP.
454 * The column width is set to the largest width amongst controls in the column, and the row height is set to the largest
455 * height amongst controls in the row.
456 * Therefore, the smaller controls have vertical or horizontal margins around them, and they are repositioned in cells
457 * according to the alignment options.
459 result SetAlignment(Control& childControl, LayoutHorizontalAlignment horizontalAlignment, LayoutVerticalAlignment verticalAlignment);
462 * Sets the margins of the specified control.
466 * @return An error code
467 * @param[in] childControl The control for which the margins are set
468 * @param[in] left The left margin
469 * @param[in] right The right margin
470 * @param[in] top The top margin
471 * @param[in] bottom The bottom margin
472 * @exception E_SUCCESS The method is successful.
473 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
474 * The specified @c childControl parameter is not a child of the container that owns the layout.
475 * @exception E_SYSTEM A system error has occurred.
476 * @remarks By default, the margins are set to @c 0.
478 result SetMargin(Control& childControl, int left, int right, int top, int bottom);
481 * Sets the margins of the specified control.
485 * @return An error code
486 * @param[in] childControl The control for which the margins are set
487 * @param[in] left The left margin
488 * @param[in] right The right margin
489 * @param[in] top The top margin
490 * @param[in] bottom The bottom margin
491 * @exception E_SUCCESS The method is successful.
492 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
493 * The specified @c childControl parameter is not a child of the container that owns the layout.
494 * @exception E_SYSTEM A system error has occurred.
495 * @remarks By default, the margins are set to @c 0.
497 result SetMargin(Control& childControl, float left, float right, float top, float bottom);
500 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
502 GridLayout(const GridLayout& rhs);
505 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
507 GridLayout& operator =(const GridLayout& rhs);
512 #endif // _FUI_GRID_LAYOUT_H_