#include <Wt/WContainerWidget>
Public Types | |
enum | Overflow { OverflowVisible = 0x0, OverflowAuto = 0x1, OverflowHidden = 0x2, OverflowScroll = 0x3 } |
How to handle overflow of inner content. More... | |
Public Member Functions | |
WContainerWidget (WContainerWidget *parent=0) | |
Create a container with optional parent. | |
~WContainerWidget () | |
Destruct a WContainerWidget. | |
void | setLayout (WLayout *layout) |
Set a layout manager for the container. | |
void | setLayout (WLayout *layout, int alignment) |
Set a layout manager for the container. | |
WLayout * | layout () |
Get the layout manager that was set for the container. | |
virtual void | addWidget (WWidget *widget) |
Add a child widget to this container. | |
virtual void | insertBefore (WWidget *widget, WWidget *before) |
insert a child widget in this container, before another widget. | |
virtual void | insertWidget (int index, WWidget *widget) |
insert a child widget in this container at given index. | |
virtual void | removeWidget (WWidget *widget) |
Remove a child widget from this container. | |
virtual void | clear () |
Remove and delete all child widgets. | |
virtual int | indexOf (WWidget *widget) const |
Return the index of a widget. | |
virtual WWidget * | widget (int index) const |
Return the widget at index. | |
virtual int | count () const |
Get the number of widgets in this container. | |
void | setContentAlignment (HorizontalAlignment contentAlignment) |
Specify how child widgets must be aligned within the container. | |
void | setPadding (WLength padding, int sides=All) |
Set padding inside the widget. | |
WLength | padding (Side side) const |
Get the padding set for the widget. | |
HorizontalAlignment | contentAlignment () const |
Get the horizontal alignment of children. | |
virtual const std::vector< WWidget * > & | children () const |
Get the children. | |
void | setOverflow (Overflow overflow, int orientation=(Horizontal|Vertical)) |
Set how overflow of contained children must be handled. | |
void | setList (bool list, bool ordered=false) |
Render the container as an HTML list. | |
bool | isList () const |
Return if this container is rendered as a List. | |
bool | isUnorderedList () const |
Return if this container is rendered as an Unordered List. | |
bool | isOrderedList () const |
Return if this container is rendered as an Ordered List. |
A WContainerWidget acts as a container for child widgets. Child widgets may be added directly to the container or using a layout manager.
Use addWidget() or pass the container as constructor argument to a widget to directly add children to the container, without using a layout manager. In that case, CSS-based layout is used, which is governed by properties of the children, and properties of the container. By default, a WContainerWidget is stacked and manages its children within a rectangle. Inline child widgets are layed out in lines, wrapping around as needed, while stacked widgets are stacked vertically. The container may add padding at the container edges using setPadding(), and provide alignment of contents using setContentAlignment(). A container is rendered by default using a HTML div
tag, but this may be changed to an HTML ul
or ol
tag to make use of other CSS layout techniques, using setList(). In addition, specializations of this class as implemented by WAnchor, WGroupBox, WStackedWidget and WTableCell provide other alternative rendering of the container.
When setting the WContainerWidget inline the container only acts as a conceptual container, offering a common style to its children. Inline children are still layed out inline within the flow of the parent container of this container, as if they were inserted directly into that parent container.
To use a layout manager instead of CSS-based layout, use setLayout() or pass the container as constructor argument to a layout manager. In that case you should not define any padding for the container, and widgets and nested layout managers must be added to the layout manager, instead of to the container directly.
void Wt::WContainerWidget::setLayout | ( | WLayout * | layout | ) | [virtual] |
Set a layout manager for the container.
Only a single layout manager may be set. Note that you can nest layout managers inside each other, to create a complex layout hierarchy.
The layout manager arranges children in the entire width and height of the container. This is equivalent to setLayout(layout, AlignJustify)
Reimplemented from Wt::WWidget.
void Wt::WContainerWidget::setLayout | ( | WLayout * | layout, | |
int | alignment | |||
) |
Set a layout manager for the container.
The alignment argument determines how the layout is aligned inside the container. By default, the layout manager arranges children over the entire width and height of the container, corresponding to a value of AlignJustify. This requires that the container has a specified height (either because it is managed by another layout manager, is the root container widget, or has a height set).
In general, alignment is the logical OR of a horizontal and vertical alignment. Horizontal alignment options may be AlignLeft, AlignCenter, AlignRight, or AlignJustify. The only vertical alignment that is supported is '0' (corresponding to vertical justification to the full height), or AlignTop. When using a horizontal alingment different from AlignJustify, and a vertical alignment different from '0', the widget is sized in that direction to fit the contents. This is useful when the container does not have a specific size and when the layout manager does not contain any widgets that wish to consume all remaining space in that direction.
Only a single layout manager may be set. If you want to replace the current layout manager, you have to erase all contents first using clear(), which also deletes the layout manager.
Note that you can nest layout managers inside each other, to create a complex layout hierarchy.
The widget will take ownership of layout.
WLayout* Wt::WContainerWidget::layout | ( | ) | [inline] |
Get the layout manager that was set for the container.
If no layout manager was previously set using setLayout(WLayout *), 0 is returned.
void Wt::WContainerWidget::addWidget | ( | WWidget * | widget | ) | [virtual] |
Add a child widget to this container.
This is equivalent to passing this container as the parent when constructing the child. The widget is appended to the list of children, and thus also layed-out at the end.
Reimplemented in Wt::Ext::Splitter, and Wt::WStackedWidget.
insert a child widget in this container, before another widget.
The widget is inserted at the place of the before widget, and subsequent widgets are shifted.
Reimplemented in Wt::Ext::Splitter.
void Wt::WContainerWidget::insertWidget | ( | int | index, | |
WWidget * | widget | |||
) | [virtual] |
insert a child widget in this container at given index.
The widget is inserted at the given index, and subsequent widgets are shifted.
Reimplemented in Wt::Ext::Splitter, and Wt::WStackedWidget.
void Wt::WContainerWidget::removeWidget | ( | WWidget * | widget | ) | [virtual] |
Remove a child widget from this container.
This removes the widget from this container, but does not delete the widget !
Reimplemented in Wt::WStackedWidget.
void Wt::WContainerWidget::clear | ( | ) | [virtual] |
Remove and delete all child widgets.
This deletes all children that have been added to this container.
If a layout was set, also the layout manager is deleted.
void Wt::WContainerWidget::setContentAlignment | ( | HorizontalAlignment | contentAlignment | ) |
Specify how child widgets must be aligned within the container.
Specify the horizontal alignment of child widgets. Note that there is no way to specify vertical alignment: children are always pushed to the top of the container. Only in a WTableCell, there is a method to align the children vertically.
void Wt::WContainerWidget::setPadding | ( | WLength | padding, | |
int | sides = All | |||
) |
Set padding inside the widget.
Setting padding has the effect of adding distance between the widget children and the border.
Get the padding set for the widget.
HorizontalAlignment Wt::WContainerWidget::contentAlignment | ( | ) | const [inline] |
void Wt::WContainerWidget::setOverflow | ( | Overflow | overflow, | |
int | orientation = (Horizontal | Vertical) | |||
) |
Set how overflow of contained children must be handled.
This is an alternative (CSS-ish) way to provide scroll bars on a container widget, compared to wrapping inside a WScrollArea.
Note that currently, you cannot separately specify vertical and horizontal scroll behaviour, since this is not supported on Opera. Therefore, settings will apply automatically to both orientations.
void Wt::WContainerWidget::setList | ( | bool | list, | |
bool | ordered = false | |||
) |
Render the container as an HTML list.
Setting renderList to true will cause the container to be using an HTML <UL> or <OL> type, depending on the value of orderedList. This must be set before the initial render of the container. When set, any contained WContainerWidget will be rendered as an HTML <LI>. Adding non-WContainerWidget children results in unspecified behaviour.
Note that CSS default layout rules for <UL> and <OL> add margin and padding to the container, which may look odd if you do not use bullets.
By default, a container is rendered using a <DIV> element.
bool Wt::WContainerWidget::isList | ( | ) | const |
Return if this container is rendered as a List.
bool Wt::WContainerWidget::isUnorderedList | ( | ) | const |
Return if this container is rendered as an Unordered List.
bool Wt::WContainerWidget::isOrderedList | ( | ) | const |