Wt  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | List of all members
Wt::WGridLayout Class Reference

A layout manager which arranges widgets in a grid. More...

#include <Wt/WGridLayout>

Inheritance diagram for Wt::WGridLayout:
Inheritance graph
[legend]

Public Member Functions

 WGridLayout (WWidget *parent=0)
 Create a new grid layout.
virtual void addItem (WLayoutItem *item)
 Adds a layout item.
virtual void removeItem (WLayoutItem *item)
 Removes a layout item (widget or nested layout).
virtual WLayoutItemitemAt (int index) const
 Returns the layout item at a specific index.
virtual int count () const
 Returns the number of items in this layout.
virtual void clear ()
 Removes and deletes all child widgets and nested layouts.
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.
void setColumnResizable (int column, bool enabled=true)
 Sets whether the user may drag a particular column border.
bool columnIsResizable (int column) const
 Returns whether the user may drag a particular column border.
void setRowResizable (int row, bool enabled=true)
 Sets whether the user may drag a particular row border.
bool rowIsResizable (int row) const
 Returns whether the user may drag a particular row border.
- Public Member Functions inherited from Wt::WLayout
virtual ~WLayout ()
 Destructor.
void addWidget (WWidget *widget)
 Adds the given widget to the layout.
bool removeWidget (WWidget *widget)
 Removes the given widget from the layout.
virtual int indexOf (WLayoutItem *item) const
 Returns the index of a given item.
virtual WWidgetItemfindWidgetItem (WWidget *widget)
 Finds the widget item associated with the given widget.
void setLayoutHint (const std::string &name, const std::string &value)
 Provides a hint to the layout implementation.
virtual WWidgetwidget ()
 Returns the widget that is held by this WLayoutItem.
virtual WLayoutlayout ()
 Returns the layout that implements this WLayoutItem.
virtual WLayoutparentLayout () const
 Returns the layout in which this item is contained.
WLayoutItemImplimpl () const
 Returns the implementation for this layout item.
void setContentsMargins (int left, int top, int right, int bottom)
 Set contents margins (in pixels).
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 Returns the contents margins.
- Public Member Functions inherited from Wt::WLayoutItem
virtual ~WLayoutItem ()
 Destructor.
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
 Create a WObject with a given parent object.
virtual ~WObject ()
 Destructor.
virtual const std::string id () const
 Returns the (unique) identifier for this object.
void setObjectName (const std::string &name)
 Sets an object name.
virtual std::string objectName () const
 Returns the object name.
void resetLearnedSlots ()
 Resets learned stateless slot implementations.
template<class T >
void resetLearnedSlot (void(T::*method)())
 Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)())
 Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 Declares a slot to be stateless and learn client-side behaviour in advance.
template<class T >
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 Provides a JavaScript implementation for a method.
void addChild (WObject *child)
 Adds a child object.
virtual void removeChild (WObject *child)
 Removes a child object.
const std::vector< WObject * > & children () const
 Returns the children.
WObjectparent () const
 Returns the parent object.

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method )()
 Typedef for a WObject method without arguments.
- Protected Member Functions inherited from Wt::WLayout
 WLayout ()
 Create a layout.
void update (WLayoutItem *item=0)
 Update the layout.
void updateAddItem (WLayoutItem *item)
 Update the layout, adding the given layout item.
void updateRemoveItem (WLayoutItem *item)
 Update the layout, remove the given layout item.
void setLayoutInParent (WWidget *parent)
 Set the layout in the parent.
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 Returns the sender of the current slot call.

Detailed Description

A layout manager which arranges widgets in a grid.

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().

If you want to use the layout manager for a container which does not have a height that is constrained somehow, you need to specify AlignTop in the alignment flags of WContainerWidget::setLayout(). Otherwise the behavior is undefined (the parent container will continue to increase in size as it tries to satisfy the constraints assuming a contrained height).

You can use WContainerWidget::setOverflow(OverflowAuto) or use a WScrollArea to automatically show scrollbars on a widget inserted in the layout.

A caveat with layout managers is that you cannot reliably use a stylesheet to add borders (or margin) to a widget inserted in a layout: this is broken on Internet Explorer. To provide the layout, the layout manager needs to set sizes on the contained widget but these sizes also need to take into account the border/margin width. Since on IE, this value will be 0 if the border or margin is provided by a stylesheet (as opposed to by inline CSS by using WWidget::decorationStyle()), the result will be wrong behaviour like widgets that keep growing in size.

A layout manager may provide resize handles between columns or rows which allow the user to change the automatic layout provided by the layout manager (see setRowResizable() and setColumnResizable()). Resize handles between rows only work when the layout fills the parent vertical space (i.e. is not aligned to the top). Likewise, resize handles between columns only work when the layout fills the parent horiziontal space (i.e. is not aligned left, right or centered).

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:

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);
Note
This layout manager is applicable only to WContainerWidget container widgets. You may use it within an Ext::Container indirectly by first setting a WContainerWidget using a WFitLayout.
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()):
  • "table-layout" with possible values "auto" (default) or "fixed".
    Use "fixed" to prevent nested tables from overflowing the layout. In that case, you will need to specify a width (in CSS or otherwise) for at least one item in every column that has no stretch factor.

Constructor & Destructor Documentation

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.

Member Function Documentation

void Wt::WGridLayout::addItem ( WLayoutItem item)
virtual

Adds 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.

See Also
removeItem(WLayoutItem *), addWidget(WWidget *)

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).

See Also
addLayout(), addWidget()
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).

See Also
addLayout(WLayout *, int, int, int, int, WFlags<AlignmentFlag>)
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).

See Also
addLayout(WLayout *, int, int, WFlags<AlignmentFlag>)
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).

See Also
addWidget(WWidget *, int, int, int, int, WFlags<AlignmentFlag>)
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).

See Also
addWidget(WWidget *, int, int, WFlags<AlignmentFlag>)
void Wt::WGridLayout::clear ( )
virtual

Removes and deletes all child widgets and nested layouts.

This is similar to WContainerWidget::clear(), with the exception that the layout itself is not deleted.

Implements Wt::WLayout.

int Wt::WGridLayout::columnCount ( ) const

Returns the column count.

The grid dimensions change dynamically when adding contents to the grid.

See Also
rowCount()
bool Wt::WGridLayout::columnIsResizable ( int  column) const

Returns whether the user may drag a particular column border.

This method returns whether the border that separates column column from the next column may be resized by the user.

See Also
setColumnResizable()
int Wt::WGridLayout::columnStretch ( int  column) const

Returns the column stretch.

See Also
setColumnStretch(int, int)
int Wt::WGridLayout::count ( ) const
virtual

Returns 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.

int Wt::WGridLayout::horizontalSpacing ( ) const

Returns the horizontal spacing.

See Also
setHorizontalSpacing(int)
WLayoutItem * Wt::WGridLayout::itemAt ( int  index) const
virtual

Returns the layout item at a specific index.

If there is no item at the index, 0 is returned.

See Also
indexOf(WLayoutItem *) const, count()

Implements Wt::WLayout.

void Wt::WGridLayout::removeItem ( WLayoutItem item)
virtual

Removes a layout item (widget or nested layout).

See Also
addItem(WLayoutItem *), removeWidget(WWidget *)

Implements Wt::WLayout.

int Wt::WGridLayout::rowCount ( ) const

Returns the row count.

The grid dimensions change dynamically when adding contents to the grid.

See Also
columnCount()
bool Wt::WGridLayout::rowIsResizable ( int  row) const

Returns whether the user may drag a particular row border.

This method returns whether the border that separates row row from the next row may be resized by the user.

See Also
setRowResizable()
int Wt::WGridLayout::rowStretch ( int  row) const

Returns the column stretch.

See Also
setRowStretch(int, int)
void Wt::WGridLayout::setColumnResizable ( int  column,
bool  enabled = true 
)

Sets whether the user may drag a particular column border.

This method sets whether the border that separates column column from the next column may be resized by the user, depending on the value of enabled.

The default value is false.

void Wt::WGridLayout::setColumnStretch ( int  column,
int  stretch 
)

Sets the column stretch.

Sets the stretch factor for column column.

See Also
columnStretch()
void Wt::WGridLayout::setHorizontalSpacing ( int  size)

Sets the horizontal spacing.

The default horizontal spacing is 9 pixels.

See Also
setVerticalSpacing(int)
void Wt::WGridLayout::setRowResizable ( int  row,
bool  enabled = true 
)

Sets whether the user may drag a particular row border.

This method sets whether the border that separates row row from the next row may be resized by the user, depending on the value of enabled.

The default value is false.

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.

See Also
rowStretch()
void Wt::WGridLayout::setVerticalSpacing ( int  size)

Sets the vertical spacing.

The default vertical spacing is 9 pixels.

See Also
setHorizontalSpacing(int)
int Wt::WGridLayout::verticalSpacing ( ) const

Returns the vertical spacing.

See Also
setVerticalSpacing(int)

Generated on Mon Aug 25 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2