#include <Wt/WGridLayout>
Public Member Functions | |
WGridLayout (WWidget *parent=0) | |
Create a new grid layout. | |
virtual void | addItem (WLayoutItem *item) |
Add a layout item. | |
virtual void | removeItem (WLayoutItem *item) |
Remove a layout item (widget or nested layout). | |
virtual WLayoutItem * | itemAt (int index) const |
Return the layout item at a specific index. | |
virtual int | count () const |
Return the number of items in this layout. | |
void | addItem (WLayoutItem *item, int row, int column, int rowSpan=1, int columnSpan=1, WFlags< AlignmentFlag > alignment=0) |
Adds a layout item to the grid. | |
void | addLayout (WLayout *layout, int row, int column, WFlags< AlignmentFlag > alignment=0) |
Adds a nested layout item to the grid. | |
void | addLayout (WLayout *layout, int row, int column, int rowSpan, int columnSpan, WFlags< AlignmentFlag > alignment=0) |
Adds a nested layout item to the grid. | |
void | addWidget (WWidget *widget, int row, int column, WFlags< AlignmentFlag > alignment=0) |
Adds a widget to the grid. | |
void | addWidget (WWidget *widget, int row, int column, int rowSpan, int columnSpan, WFlags< AlignmentFlag > alignment=0) |
Adds a widget to the grid. | |
void | setHorizontalSpacing (int size) |
Sets the horizontal spacing. | |
int | horizontalSpacing () const |
Returns the horizontal spacing. | |
void | setVerticalSpacing (int size) |
Sets the vertical spacing. | |
int | verticalSpacing () const |
Returns the vertical spacing. | |
int | columnCount () const |
Returns the column count. | |
int | rowCount () const |
Returns the row count. | |
void | setColumnStretch (int column, int stretch) |
Sets the column stretch. | |
int | columnStretch (int column) const |
Returns the column stretch. | |
void | setRowStretch (int row, int stretch) |
Sets the row stretch. | |
int | rowStretch (int row) const |
Returns the column stretch. |
This is a layout class that arranges widgets in a grid, to span the entire area of the parent container. Each grid location (row, column) may contain one widget or nested layout. Horizontal and vertical space are divided so that each column/row is given its minimum size and the remaining space is dived according to stretch factors among the columns/rows. The minimum width of a column/row is based on the minimum dimensions of contained widgets or nested layouts. The default minimum height and width may be overridden using WWidget::setMinimumSize().
You can use WContainerWidget::setOverflow() to automatically show scrollbars on a container widget which you have set for a grid cell. In some cases, you will want to wrap another widget (like a WTable) into WContainerWidget to have the scrollbars, since not all widgets allow for scrollbars.
Columns and rows are separated using a constant spacing, which defaults to 6 pixels by default, and can be changed using setHorizontalSpacing() and setVerticalSpacing(). In addition, when this layout is a top-level layout (i.e. is not nested inside another layout), a margin is set around the contents, which thus replaces padding defined for the container. It is not allowed to define padding for the container widget using its CSS 'padding' property or the WContainerWidget::setPadding(). This margin also defaults to 9 pixels, and can be changed using setContentsMargins().
For each column or row, a stretch factor may be defined, which controls how remaining horizontal or vertical space is used. Each column and row is stretched using the stretch factor to fill the remaining space. When the stretch factor is 0, the height of the row and its contents is not actively managed. As a consequence, the contents of each cell will not fill the cell. You may use a special stretch factor of -1 to indicate that the height of the row should not stretch but the contents height should be actively managed. This has as draw-back that the height of the row will no longer reduce in size when any of the cell contents reduces in size.
Usage example:
Wt::WContainerWidget *w = new Wt::WContainerWidget(this); w->resize(WLength::Auto, 600); Wt::WGridLayout *layout = new Wt::WGridLayout(); layout->addWidget(new Wt::WText("Item 0 0"), 0, 0); layout->addWidget(new Wt::WText("Item 0 1"), 0, 1); layout->addWidget(new Wt::WText("Item 1 0"), 1, 0); layout->addWidget(new Wt::WText("Item 1 1"), 1, 1); w->setLayout(layout);
When JavaScript support is not available, only Safari and Firefox properly implement this layout. For other browsers, only the horizontal layout is properly implemented, while vertically all widgets use their minimum size.
When set on a WContainerWidget, this layout manager accepts the following hints (see setLayoutHint()):
Wt::WGridLayout::WGridLayout | ( | WWidget * | parent = 0 |
) |
Create a new grid layout.
The grid will grow dynamically as items are added.
Use parent
= 0
to create a layout manager that can be nested inside other layout managers or to specify a specific alignment when setting the layout to a WContainerWidget.
void Wt::WGridLayout::addItem | ( | WLayoutItem * | item | ) | [virtual] |
Add a layout item.
The item may be a widget or nested layout.
How the item is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.
Implements Wt::WLayout.
void Wt::WGridLayout::removeItem | ( | WLayoutItem * | item | ) | [virtual] |
WLayoutItem * Wt::WGridLayout::itemAt | ( | int | index | ) | const [virtual] |
Return the layout item at a specific index.
If there is no item at the index
, 0
is returned.
Implements Wt::WLayout.
int Wt::WGridLayout::count | ( | ) | const [virtual] |
Return the number of items in this layout.
This may be a theoretical number, which is greater than the actual number of items. It can be used to iterate over the items in the layout, in conjunction with itemAt().
Implements Wt::WLayout.
void Wt::WGridLayout::addItem | ( | WLayoutItem * | item, | |
int | row, | |||
int | column, | |||
int | rowSpan = 1 , |
|||
int | columnSpan = 1 , |
|||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a layout item to the grid.
Adds the item at (row, column
). If an item was already added to that location, it is replaced (but not deleted).
An item may span several more rows or columns, which is controlled by rowSpan and columnSpan
.
The alignment
specifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. The alignment can be specified as a logical combination of a horizontal alignment (Wt::AlignLeft, Wt::AlignCenter, or Wt::AlignRight) and a vertical alignment (Wt::AlignTop, Wt::AlignMiddle, or Wt::AlignBottom).
void Wt::WGridLayout::addLayout | ( | WLayout * | layout, | |
int | row, | |||
int | column, | |||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a nested layout item to the grid.
Adds the layout at (row, column
). If an item was already added to that location, it is replaced (but not deleted).
The alignment
specifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. The alignment can be specified as a logical combination of a horizontal alignment (Wt::AlignLeft, Wt::AlignCenter, or Wt::AlignRight) and a vertical alignment (Wt::AlignTop, Wt::AlignMiddle, or Wt::AlignBottom).
void Wt::WGridLayout::addLayout | ( | WLayout * | layout, | |
int | row, | |||
int | column, | |||
int | rowSpan, | |||
int | columnSpan, | |||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a nested layout item to the grid.
Adds the layout at (row, column
). If an item was already added to that location, it is replaced (but not deleted).
An item may span several more rows or columns, which is controlled by rowSpan and columnSpan
.
The alignment
specifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. The alignment can be specified as a logical combination of a horizontal alignment (Wt::AlignLeft, Wt::AlignCenter, or Wt::AlignRight) and a vertical alignment (Wt::AlignTop, Wt::AlignMiddle, or Wt::AlignBottom).
void Wt::WGridLayout::addWidget | ( | WWidget * | widget, | |
int | row, | |||
int | column, | |||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a widget to the grid.
Adds the widget at (row, column
). If an item was already added to that location, it is replaced (but not deleted).
The alignment
specifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. The alignment can be specified as a logical combination of a horizontal alignment (Wt::AlignLeft, Wt::AlignCenter, or Wt::AlignRight) and a vertical alignment (Wt::AlignTop, Wt::AlignMiddle, or Wt::AlignBottom).
void Wt::WGridLayout::addWidget | ( | WWidget * | widget, | |
int | row, | |||
int | column, | |||
int | rowSpan, | |||
int | columnSpan, | |||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a widget to the grid.
Adds the widget at (row, column
). If an item was already added to that location, it is replaced (but not deleted).
The widget may span several more rows or columns, which is controlled by rowSpan and columnSpan
.
The alignment
specifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. The alignment can be specified as a logical combination of a horizontal alignment (Wt::AlignLeft, Wt::AlignCenter, or Wt::AlignRight) and a vertical alignment (Wt::AlignTop, Wt::AlignMiddle, or Wt::AlignBottom).
void Wt::WGridLayout::setHorizontalSpacing | ( | int | size | ) |
Sets the horizontal spacing.
The default horizontal spacing is 9 pixels.
int Wt::WGridLayout::horizontalSpacing | ( | ) | const [inline] |
void Wt::WGridLayout::setVerticalSpacing | ( | int | size | ) |
Sets the vertical spacing.
The default vertical spacing is 9 pixels.
int Wt::WGridLayout::verticalSpacing | ( | ) | const [inline] |
int Wt::WGridLayout::columnCount | ( | ) | const |
Returns the column count.
The grid dimensions change dynamically when adding contents to the grid.
int Wt::WGridLayout::rowCount | ( | ) | const |
Returns the row count.
The grid dimensions change dynamically when adding contents to the grid.
void Wt::WGridLayout::setColumnStretch | ( | int | column, | |
int | stretch | |||
) |
int Wt::WGridLayout::columnStretch | ( | int | column | ) | const |
void Wt::WGridLayout::setRowStretch | ( | int | row, | |
int | stretch | |||
) |
Sets the row stretch.
Sets the stretch factor for row row
. See the description for the special value of -1.
int Wt::WGridLayout::rowStretch | ( | int | row | ) | const |