ConstraintAnchor
public class ConstraintAnchor
Model a constraint relation. Widgets contains anchors, and a constraint relation between two widgets is made by connecting one anchor to another. The anchor will contains a pointer to the target anchor if it is connected.
Summary
Nested types |
|---|
public enum ConstraintAnchor.TypeDefine the type of anchor |
Public fields |
|
|---|---|
int |
|
final ConstraintWidget |
|
ConstraintAnchor |
|
final ConstraintAnchor.Type |
Public constructors |
|---|
ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)Constructor |
Public methods |
|
|---|---|
boolean |
connect(ConstraintAnchor toAnchor, int margin)Connects this anchor to another one. |
boolean |
connect(Connects this anchor to another one. |
void |
copyFrom( |
void |
findDependents( |
HashSet<ConstraintAnchor> |
|
int |
|
int |
Return the connection's margin from this anchor to its target. |
final ConstraintAnchor |
Returns the opposite anchor to this one |
ConstraintWidget |
getOwner()Return the anchor's owner |
SolverVariable |
Return the solver variable for this anchor |
ConstraintAnchor |
Return the connection's target (null if not connected) |
ConstraintAnchor.Type |
getType()Return the type of the anchor |
boolean |
|
boolean |
|
boolean |
|
boolean |
Returns the connection status of this anchor |
boolean |
isConnectionAllowed(ConstraintWidget target)Return true if we can connect this anchor to this target. |
boolean |
isConnectionAllowed(ConstraintWidget target, ConstraintAnchor anchor)Return true if we can connect this anchor to this target. |
boolean |
Return true if this anchor is a side anchor |
boolean |
Return true if the connection to the given anchor is in the same dimension (horizontal or vertical) |
boolean |
isValidConnection(ConstraintAnchor anchor)Checks if the connection to a given anchor is valid. |
boolean |
Utility function returning true if this anchor is a vertical one. |
void |
reset()Resets the anchor's connection. |
void |
|
void |
resetSolverVariable(Cache cache)Reset the solver variable |
void |
setFinalValue(int finalValue) |
void |
setGoneMargin(int margin)Set the gone margin of the connection (if there's one) |
void |
setMargin(int margin)Set the margin of the connection (if there's one) |
String |
toString()Return a string representation of this anchor |
Public fields
Public constructors
ConstraintAnchor
public ConstraintAnchor(ConstraintWidget owner, ConstraintAnchor.Type type)
Constructor
| Parameters | |
|---|---|
ConstraintWidget owner |
the widget owner of this anchor. |
ConstraintAnchor.Type type |
the anchor type. |
Public methods
connect
public boolean connect(ConstraintAnchor toAnchor, int margin)
Connects this anchor to another one.
| Returns | |
|---|---|
boolean |
true if the connection succeeds. |
connect
public boolean connect(
ConstraintAnchor toAnchor,
int margin,
int goneMargin,
boolean forceConnection
)
Connects this anchor to another one.
| Returns | |
|---|---|
boolean |
true if the connection succeeds. |
copyFrom
public void copyFrom(
ConstraintAnchor source,
HashMap<ConstraintWidget, ConstraintWidget> map
)
findDependents
public void findDependents(
int orientation,
ArrayList<WidgetGroup> list,
WidgetGroup group
)
getMargin
public int getMargin()
Return the connection's margin from this anchor to its target.
| Returns | |
|---|---|
int |
the margin value. 0 if not connected. |
getOpposite
public final ConstraintAnchor getOpposite()
Returns the opposite anchor to this one
| Returns | |
|---|---|
ConstraintAnchor |
opposite anchor |
getOwner
public ConstraintWidget getOwner()
Return the anchor's owner
| Returns | |
|---|---|
ConstraintWidget |
the Widget owning the anchor |
getSolverVariable
public SolverVariable getSolverVariable()
Return the solver variable for this anchor
getTarget
public ConstraintAnchor getTarget()
Return the connection's target (null if not connected)
| Returns | |
|---|---|
ConstraintAnchor |
the ConstraintAnchor target |
getType
public ConstraintAnchor.Type getType()
Return the type of the anchor
| Returns | |
|---|---|
ConstraintAnchor.Type |
type of the anchor. |
isConnected
public boolean isConnected()
Returns the connection status of this anchor
| Returns | |
|---|---|
boolean |
true if the anchor is connected to another one. |
isConnectionAllowed
public boolean isConnectionAllowed(ConstraintWidget target)
Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.
| Parameters | |
|---|---|
ConstraintWidget target |
the ConstraintWidget we are trying to connect to |
| Returns | |
|---|---|
boolean |
true if the connection is allowed, false otherwise |
isConnectionAllowed
public boolean isConnectionAllowed(ConstraintWidget target, ConstraintAnchor anchor)
Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.
| Parameters | |
|---|---|
ConstraintWidget target |
the ConstraintWidget we are trying to connect to |
ConstraintAnchor anchor |
Allow anchor if it loops back to me directly |
| Returns | |
|---|---|
boolean |
if the connection is allowed, false otherwise |
isSideAnchor
public boolean isSideAnchor()
Return true if this anchor is a side anchor
| Returns | |
|---|---|
boolean |
true if side anchor |
isSimilarDimensionConnection
public boolean isSimilarDimensionConnection(ConstraintAnchor anchor)
Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)
| Parameters | |
|---|---|
ConstraintAnchor anchor |
the anchor we want to connect to |
| Returns | |
|---|---|
boolean |
true if it's an anchor on the same dimension |
isValidConnection
public boolean isValidConnection(ConstraintAnchor anchor)
Checks if the connection to a given anchor is valid.
| Parameters | |
|---|---|
ConstraintAnchor anchor |
the anchor we want to connect to |
| Returns | |
|---|---|
boolean |
true if it's a compatible anchor |
isVerticalAnchor
public boolean isVerticalAnchor()
Utility function returning true if this anchor is a vertical one.
| Returns | |
|---|---|
boolean |
true if vertical anchor, false otherwise |
resetSolverVariable
public void resetSolverVariable(Cache cache)
Reset the solver variable
setGoneMargin
public void setGoneMargin(int margin)
Set the gone margin of the connection (if there's one)
| Parameters | |
|---|---|
int margin |
the new margin of the connection |