public class LayeredLayout.LayeredLayoutConstraint extends Object
Modifier and Type | Class and Description |
---|---|
class |
LayeredLayout.LayeredLayoutConstraint.Inset
Encapsulates an inset.
|
Constructor and Description |
---|
LayeredLayoutConstraint() |
Modifier and Type | Method and Description |
---|---|
LayeredLayout.LayeredLayoutConstraint.Inset |
bottom()
Gets the bottom inset.
|
LayeredLayout.LayeredLayoutConstraint |
constraint()
Gets the constraint itself.
|
LayeredLayout.LayeredLayoutConstraint |
copy()
Makes a full copy of this inset.
|
LayeredLayout.LayeredLayoutConstraint |
copyTo(LayeredLayout.LayeredLayoutConstraint dest)
Copies the settings of this constraint into another constraint.
|
boolean |
dependsOn(Component cmp)
Checks to see if this constraint has the given component in its set of dependencies.
|
LayeredLayout.LayeredLayoutConstraint |
fixDependencies(Container parent)
Recursively fixes all dependencies so that they are contained inside
the provided parent.
|
Set<Component> |
getDependencies()
Gets the dependencies (i.e.
|
Set<Component> |
getDependencies(Set<Component> deps)
Gets the dependencies (i.e.
|
Collection<LayeredLayout.LayeredLayoutConstraint.Inset> |
getFixedInsets()
Gets the set of insets on this constraint that are fixed.
|
Collection<LayeredLayout.LayeredLayoutConstraint.Inset> |
getFlexibleInsets()
Gets the set of insets in this constraint that are flexible.
|
LayeredLayout.LayeredLayoutConstraint.Inset |
getInset(int inset)
Gets the inset for a particular side.
|
String |
getInsetsAsString(boolean withLabels)
Gets the insets of this constraint as a string.
|
float |
getPercentInsetAnchorHorizontal() |
float |
getPercentInsetAnchorVertical() |
Rectangle |
getReferenceBox(Container parent)
Returns a reference box within which insets of the given component are calculated.
|
Rectangle |
getReferenceBox(Container parent,
Component cmp)
Deprecated.
Use {@link #getReferenceBox(com.codename1.ui.Container)
|
Rectangle |
getReferenceBox(Container parent,
Component cmp2,
Rectangle box)
Deprecated.
|
Rectangle |
getReferenceBox(Container parent,
Rectangle box)
Returns a reference box within which insets of the given component are calculated.
|
String |
getReferenceComponentIndicesAsString(Container parent,
boolean withLabels)
Gets the reference component indexes within the provided parent container as a string.
|
String |
getReferencePositionsAsString(boolean withLabels)
Gets the reference positions of this constraint as a string.
|
boolean |
hasCircularDependency(Component start)
Checks to see if this constraint has any circular dependencies.
|
LayeredLayout.LayeredLayoutConstraint.Inset |
left()
Gets the left inset.
|
LayeredLayout.LayeredLayoutConstraint.Inset |
right()
Gets the right inset.
|
LayeredLayout.LayeredLayoutConstraint |
setInsets(String insetStr)
Sets the insets for this constraint as a string.
|
LayeredLayout.LayeredLayoutConstraint |
setPercentInsetAnchorHorizontal(float anchor)
Sets the anchor used for left and right percentage insets.
|
LayeredLayout.LayeredLayoutConstraint |
setPercentInsetAnchorVertical(float anchor)
Sets the anchor used for top and bottom percentage insets.
|
LayeredLayout.LayeredLayoutConstraint |
setReferenceComponentIndices(Container parent,
String indices)
Sets the reference components of the insets of this constraint as indices of the provided parent
container.
|
LayeredLayout.LayeredLayoutConstraint |
setReferenceComponents(Component... refs)
Sets the reference components for the constraint.
|
LayeredLayout.LayeredLayoutConstraint |
setReferencePositions(float... p)
Sets the reference positions for the constraint.
|
LayeredLayout.LayeredLayoutConstraint |
setReferencePositions(String positionsStr)
Sets the reference component positions for this constraint from a string.
|
LayeredLayout.LayeredLayoutConstraint.Inset |
top()
Gets the top inset
|
String |
toString()
Gets the insets as a string.
|
LayeredLayout.LayeredLayoutConstraint |
translateMM(float x,
float y,
boolean preferMM,
Container parent)
Shifts the constraint by the specified number of millimetres while maintaining the same units.
|
LayeredLayout.LayeredLayoutConstraint |
translatePixels(int x,
int y,
boolean preferMM,
Container parent)
Shifts the constraint by the specified number of pixels while maintaining the same units.
|
public String toString()
public LayeredLayout.LayeredLayoutConstraint fixDependencies(Container parent)
parent
- The parent container within which all dependencies should reside.setReferenceComponents(com.codename1.ui.Component...)
public boolean hasCircularDependency(Component start)
start
- The start component to check.public LayeredLayout.LayeredLayoutConstraint.Inset getInset(int inset)
inset
- One of Component.TOP
, Component.BOTTOM
, Component.LEFT
or
Component.RIGHT
.public LayeredLayout.LayeredLayoutConstraint copy()
public LayeredLayout.LayeredLayoutConstraint copyTo(LayeredLayout.LayeredLayoutConstraint dest)
dest
- The inset to copy to.public Rectangle getReferenceBox(Container parent, Rectangle box)
cmp
has no reference components in any of its insets, then the resulting box will
just bee the inner box of the parent (e.g. the parent's inner bounds.parent
- The parent container.parent
- box
- An out parameter. This will store the bounds of the box.public Rectangle getReferenceBox(Container parent, Component cmp2, Rectangle box)
getReferenceBox(com.codename1.ui.Container, com.codename1.ui.geom.Rectangle)
instead.cmp
has no reference components in any of its insets, then the resulting box will
just bee the inner box of the parent (e.g. the parent's inner bounds.parent
- The parent container.cmp
- The component whose reference box we are obtaining. Not used. May be null.box
- An out parameter. This will store the bounds of the box.public Rectangle getReferenceBox(Container parent, Component cmp)
cmp
has no reference components in any of its insets, then the resulting box will
just bee the inner box of the parent (e.g. the parent's inner bounds.parent
- The parent container.cmp
- The component whose reference box we are obtaining.public Rectangle getReferenceBox(Container parent)
cmp
has no reference components in any of its insets, then the resulting box will
just bee the inner box of the parent (e.g. the parent's inner bounds.parent
- The parent container.public LayeredLayout.LayeredLayoutConstraint translatePixels(int x, int y, boolean preferMM, Container parent)
x
- The number of pixels that the insets should be shifted on the x axis.y
- The number of pixels that the insets should be shifted on the y axis.preferMM
- If an inset needs to be switched from flexible to fixed, then this indicates where it will
be changed to millimetres or pixels. true for millimetres.parent
- The parent container in which calculations should be performed.translateMM(float, float, boolean, com.codename1.ui.Container)
public LayeredLayout.LayeredLayoutConstraint translateMM(float x, float y, boolean preferMM, Container parent)
x
- The number of pixels that the insets should be shifted on the x axis.y
- The number of pixels that the insets should be shifted on the y axis.preferMM
- If an inset needs to be switched from flexible to fixed, then this indicates where it will
be changed to millimetres or pixels. true for millimetres.parent
- The parent container in which calculations should be performed.translatePixels(int, int, boolean, com.codename1.ui.Container)
public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFixedInsets()
LayeredLayout.UNIT_AUTO
.public Collection<LayeredLayout.LayeredLayoutConstraint.Inset> getFlexibleInsets()
LayeredLayout.UNIT_AUTO
.public String getReferencePositionsAsString(boolean withLabels)
withLabels
- True to return the string in CSS format: e.g. "top:1.0; right:0; bottom:1.0; left:1.0"
false
to return as a space-delimited string of inset reference positions in the order "top right bottom left". E.g. "1.0 0 1.0 1.0"public LayeredLayout.LayeredLayoutConstraint setReferencePositions(String positionsStr)
If you provide the positions as a space-delimited string, then they are expected to follow the same format as is used in CSS for providing margin. To summarize:
//Apply to all four sides
1.0
//vertical | horizontal
1.0 0
// top | horizontal | bottom
1.0 0.0 0.5
// top | right | bottom | left
1.0 1.0 1.0 1.0
Interpretation of Reference Positions:
When an inset includes a reference component, that means that the inset is "anchored" to that reference component. I.e. An inset of 1mm is measured 1mm from the outer edge of the reference component. By default it chooses the edge of on the same side as the inset. So if this is a "left" inset, then it will measure against the "left" outer edge of the reference component. This is the meaning of a 0 value for the associated reference positions.
A reference position of 1.0 will start measuring from the opposite edge. So for a "left" inset, it will measure from the "right" outer edge of the reference component. You can choose any real value for the reference position, and it will cause the measurement to be scaled accordingly. E.g. 0.5. would measure from the center point of the reference component.
positionsStr
- The reference positions.public String getReferenceComponentIndicesAsString(Container parent, boolean withLabels)
Use the withLabels parameter to choose whether to include labels with the indices or not. E.g:
String indices = getReferenceComponentIndicesAsString(parent, true);
// Would return something like
// "top:-1; right:2; bottom:-1; left: 0"
indices = getReferenceComponentIndicesAsString(parent, false);
// Would return something like:
// "-1 2 -1 0" (i.e. Top Right Bottom Left)
// Interpretation:
// Top inset has no reference component
// Right inset has component with index 2 (i.e. parent.getComponentIndex(rightReferenceComponent) == 2)
// Bottom inset has no reference component
// Left inset has component with index 0 as a reference component.
parent
- withLabels
- public LayeredLayout.LayeredLayoutConstraint setReferenceComponentIndices(Container parent, String indices)
parent
- The parent container whose children are to be used as reference components.indices
- The indices to set as the reference components.
The string format may be either using labels following the same output format of cnst.getReferenceComponentIndicesAsString(true) or as a space-delimited string (e.g. cnst.getReferenceComponentIndicesAsString(false). When using the label format, you may provide one or more inset values in the string. E.g. the following are all acceptable:
If you provide the positions as a space-delimited string, then they are expected to follow the same format as is used in CSS for providing margin. To summarize:
//Set component at index 0 as reference for all 4 insets.
0
//vertical insets use component index 2 | horizontal insets use component index 1
2 1
// top | horizontal | bottom
-1 3 10
// top | right | bottom | left
-1 -1 -1 -1
Note: An index of -1 means that the corresponding inset has no reference component.
public String getInsetsAsString(boolean withLabels)
top:2mm; right:0; bottom:10%; left:auto
If withLabels is false then it will return a space-delimited string with the inset values ordered "top right bottom left" (the same as for CSS margins) order.
withLabels
- public LayeredLayout.LayeredLayoutConstraint setReferenceComponents(Component... refs)
refs
- May contain 1, 2, 3, or 4 values. If only 1 value is passed, then it is
set on all 4 insets. If two values are passed, then the first is set on the top and bottom
insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal).
If 3 values are passed, then, they are used for top, horizontal, and bottom.
If 4 values are passed, then they are used for top, right, bottom, left (in that order).public LayeredLayout.LayeredLayoutConstraint setReferencePositions(float... p)
Interpretation of Reference Positions:
When an inset includes a reference component, that means that the inset is "anchored" to that reference component. I.e. An inset of 1mm is measured 1mm from the outer edge of the reference component. By default it chooses the edge of on the same side as the inset. So if this is a "left" inset, then it will measure against the "left" outer edge of the reference component. This is the meaning of a 0 value for the associated reference positions.
A reference position of 1.0 will start measuring from the opposite edge. So for a "left" inset, it will measure from the "right" outer edge of the reference component. You can choose any real value for the reference position, and it will cause the measurement to be scaled accordingly. E.g. 0.5. would measure from the center point of the reference component.
p
- May contain 1, 2, 3, or 4 values. If only 1 value is passed, then it is
set on all 4 insets. If two values are passed, then the first is set on the top and bottom
insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal).
If 3 values are passed, then, they are used for top, horizontal, and bottom.
If 4 values are passed, then they are used for top, right, bottom, left (in that order).public LayeredLayout.LayeredLayoutConstraint setInsets(String insetStr)
If providing as a space-delimited string of inset values, then you can provide 1, 2, 3, or 4 values. If only 1 value is passed, then it is set on all 4 insets. If two values are passed, then the first is set on the top and bottom insets, and the 2nd is set on the left and right insets (i.e. vertical | horizontal). If 3 values are passed, then, they are used for top, horizontal, and bottom. If 4 values are passed, then they are used for top, right, bottom, left (in that order).
Example Inputs
insetStr
- public LayeredLayout.LayeredLayoutConstraint.Inset left()
public LayeredLayout.LayeredLayoutConstraint.Inset right()
public LayeredLayout.LayeredLayoutConstraint.Inset top()
public LayeredLayout.LayeredLayoutConstraint.Inset bottom()
public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorHorizontal(float anchor)
anchor
- public LayeredLayout.LayeredLayoutConstraint setPercentInsetAnchorVertical(float anchor)
anchor
- public float getPercentInsetAnchorHorizontal()
public float getPercentInsetAnchorVertical()
public LayeredLayout.LayeredLayoutConstraint constraint()
public Set<Component> getDependencies(Set<Component> deps)
deps
- A set to add the dependencies to. (An "out" parameter).public Set<Component> getDependencies()
public boolean dependsOn(Component cmp)
cmp
- The component to check.