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 stretching ability of the specified row.
298 * @return An error code
299 * @param[in] rowIndex The row index
300 * @param[in] stretchable Set to @c true to make the row stretchable, @n
302 * @exception E_SUCCESS The method is successful.
303 * @exception E_OUT_OF_RANGE The specified index is out of range.
304 * @exception E_SYSTEM A system error has occurred.
306 result SetRowStretchable(int rowIndex, bool stretchable);
309 * Sets the shrinking ability of the specified row.
313 * @return An error code
314 * @param[in] rowIndex The row index
315 * @param[in] shrinkable Set to @c true to make the row shrinkable, @n
317 * @exception E_SUCCESS The method is successful.
318 * @exception E_OUT_OF_RANGE The specified index is out of range.
319 * @exception E_SYSTEM A system error has occurred.
321 result SetRowShrinkable(int rowIndex, bool shrinkable);
324 * Sets the collapsibility of the specified row.
328 * @return An error code
329 * @param[in] rowIndex The row index
330 * @param[in] collapsed Set to @c true to make the row as collapsible, @n
332 * @exception E_SUCCESS The method is successful.
333 * @exception E_OUT_OF_RANGE The specified index is out of range.
334 * @exception E_SYSTEM A system error has occurred.
336 result SetRowCollapsed(int rowIndex, bool collapsed);
339 * Sets the stretching ability of all the rows.
343 * @return An error code
344 * @param[in] stretchable Set to @c true to set all the rows as stretchable, @n
346 * @exception E_SUCCESS The method is successful.
347 * @exception E_SYSTEM A system error has occurred.
349 result SetAllRowsStretchable(bool stretchable);
352 * Sets the shrinking ability of all the rows.
356 * @return An error code
357 * @param[in] shrinkable Set to @c true to set all the rows as shrinkable, @n
359 * @exception E_SUCCESS The method is successful.
360 * @exception E_SYSTEM A system error has occurred.
362 result SetAllRowsShrinkable(bool shrinkable);
365 * Sets the space before the specified column index.
369 * @return An error code
370 * @param[in] rowIndex The row index
371 * @param[in] space An @c int representing the space
372 * @exception E_SUCCESS The method is successful.
373 * @exception E_INVALID_ARG The specified input parameter is invalid.
374 * @exception E_OUT_OF_RANGE The specified index is out of range.
375 * @exception E_SYSTEM A system error has occurred.
376 * @remarks This method does not perform any operation if the value of @c rowIndex is @c 0.
377 * @remarks The row spacing cannot be applied to the first column.
379 result SetRowSpacing(int rowIndex, int space);
382 * Sets the position and span of the control. @n
383 * Adds the control at the specified position.
387 * @return An error code
388 * @param[in] childControl The control for which the position is set
389 * @param[in] rowStartIndex The row index
390 * @param[in] columnStartIndex The column index
391 * @param[in] rowSpan The row span specifies the total number of cells in a row that are to be merged into a cell
392 * @param[in] columnSpan The column span specifies the total number of cells in a column that are to be merged into a cell
393 * @exception E_SUCCESS The method is successful.
394 * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
395 * - A specified input parameter is invalid. @n
396 * - Either @c rowSpan or @c columnSpan is @c 0 or negative. @n
397 * - The specified @c childControl parameter is not a child of the container that owns the layout. @n
398 * - The specified span has tried to include a cell, which is already included in another span.
399 * @exception E_OUT_OF_RANGE The specified index is out of range, or @n
400 * the calculated range of the cell is out of the grid.
401 * @exception E_SYSTEM A system error has occurred.
403 result SetPosition(Control& childControl, int rowStartIndex, int columnStartIndex, int rowSpan, int columnSpan);
406 * Sets the horizontal alignment and the vertical alignment.
410 * @return An error code
411 * @param[in] childControl The control for which the alignment is set
412 * @param[in] horizontalAlignment The horizontal alignment
413 * @param[in] verticalAlignment The vertical alignment
414 * @exception E_SUCCESS The method is successful.
415 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
416 * The specified @c childControl parameter is not a child of the container that owns the layout.
417 * @exception E_SYSTEM A system error has occurred.
418 * @remarks By default, the value of @c horizontalAlignment is HORIZONTAL_ALIGN_LEFT and the value of @c verticalAlignment is
419 * VERTICAL_ALIGN_TOP.
420 * The column width is set to the largest width amongst controls in the column, and the row height is set to the largest
421 * height amongst controls in the row.
422 * Therefore, the smaller controls have vertical or horizontal margins around them, and they are repositioned in cells
423 * according to the alignment options.
425 result SetAlignment(Control& childControl, LayoutHorizontalAlignment horizontalAlignment, LayoutVerticalAlignment verticalAlignment);
428 * Sets the margins of the specified control.
432 * @return An error code
433 * @param[in] childControl The control for which the margins are set
434 * @param[in] left The left margin
435 * @param[in] right The right margin
436 * @param[in] top The top margin
437 * @param[in] bottom The bottom margin
438 * @exception E_SUCCESS The method is successful.
439 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
440 * The specified @c childControl parameter is not a child of the container that owns the layout.
441 * @exception E_SYSTEM A system error has occurred.
442 * @remarks By default, the margins are set to @c 0.
444 result SetMargin(Control& childControl, int left, int right, int top, int bottom);
448 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
450 GridLayout(const GridLayout& rhs);
453 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
455 GridLayout& operator =(const GridLayout& rhs);
460 #endif // _FUI_GRID_LAYOUT_H_