Class WContainerWidget
- Direct Known Subclasses:
IndexContainerWidget,WAnchor,WDeferred,WFileDropWidget,WGroupBox,WMenuItem,WStackedWidget,WTableCell
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, and the resulting display is determined
by properties of the children and the container. By default, a WContainerWidget is displayed as a
block and manages its children within a rectangle.
Inline child widgets are layed out in lines, wrapping around as needed, while block child 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. Block children are then not allowed
(according to the HTML specification).
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.
Usage example:
// Example 1:
// Instantiate a container widget and add some children whose layout
// is governed based on HTML/CSS rules.
WContainerWidget container1 = new WContainerWidget();
container1.addWidget(new WText("Some text"));
container1.addWidget(new WImage("images/img.png"));
WContainerWidget child3 = new WContainerWidget(container1);
// Example 2:
// Instantiate a container widget which uses a layout manager
WContainerWidget container2 = new WContainerWidget();
// give the container a fixed height
container2.resize(WLength.Auto, new WLength(600));
WVBoxLayout layout = new WVBoxLayout();
layout.addWidget(new WText("Some text"));
layout.addWidget(new WImage("images/img.png"));
container2.setLayout(layout); // set the layout to the container.
When using a layout manager, you need to carefully consider the alignment of the layout
manager with respect to the container: when the container's height is unconstrained (not
specified explicitly using WWebWidget#resize() or a style class, and the container is not included in a layout manager),
you should pass AlignmentFlag.Top to setLayout().
CSS
Depending on its configuration and usage, the widget corresponds to the following HTML tags:
- By default, the widget corresponds to a
<div>tag. - When configured with setInline(true), the widget corresponds to a
<span>. - When configured with setList(true), the widget corresponds to a
<ul>. - When configured with setList(true, true), the widget corresponds to a
<ol>. - When inserted into a container widget that
isList(), the widget corresponds to a<li>.
This widget does not provide styling, and can be styled using inline or external CSS as appropriate.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefaultFields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionCreates a container.WContainerWidget(WContainerWidget parentContainer) Creates a container. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a child widget to this container.voidclear()Removes all widgets.protected DomElementCreate DOM element for widget.Returns the alignment of children.intgetCount()Returns the number of widgets in this container.protected voidgetDomChanges(List<DomElement> result, WApplication app) Get DOM changes for this widget.intgetIndexOf(WWidget widget) Returns the index of a widget.Returns the layout manager that was set for the container.getPadding(Side side) Returns the padding set for the widget.intreturn the number of pixels the container is scrolled verticallyintreturn the number of pixels the container is scrolled horizontallygetWidget(int index) Returns the widget at indexvoidinsertBefore(WWidget widget, WWidget before) Inserts a child widget in this container, before another widget.voidinsertWidget(int index, WWidget widget) Inserts a child widget in this container at given index.booleanbooleanisList()Returns if this container is rendered as a List.booleanReturns if this container is rendered as an Ordered List.booleanReturns if this container is rendered as an Unordered List.protected voiditerateChildren(HandleWidgetMethod method) protected voidparentResized(WWidget parent, EnumSet<Orientation> directions) voidremove()Destructor.removeWidget(WWidget widget) Removes a child widget from this container.scrolled()Event signal emitted when scrolling in the widget.final voidsetContentAlignment(AlignmentFlag alignmen, AlignmentFlag... alignment) Specifies how child widgets must be aligned within the container.voidsetContentAlignment(EnumSet<AlignmentFlag> alignment) Specifies how child widgets must be aligned within the container.protected voidsetFormData(WObject.FormData formData) voidsetGlobalUnfocused(boolean b) voidSets a layout manager for the container.final voidsetList(boolean list) Renders the container as an HTML list.voidsetList(boolean list, boolean ordered) Renders the container as an HTML list.final voidsetOverflow(Overflow value) Sets how overflow of contained children must be handled.final voidsetOverflow(Overflow value, Orientation orientatio, Orientation... orientation) Sets how overflow of contained children must be handled.voidsetOverflow(Overflow value, EnumSet<Orientation> orientation) Sets how overflow of contained children must be handled.final voidsetPadding(WLength length) Sets padding inside the widget.final voidsetPadding(WLength length, Side side, Side... sides) Sets padding inside the widget.voidsetPadding(WLength length, EnumSet<Side> sides) Sets padding inside the widget.Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, render, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggableMethods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, enableAjax, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemovedMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WContainerWidget
Creates a container. -
WContainerWidget
public WContainerWidget()Creates a container.
-
-
Method Details
-
remove
public void remove()Destructor.- Overrides:
removein classWInteractWidget- See Also:
-
setLayout
Sets a layout manager for the container.Note that you can nest layout managers inside each other, to create a complex layout hierarchy.
If a previous layout manager was already set, it is first deleted. In that case, you will need to make sure that you either readd all widgets that were part of the previous layout to the new layout, or delete them, to avoid memory leaks.
- See Also:
-
getLayout
Returns the layout manager that was set for the container.If no layout manager was previously set using setLayout(
WLayout*), 0 is returned. -
addWidget
Adds a child widget to this container.The widget is appended to the list of children, and thus also layed-out at the end.
If, for some reason, you want to be in control of the lifetime of the widget, you can retrieve a unique_ptr with WObject::removeChild()
-
insertBefore
Inserts a child widget in this container, before another widget.The widget is inserted at the place of the
beforewidget, and subsequent widgets are shifted.If, for some reason, you want to be in control of the lifetime of the widget, you can regain ownership of the widget (without any functional implication) using WObject::removeChild()
-
insertWidget
Inserts a child widget in this container at given index.The widget is inserted at the given
index, and subsequent widgets are shifted.If, for some reason, you want to be in control of the lifetime of the widget, you can regain ownership of the widget (without any functional implication) using WObject::removeChild()
-
removeWidget
Removes a child widget from this container.If the
WContainerWidgetowns the given widget (i.e. if it was added withaddWidget()orinsertWidget()and not removed with WObject::removeChild()), a unique_ptr to this widget is returned. Otherwise, this returns nullptr.- Overrides:
removeWidgetin classWWidget
-
clear
public void clear()Removes all widgets.This removes all children that have been added to this container. If a layout was set, also the layout manager is cleared.
-
getIndexOf
Returns the index of a widget. -
getWidget
Returns the widget at index -
getCount
public int getCount()Returns the number of widgets in this container. -
setContentAlignment
Specifies how child widgets must be aligned within the container.For a
WContainerWidget, only specifes 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.For a
WTableCell, this may also specify the vertical alignment. The default alignment is (AlignmentFlag.Top|AlignmentFlag.Left). -
setContentAlignment
Specifies how child widgets must be aligned within the container. -
setPadding
Sets padding inside the widget.Setting padding has the effect of adding distance between the widget children and the border.
-
setPadding
Sets padding inside the widget. -
setPadding
Sets padding inside the widget. -
getPadding
Returns the padding set for the widget.- See Also:
-
getContentAlignment
Returns the alignment of children.- See Also:
-
setOverflow
Sets how overflow of contained children must be handled. -
setOverflow
Sets how overflow of contained children must be handled.Calls
setOverflow(value, EnumSet.of(orientatio, orientation)) -
setOverflow
Sets how overflow of contained children must be handled.Calls
setOverflow(value, EnumSet.of (Orientation.Horizontal, Orientation.Vertical)) -
setList
public void setList(boolean list, boolean ordered) Renders the container as an HTML list.Setting
renderListtotruewill cause the container to be using an HTML<ul>or<ol>type, depending on the value oforderedList. This must be set before the initial render of the container. When set, any containedWContainerWidgetwill 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.- See Also:
-
setList
public final void setList(boolean list) Renders the container as an HTML list.Calls
setList(list, false) -
isList
public boolean isList()Returns if this container is rendered as a List.- See Also:
-
isUnorderedList
public boolean isUnorderedList()Returns if this container is rendered as an Unordered List.- See Also:
-
isOrderedList
public boolean isOrderedList()Returns if this container is rendered as an Ordered List.- See Also:
-
scrolled
Event signal emitted when scrolling in the widget.This event is emitted when the user scrolls in the widget (for setting the scroll bar policy, see
setOverflow()). The event conveys details such as the new scroll bar position, the total contents height and the current widget height.- See Also:
-
getScrollTop
public int getScrollTop()return the number of pixels the container is scrolled horizontallyThis value is only set if
setOverflow()has been called- See Also:
-
getScrollLeft
public int getScrollLeft()return the number of pixels the container is scrolled verticallyThis value is only set if
setOverflow()has been called- See Also:
-
setGlobalUnfocused
public void setGlobalUnfocused(boolean b) -
isGlobalUnfocussed
public boolean isGlobalUnfocussed() -
parentResized
- Overrides:
parentResizedin classWWebWidget
-
getDomChanges
Description copied from class:WWebWidgetGet DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChangesin classWWebWidget
-
iterateChildren
- Overrides:
iterateChildrenin classWWebWidget
-
createDomElement
Description copied from class:WWebWidgetCreate DOM element for widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
createDomElementin classWWebWidget
-
setFormData
- Overrides:
setFormDatain classWObject
-