public class Canvas extends Container
Each child is laid out at the position it has been given.
In a canvas, each child will have the size it has been given, or if desired, its optimal size.
NO_CONSTRAINT
Constructor and Description |
---|
Canvas()
Creates a canvas.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Widget child,
int x,
int y,
int width,
int height)
Adds the specified widget to this canvas.
|
void |
changeChildIndex(Widget child,
int index)
Changes the position of the specified widget in the list of children of this container.
|
protected void |
computeContentOptimalSize(Size size)
Computes the optimal size of the widget.
|
protected void |
layOutChildren(int contentWidth,
int contentHeight)
Lays out the children of this container.
|
void |
removeAllChildren()
Removes all the children of this container.
|
void |
removeChild(Widget child)
Removes the specified widget from the list of children of this container.
|
addChild, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, insertChild, layOutChild, renderChild, renderContent, replaceChild, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getDesktop, getHeight, getParent, getStyle, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle
public void addChild(Widget child, int x, int y, int width, int height)
If the given width or height is Widget.NO_CONSTRAINT
, the widget is fitted to its optimal width/height.
child
- the widget to add.x
- the x coordinate of the widget.y
- the y coordinate of the widget.width
- the width of the widget, or Widget.NO_CONSTRAINT
to use the widget optimal width.height
- the height of the widget, or Widget.NO_CONSTRAINT
to use the widget optimal height.NullPointerException
- if the specified widget is null
.IllegalArgumentException
- if the specified widget is already in a hierarchy (already contained in a container or desktop).Container.addChild(Widget)
public void changeChildIndex(Widget child, int index)
Container
changeChildIndex
in class Container
child
- the child to move.index
- the index at which the widget should be moved.protected void computeContentOptimalSize(Size size)
Widget
This method does not consider the border, margin, padding and dimension specified in the style.
The given size is the available size for this widget in its parent. A width or a height equal to
Widget#NO_CONSTRAINT
means that there is no constraint on this dimension.
The given size is modified to set the optimal size.
computeContentOptimalSize
in class Widget
size
- the size available for the content.protected void layOutChildren(int contentWidth, int contentHeight)
Container
The given size is the size of this container minus the border, margin and padding specified in the style.
When this method returns the children of this container have been lay out using
Container.layOutChild(Widget, int, int, int, int)
.
layOutChildren
in class Container
contentWidth
- the width available for the content.contentHeight
- the height available for the content.public void removeAllChildren()
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
removeAllChildren
in class Container
Widget.requestLayOut()
public void removeChild(Widget child)
Container
The container needs to be laid out again.
If the widget is not in the list of children of the container, nothing is done.
Should be called in the display thread to avoid concurrency issues.
removeChild
in class Container
child
- the widget to remove.Widget.requestLayOut()