A layout manager which arranges widgets horizontally or vertically. More...
#include <Wt/WBoxLayout>
Inherits Wt::WLayout.
Inherited by Wt::WHBoxLayout, and Wt::WVBoxLayout.
Public Types | |
enum | Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop } |
Enumeration of the direction in which widgets are layed out. More... | |
Public Member Functions | |
WBoxLayout (Direction dir, WWidget *parent=0) | |
Creates a new box layout. | |
virtual void | addItem (WLayoutItem *item) |
Adds a layout item. | |
virtual void | removeItem (WLayoutItem *item) |
Removes a layout item (widget or nested layout). | |
virtual WLayoutItem * | itemAt (int index) const |
Returns the layout item at a specific index. | |
virtual int | count () const |
Returns the number of items in this layout. | |
void | setDirection (Direction direction) |
Sets the layout direction. | |
Direction | direction () const |
Returns the layout direction. | |
void | setSpacing (int size) |
Sets spacing between each item. | |
int | spacing () const |
Returns the spacing between each item. | |
void | addWidget (WWidget *widget, int stretch=0, WFlags< AlignmentFlag > alignment=0) |
Adds a widget to the layout. | |
void | addLayout (WLayout *layout, int stretch=0, WFlags< AlignmentFlag > alignment=0) |
Adds a nested layout to the layout. | |
void | addSpacing (const WLength &size) |
Adds extra spacing. | |
void | addStretch (int stretch=0) |
Adds a stretch element. | |
void | insertWidget (int index, WWidget *widget, int stretch=0, WFlags< AlignmentFlag > alignment=0) |
Inserts a widget in the layout. | |
void | insertLayout (int index, WLayout *layout, int stretch=0, WFlags< AlignmentFlag > alignment=0) |
Inserts a nested layout in the layout. | |
void | insertSpacing (int index, const WLength &size) |
Inserts extra spacing in the layout. | |
void | insertStretch (int index, int stretch=0) |
Inserts a stretch element in the layout. | |
bool | setStretchFactor (WLayout *layout, int stretch) |
Sets the stretch factor for a nested layout. | |
bool | setStretchFactor (WWidget *widget, int stretch) |
Sets the stretch factor for a nested layout. | |
void | setResizable (int index, bool enabled=true) |
Sets whether the use may drag a particular border. | |
bool | isResizable (int row) const |
Returns whether the user may drag a particular border. |
A layout manager which arranges widgets horizontally or vertically.
This layout manager arranges widgets horizontally or vertically inside the parent container. The space is divided so that each widgets is given its minimum size, and remaining space is divided according to stretch factors among the widgets. The widget minimum height or width is used for sizing each widget, whose default values 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) to automatically show scrollbars on a container widget inserted in the layout. 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.
A layout manager may provide resize handles between items which allow the user to change the automatic layout provided by the layout manager (see setResizable()). Resize handles between rows for a vertically oriented box layout only work when the layout fills the parent vertical space (i.e. is not aligned to the top). Likewise, resize handles between columns for a horizontally oriented box layout only work when the layout fills the parent horiziontal space (i.e. is not aligned left, right or centered).
Each item is separated using a constant spacing, which defaults to 6 pixels, and can be changed using setSpacing(). 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. This margin defaults to 9 pixels, and can be changed using setContentsMargins(). It is not allowed to define padding for the container widget using its CSS 'padding' property or the WContainerWidget::setPadding(). You can add more space between two widgets using addSpacing().
For each item a stretch factor may be defined, which controls how remaining space is used. Each item is stretched using the stretch factor to fill the remaining space.
Usage example:
Wt::WContainerWidget *w = new Wt::WContainerWidget(this); w->resize(WLength(), 600); Wt::WBoxLayout *layout = new Wt::WBoxLayout(Wt::WBoxLayout::TopToBottom); layout->addWidget(new Wt::WText("One")); layout->addWidget(new Wt::WText("Two")); layout->addWidget(new Wt::WText("Three")); layout->addWidget(new Wt::WText("Four")); w->setLayout(layout);
Enumeration of the direction in which widgets are layed out.
Creates a new box layout.
This constructor is rarely used. Instead, use the convenient constructors of the specialized WHBoxLayout or WVBoxLayout classes.
Use parent
= 0
to created a layout manager that can be nested inside other layout managers.
void Wt::WBoxLayout::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.
Implements Wt::WLayout.
void Wt::WBoxLayout::addLayout | ( | WLayout * | layout, | |
int | stretch = 0 , |
|||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a nested layout to the layout.
Adds a nested layout, with given stretch
factor.
void Wt::WBoxLayout::addSpacing | ( | const WLength & | size | ) |
void Wt::WBoxLayout::addStretch | ( | int | stretch = 0 |
) |
Adds a stretch element.
Adds a stretch element to the layout. This adds an empty space that stretches as needed.
void Wt::WBoxLayout::addWidget | ( | WWidget * | widget, | |
int | stretch = 0 , |
|||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Adds a widget to the layout.
Adds a widget to the layout, with given stretch
factor. The alignemnt
parameter is a combination of a horizontal and/or a vertical AlignmentFlag OR'ed together.
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 column or row. 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).
int Wt::WBoxLayout::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.
Direction Wt::WBoxLayout::direction | ( | ) | const [inline] |
Returns the layout direction.
void Wt::WBoxLayout::insertLayout | ( | int | index, | |
WLayout * | layout, | |||
int | stretch = 0 , |
|||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Inserts a nested layout in the layout.
Inserts a nested layout in the layout at positionindex
, with given stretch
factor.
void Wt::WBoxLayout::insertSpacing | ( | int | index, | |
const WLength & | size | |||
) |
Inserts extra spacing in the layout.
Inserts extra spacing in the layout at position index
.
void Wt::WBoxLayout::insertStretch | ( | int | index, | |
int | stretch = 0 | |||
) |
Inserts a stretch element in the layout.
Inserts a stretch element in the layout at position index
. This adds an empty space that stretches as needed.
void Wt::WBoxLayout::insertWidget | ( | int | index, | |
WWidget * | widget, | |||
int | stretch = 0 , |
|||
WFlags< AlignmentFlag > | alignment = 0 | |||
) |
Inserts a widget in the layout.
Inserts a widget in the layout at position index
, with given stretch
factor.
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 column or row. 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).
bool Wt::WBoxLayout::isResizable | ( | int | row | ) | const |
Returns whether the user may drag a particular border.
This method returns whether the border that separates item index from the next item may be resized by the user.
WLayoutItem * Wt::WBoxLayout::itemAt | ( | int | index | ) | const [virtual] |
Returns the layout item at a specific index.
If there is no item at the index
, 0
is returned.
Implements Wt::WLayout.
void Wt::WBoxLayout::removeItem | ( | WLayoutItem * | item | ) | [virtual] |
Removes a layout item (widget or nested layout).
Implements Wt::WLayout.
void Wt::WBoxLayout::setDirection | ( | Direction | direction | ) |
Sets the layout direction.
void Wt::WBoxLayout::setResizable | ( | int | index, | |
bool | enabled = true | |||
) |
Sets whether the use may drag a particular border.
This method sets whether the border that separates item index from the next item may be resized by the user, depending on the value of enabled.
The default value is false.
void Wt::WBoxLayout::setSpacing | ( | int | size | ) |
Sets spacing between each item.
The default spacing is 6 pixels.
bool Wt::WBoxLayout::setStretchFactor | ( | WLayout * | layout, | |
int | stretch | |||
) |
Sets the stretch factor for a nested layout.
The layout
must have previously been added to this layout using insertLayout() or addLayout().
Returns whether the stretch
could be set.
bool Wt::WBoxLayout::setStretchFactor | ( | WWidget * | widget, | |
int | stretch | |||
) |
Sets the stretch factor for a nested layout.
The widget
must have previously been added to this layout using insertWidget() or addWidget().
Returns whether the stretch
could be set.
int Wt::WBoxLayout::spacing | ( | ) | const [inline] |
Returns the spacing between each item.