use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.
the class SnapDraw method drawSnapVerticalIndicator.
/**
* Draw a snap indicator for vertical anchors
*
* @param transform view transform
* @param g Graphics context
* @param candidate the snap candidate
*/
private static void drawSnapVerticalIndicator(ViewTransform transform, Graphics2D g, SnapCandidate candidate) {
ConstraintAnchor source = candidate.source;
ConstraintAnchor target = candidate.target;
ConstraintHandle sourceHandle = WidgetInteractionTargets.constraintHandle(source);
ConstraintHandle targetHandle = WidgetInteractionTargets.constraintHandle(target);
int y = transform.getSwingY(candidate.y);
if (targetHandle != null) {
y = transform.getSwingY(targetHandle.getDrawY());
}
int x1 = transform.getSwingX(source.getOwner().getDrawX());
int x2 = transform.getSwingX(source.getOwner().getDrawX() + source.getOwner().getDrawWidth());
int x3 = transform.getSwingX(target.getOwner().getDrawX());
int x4 = transform.getSwingX(target.getOwner().getDrawX() + target.getOwner().getDrawWidth());
int minX = Math.min(x1, x3);
int maxX = Math.max(x2, x4);
if (candidate.margin != 0) {
int y2 = transform.getSwingY(sourceHandle.getDrawY());
String textMargin = "" + Math.abs(candidate.margin);
int xS = x2;
int xT = x4 + OVER_MARGIN / 2;
int mX = xS + OVER_MARGIN;
if (x1 < x3) {
xS = x1;
xT = x3 - OVER_MARGIN / 2;
mX = xS - OVER_MARGIN;
}
drawSnapVerticalMargin(transform, g, mX, y, y2, textMargin);
Graphics2D g2 = (Graphics2D) g.create();
g2.setStroke(sDashedStroke);
g2.drawLine(xS, y, xT, y);
g2.dispose();
} else {
Graphics2D g2 = (Graphics2D) g.create();
boolean insideIndicator = (source.getOwner().getParent() == candidate.target.getOwner()) || (candidate.target.getOwner() instanceof Guideline);
if (insideIndicator) {
g2.setStroke(sLongDashedStroke);
g2.drawLine(minX, y, maxX, y);
} else {
g2.setStroke(sDashedStroke);
g2.drawLine(minX - OVER, y, maxX + OVER, y);
}
g2.dispose();
}
}
use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.
the class SnapDraw method drawSnapHorizontalIndicator.
/**
* Draw a snap indicator for horizontal anchors
*
* @param transform view transform
* @param g Graphics context
* @param candidate the snap candidate
*/
private static void drawSnapHorizontalIndicator(ViewTransform transform, Graphics2D g, SnapCandidate candidate) {
ConstraintAnchor source = candidate.source;
ConstraintAnchor target = candidate.target;
ConstraintHandle sourceHandle = WidgetInteractionTargets.constraintHandle(source);
ConstraintHandle targetHandle = WidgetInteractionTargets.constraintHandle(target);
int x = transform.getSwingX(candidate.x);
if (targetHandle != null) {
x = transform.getSwingX(targetHandle.getDrawX());
}
int y1 = transform.getSwingY(source.getOwner().getDrawY());
int y2 = transform.getSwingY(source.getOwner().getDrawY() + source.getOwner().getHeight());
int y3 = transform.getSwingY(target.getOwner().getDrawY());
int y4 = transform.getSwingY(target.getOwner().getDrawY() + target.getOwner().getHeight());
int minY = Math.min(y1, y3);
int maxY = Math.max(y2, y4);
if (candidate.margin != 0) {
int x2 = transform.getSwingX(sourceHandle.getDrawX());
String textMargin = String.valueOf(Math.abs(candidate.margin));
int yS = y2;
int yT = y4 + OVER_MARGIN / 2;
int mY = yS + OVER_MARGIN;
boolean textOver = false;
if (y1 < y3) {
yS = y1;
yT = y3 - OVER_MARGIN / 2;
mY = yS - OVER_MARGIN;
textOver = true;
}
drawSnapHorizontalMargin(transform, g, x, x2, mY, textMargin, textOver);
Graphics2D g2 = (Graphics2D) g.create();
g2.setStroke(sDashedStroke);
g2.drawLine(x, yS, x, yT);
g2.dispose();
} else {
Graphics2D g2 = (Graphics2D) g.create();
boolean insideIndicator = (source.getOwner().getParent() == candidate.target.getOwner()) || (candidate.target.getOwner() instanceof Guideline);
if (insideIndicator) {
g2.setStroke(sLongDashedStroke);
g2.drawLine(x, minY, x, maxY);
} else {
g2.setStroke(sDashedStroke);
g2.drawLine(x, minY - OVER, x, maxY + OVER);
}
g2.dispose();
}
}
use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.
the class WidgetDraw method drawWidgetFrame.
/**
* Draw the widget frame (resizable area...) as well as
* the constraints anchors and their state.
* The color and style used for the drawing will be the current ones in the graphics context.
*
* @param transform view transform
* @param g Graphics context
* @param widget the widget we are drawing
* @param showAnchors determinate how to display the Constraints anchors points
* @param showResizeHandles pass true to show Resize handles
* @param isSelected if the widget is currently selected
*/
public static void drawWidgetFrame(ViewTransform transform, Graphics2D g, ConstraintWidget widget, EnumSet<ANCHORS_DISPLAY> showAnchors, boolean showResizeHandles, boolean showSizeIndicator, boolean isSelected) {
g.setStroke(SnapDraw.sNormalStroke);
int l = transform.getSwingX(widget.getDrawX());
int t = transform.getSwingY(widget.getDrawY());
int w = transform.getSwingDimension(widget.getDrawWidth());
int h = transform.getSwingDimension(widget.getDrawHeight());
int r = transform.getSwingX(widget.getDrawX() + widget.getDrawWidth());
int b = transform.getSwingY(widget.getDrawY() + widget.getDrawHeight());
int radius = ConnectionDraw.CONNECTION_ANCHOR_SIZE;
int radiusRect = ConnectionDraw.CONNECTION_RESIZE_SIZE;
int rectDimension = radiusRect * 2;
int midX = transform.getSwingX((int) (widget.getDrawX() + widget.getDrawWidth() / 2f));
int midY = transform.getSwingY((int) (widget.getDrawY() + widget.getDrawHeight() / 2f));
if (widget.getParent() instanceof ConstraintWidgetContainer) {
ConstraintWidgetContainer parent = (ConstraintWidgetContainer) widget.getParent();
if (widget instanceof Guideline) {
if (parent.isRootContainer()) {
drawRootGuideline(transform, g, parent, (Guideline) widget, isSelected);
}
return;
}
}
if (widget.getVisibility() == ConstraintWidget.INVISIBLE) {
g.setStroke(SnapDraw.sDashedStroke);
}
ConstraintAnchor leftAnchor = widget.getAnchor(ConstraintAnchor.Type.LEFT);
ConstraintAnchor rightAnchor = widget.getAnchor(ConstraintAnchor.Type.RIGHT);
ConstraintAnchor topAnchor = widget.getAnchor(ConstraintAnchor.Type.TOP);
ConstraintAnchor bottomAnchor = widget.getAnchor(ConstraintAnchor.Type.BOTTOM);
boolean leftAnchorIsConnected = leftAnchor.isConnected();
boolean rightAnchorIsConnected = rightAnchor.isConnected();
boolean topAnchorIsConnected = topAnchor.isConnected();
boolean bottomAnchorIsConnected = bottomAnchor.isConnected();
boolean baselineAnchorIsConnected = widget.getAnchor(ConstraintAnchor.Type.BASELINE).isConnected();
boolean centerAnchorIsConnected = (leftAnchorIsConnected && rightAnchorIsConnected && leftAnchor.getTarget() == rightAnchor.getTarget()) || (topAnchorIsConnected && bottomAnchorIsConnected && topAnchor.getTarget() == bottomAnchor.getTarget());
// First, resize handles...
if (showResizeHandles) {
g.fillRect(l - radiusRect, t - radiusRect, rectDimension, rectDimension);
g.fillRect(r - radiusRect, t - radiusRect, rectDimension, rectDimension);
g.fillRect(l - radiusRect, b - radiusRect, rectDimension, rectDimension);
g.fillRect(r - radiusRect, b - radiusRect, rectDimension, rectDimension);
if (showSizeIndicator) {
ConnectionDraw.drawHorizontalMarginIndicator(g, String.valueOf(widget.getWidth()), l, r, t - 20);
ConnectionDraw.drawVerticalMarginIndicator(g, String.valueOf(widget.getHeight()), l - 20, t, b);
}
}
// Then, let's draw the constraints anchors
boolean displayAllAnchors = showAnchors.contains(ANCHORS_DISPLAY.ALL);
boolean showLeftAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.LEFT) || showAnchors.contains(ANCHORS_DISPLAY.HORIZONTAL);
boolean showRightAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.RIGHT) || showAnchors.contains(ANCHORS_DISPLAY.HORIZONTAL);
boolean showTopAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.TOP) || showAnchors.contains(ANCHORS_DISPLAY.VERTICAL);
boolean showBottomAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.BOTTOM) || showAnchors.contains(ANCHORS_DISPLAY.VERTICAL);
boolean showCenterAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.CENTER);
boolean showBaselineAnchor = displayAllAnchors || showAnchors.contains(ANCHORS_DISPLAY.BASELINE);
if (!showAnchors.contains(ANCHORS_DISPLAY.NONE) && showAnchors.contains(ANCHORS_DISPLAY.CONNECTED)) {
showLeftAnchor |= leftAnchorIsConnected;
showRightAnchor |= rightAnchorIsConnected;
showTopAnchor |= topAnchorIsConnected;
showBottomAnchor |= bottomAnchorIsConnected;
showCenterAnchor |= centerAnchorIsConnected;
showBaselineAnchor |= baselineAnchorIsConnected;
}
if (showBaselineAnchor && !(widget instanceof ConstraintWidgetContainer) && widget.getBaselineDistance() > 0) {
int baselineY = transform.getSwingY(WidgetInteractionTargets.constraintHandle(widget.getAnchor(ConstraintAnchor.Type.BASELINE)).getDrawY());
g.drawLine(l, baselineY, r, baselineY);
}
// Now, let's draw the widget's frame
boolean horizontalSpring = widget.getHorizontalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT;
boolean verticalSpring = widget.getVerticalDimensionBehaviour() == ConstraintWidget.DimensionBehaviour.MATCH_CONSTRAINT;
Graphics2D g2 = (Graphics2D) g.create();
if (widget instanceof ConstraintWidgetContainer) {
g2.setStroke(SnapDraw.sLongDashedStroke);
if (widget instanceof ConstraintTableLayout) {
drawTableLayoutGuidelines(transform, g2, (ConstraintTableLayout) widget);
}
}
if (!widget.isRootContainer() && (horizontalSpring || verticalSpring)) {
int x = l;
int y = t;
Stroke previousStroke = g.getStroke();
if (baselineAnchorIsConnected) {
g2.setStroke(ConnectionDraw.sSpreadDashedStroke);
}
if (horizontalSpring) {
if (showTopAnchor) {
drawHorizontalZigZagLine(g2, l, midX - radius, t, ZIGZAG, 0);
drawHorizontalZigZagLine(g2, midX + radius, r, t, ZIGZAG, 0);
} else {
drawHorizontalZigZagLine(g2, l, r, t, ZIGZAG, 0);
}
if (showBottomAnchor) {
drawHorizontalZigZagLine(g2, l, midX - radius, b, -ZIGZAG, 0);
drawHorizontalZigZagLine(g2, midX + radius, r, b, -ZIGZAG, 0);
} else {
drawHorizontalZigZagLine(g2, l, r, b, -ZIGZAG, 0);
}
} else {
g2.drawLine(x, y, x + w, y);
g2.drawLine(x, y + h, x + w, y + h);
}
g2.setStroke(previousStroke);
if (verticalSpring) {
if (showLeftAnchor) {
drawVerticalZigZagLine(g2, l, t, midY - radius, ZIGZAG, 0);
drawVerticalZigZagLine(g2, l, midY + radius, b, ZIGZAG, 0);
} else {
drawVerticalZigZagLine(g2, l, t, b, ZIGZAG, 0);
}
if (showRightAnchor) {
drawVerticalZigZagLine(g2, r, t, midY - radius, -ZIGZAG, 0);
drawVerticalZigZagLine(g2, r, midY + radius, b, -ZIGZAG, 0);
} else {
drawVerticalZigZagLine(g2, r, t, b, -ZIGZAG, 0);
}
} else {
g2.drawLine(x, y, x, y + h);
g2.drawLine(x + w, y, x + w, y + h);
}
} else {
Stroke previousStroke = g.getStroke();
if (baselineAnchorIsConnected) {
g2.setStroke(ConnectionDraw.sSpreadDashedStroke);
}
if (showTopAnchor) {
g2.drawLine(l, t, midX - radius, t);
g2.drawLine(midX + radius, t, r, t);
} else {
g2.drawLine(l, t, r, t);
}
if (showBottomAnchor) {
g2.drawLine(l, b, midX - radius, b);
g2.drawLine(midX + radius, b, r, b);
} else {
g2.drawLine(l, b, r, b);
}
g2.setStroke(previousStroke);
if (showLeftAnchor) {
g2.drawLine(l, t, l, midY - radius);
g2.drawLine(l, midY + radius, l, b);
} else {
g2.drawLine(l, t, l, b);
}
if (showRightAnchor) {
g2.drawLine(r, t, r, midY - radius);
g2.drawLine(r, midY + radius, r, b);
} else {
g2.drawLine(r, t, r, b);
}
}
g2.dispose();
if (DEBUG) {
// Draw diagonals
g.drawLine(l, t, r, b);
g.drawLine(l, b, r, t);
}
g.setStroke(SnapDraw.sNormalStroke);
}
use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.
the class ConstraintHandle method addPathConnection.
/**
* Add to a given path to represent a single connection
*
* @param transform the view transform
* @param g the graphics context
* @param isSelected if the connection is selected
* @param showMargin
* @param drawing the drawing we are adding to
* @param colorSet the current colorset
*/
private void addPathConnection(ViewTransform transform, Graphics2D g, boolean isSelected, boolean showMargin, ConnectionDrawing drawing, ColorSet colorSet, int targetX, int targetY, boolean isConnected, boolean isTargetConnected) {
int radius = 4;
int sradius = transform.getSwingDimension(radius);
int scurvature = transform.getSwingDimension(2);
int scurvature2 = transform.getSwingDimension(3);
int marginLineOffset = transform.getSwingDimension(16);
boolean isVertical = mAnchor.isVerticalAnchor();
int x0 = transform.getSwingFX(mX);
int y0 = transform.getSwingFY(mY);
int x1 = transform.getSwingFX(targetX);
int y1 = transform.getSwingFY(targetY);
drawing.mPath.moveTo(x0, y0);
int distanceX = Math.abs(targetX - mX);
int distanceY = Math.abs(targetY - mY);
int distance = (int) Math.sqrt(distanceX * distanceX + distanceY * distanceY);
int maxDistance = Math.min(24 + (int) (0.1f * distance), 64);
maxDistance = distance > maxDistance ? maxDistance : distance;
int controlDistance = transform.getSwingDimension(maxDistance);
if (isTargetConnected) {
if (isVertical) {
x1 = x0 < x1 ? x1 - sConnectionOffset : x1 + sConnectionOffset;
} else {
y1 = y0 < y1 ? y1 - sConnectionOffset : y1 + sConnectionOffset;
}
}
// If the connection points to our parent, draw the connection in a straight line
boolean beStraight = mAnchor.isConnected() && mAnchor.getTarget().getOwner() == getOwner().getParent();
if (beStraight) {
if (isVertical) {
x1 = x0;
} else {
y1 = y0;
}
}
if (isVertical) {
boolean isBaseline = mAnchor.getType() == ConstraintAnchor.Type.BASELINE;
boolean isTopConnection = mAnchor.getType() == ConstraintAnchor.Type.TOP;
isTopConnection |= isBaseline;
if (isTopConnection) {
controlDistance = -controlDistance;
}
if (isConnected && mAnchor.getTarget() != null && mAnchor.getType() == mAnchor.getTarget().getType() && !isBaseline && mAnchor.getMargin() == 0) {
int base = y0 - sradius - ConnectionDraw.ARROW_SIDE;
if (!isTopConnection) {
base = y0 + sradius + ConnectionDraw.ARROW_SIDE;
}
if (x0 > x1) {
sradius = -sradius;
}
addQuarterArc(drawing.mPath, x0, y0, x0 + sradius, base, scurvature, true);
drawing.mPath.lineTo(x1 - 2 * sradius, base);
int yt = y1 - ConnectionDraw.ARROW_SIDE;
if (!isTopConnection) {
yt = y1 + ConnectionDraw.ARROW_SIDE;
}
addQuarterArc(drawing.mPath, x1 - 2 * sradius, base, x1, yt, scurvature2, false);
if (isTopConnection) {
drawing.setArrow(ConnectionDraw.getBottomArrow(), x1, y1);
} else {
drawing.setArrow(ConnectionDraw.getTopArrow(), x1, y1);
}
} else {
if (isBaseline) {
drawing.mDrawEndCircle = false;
// In case of baseline connections, we don't want to connect directly from the
// center of the widget (where the baseline anchor (mX, mY) is, so we offset a little
int offset1 = (int) (transform.getSwingDimension(mAnchor.getOwner().getDrawWidth()) * 0.2f);
int offset2 = 0;
if (mAnchor.getTarget() != null) {
ConstraintWidget widget = mAnchor.getTarget().getOwner();
offset2 = (int) (transform.getSwingDimension(widget.getDrawWidth()) * 0.2f);
int tl = transform.getSwingX(widget.getDrawX());
int tr = transform.getSwingX(widget.getDrawRight());
int tt = transform.getSwingY(widget.getDrawY());
int tb = transform.getSwingDimension(widget.getBaselineDistance());
Shape line = new Line2D.Float(tl, tt + tb, tr, tt + tb);
drawing.addShape(line);
}
if (x0 < x1) {
x0 += offset1;
x1 -= offset2;
} else {
x0 -= offset1;
x1 += offset2;
}
drawing.mPath.moveTo(x0, y0);
}
int cx1 = x0;
int cy1 = y0 + controlDistance;
int cx2 = x1;
int cy2 = y1 - controlDistance;
int yt = y1 + ConnectionDraw.ARROW_SIDE;
if (!isTopConnection) {
yt = y1 - ConnectionDraw.ARROW_SIDE;
}
drawing.mPath.curveTo(cx1, cy1, cx2, cy2, x1, yt);
if (!isTopConnection) {
drawing.setArrow(ConnectionDraw.getBottomArrow(), x1, y1);
} else {
drawing.setArrow(ConnectionDraw.getTopArrow(), x1, y1);
}
}
if ((colorSet.alwaysShowMargins() || isSelected) && mAnchor.getMargin() > 0 && showMargin) {
Color pre = g.getColor();
g.setColor(colorSet.getMargins());
// We may want to position the margin draw a little offset to the center,
// depending on the direction of the other connections
int marginPosition;
ConstraintAnchor left = getOwner().getAnchor(ConstraintAnchor.Type.LEFT);
ConstraintAnchor right = getOwner().getAnchor(ConstraintAnchor.Type.RIGHT);
boolean centerConnectionAnchor = (left != null && right != null && left.isConnected() && left.getTarget() == right.getTarget());
boolean drawMarginToTheRight = x0 > x1;
if (centerConnectionAnchor) {
if (left.getTarget().getType() == ConstraintAnchor.Type.LEFT) {
drawMarginToTheRight = true;
} else {
drawMarginToTheRight = false;
}
}
if (drawMarginToTheRight) {
marginPosition = x0 + marginLineOffset;
} else {
marginPosition = x0 - marginLineOffset;
}
Stroke pres = g.getStroke();
g.setStroke(sSimpleStroke);
ConnectionDraw.drawVerticalMarginIndicator(g, String.valueOf(mAnchor.getMargin()), marginPosition, y0, y1);
g.setStroke(ConnectionDraw.sDashedStroke);
if (x0 > x1) {
g.drawLine(marginPosition + marginLineOffset, y1, x1, y1);
} else {
g.drawLine(marginPosition - marginLineOffset, y1, x1, y1);
}
g.setColor(pre);
g.setStroke(pres);
}
} else {
boolean isLeftConnection = mAnchor.getType() == ConstraintAnchor.Type.LEFT;
if (isLeftConnection) {
controlDistance = -controlDistance;
}
if (isConnected && mAnchor.getTarget() != null && mAnchor.getType() == mAnchor.getTarget().getType() & mAnchor.getMargin() == 0) {
int base = x0 - sradius - ConnectionDraw.ARROW_SIDE;
if (!isLeftConnection) {
base = x0 + sradius + ConnectionDraw.ARROW_SIDE;
}
if (y0 > y1) {
sradius = -sradius;
}
addQuarterArc(drawing.mPath, x0, y0, base, y0 + sradius, scurvature, false);
drawing.mPath.lineTo(base, y1 - 2 * sradius);
int xt = x1 - ConnectionDraw.ARROW_SIDE;
if (!isLeftConnection) {
xt = x1 + ConnectionDraw.ARROW_SIDE;
}
addQuarterArc(drawing.mPath, base, y1 - 2 * sradius, xt, y1, scurvature2, true);
if (isLeftConnection) {
drawing.setArrow(ConnectionDraw.getRightArrow(), x1, y1);
} else {
drawing.setArrow(ConnectionDraw.getLeftArrow(), x1, y1);
}
} else {
int cx1 = x0 + controlDistance;
int cy1 = y0;
int cx2 = x1 - controlDistance;
int cy2 = y1;
int xt = x1 + ConnectionDraw.ARROW_SIDE;
if (!isLeftConnection) {
xt = x1 - ConnectionDraw.ARROW_SIDE;
}
drawing.mPath.curveTo(cx1, cy1, cx2, cy2, xt, y1);
if (!isLeftConnection) {
drawing.setArrow(ConnectionDraw.getRightArrow(), x1, y1);
} else {
drawing.setArrow(ConnectionDraw.getLeftArrow(), x1, y1);
}
}
if ((colorSet.alwaysShowMargins() || isSelected) && mAnchor.getMargin() > 0 && showMargin) {
Color pre = g.getColor();
g.setColor(colorSet.getMargins());
// We may want to position the margin draw a little offset to the center,
// depending on the direction of the other connections
int marginPosition;
ConstraintAnchor top = getOwner().getAnchor(ConstraintAnchor.Type.TOP);
ConstraintAnchor bottom = getOwner().getAnchor(ConstraintAnchor.Type.BOTTOM);
boolean centerConnectionAnchor = (top != null && bottom != null && top.isConnected() && top.getTarget() == bottom.getTarget());
boolean drawMarginToTheBottom = y0 > y1;
if (centerConnectionAnchor) {
if (top.getTarget().getType() == ConstraintAnchor.Type.TOP) {
drawMarginToTheBottom = true;
} else {
drawMarginToTheBottom = false;
}
}
if (drawMarginToTheBottom) {
marginPosition = y0 + marginLineOffset;
} else {
marginPosition = y0 - marginLineOffset;
}
Stroke pres = g.getStroke();
g.setStroke(sSimpleStroke);
ConnectionDraw.drawHorizontalMarginIndicator(g, String.valueOf(mAnchor.getMargin()), x0, x1, marginPosition);
g.setStroke(ConnectionDraw.sDashedStroke);
if (y0 > y1) {
g.drawLine(x1, y0 + marginLineOffset, x1, y1);
} else {
g.drawLine(x1, y0 - marginLineOffset, x1, y1);
}
g.setColor(pre);
g.setStroke(pres);
}
}
}
use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.
the class SnapPlacement method checkVerticalParentMarginSnap.
/**
* Check to snap on the vertical internal margins of a parent (used when resizing)
*
* @param anchor the anchor we are trying to snap
* @param type the type of anchor on the parent that we want to check against
* @param margin the margin we'll use for the internal margin
* @param candidate the current candidate that we can fill in
*/
private static void checkVerticalParentMarginSnap(ConstraintAnchor anchor, ConstraintAnchor.Type type, int margin, SnapCandidate candidate) {
ConstraintWidget widget = anchor.getOwner();
if (widget.getParent() == null) {
return;
}
ConstraintAnchor targetParent = widget.getParent().getAnchor(type);
ConstraintHandle targetParentHandle = WidgetInteractionTargets.constraintHandle(targetParent);
ConstraintHandle anchorHandle = WidgetInteractionTargets.constraintHandle(anchor);
ConstraintAnchor target = new ConstraintAnchor(widget.getParent(), type);
int tx = targetParentHandle.getDrawX();
int ty = targetParentHandle.getDrawY() + margin;
int distance = Math.abs(anchorHandle.getDrawY() - ty);
if (distance <= CONNECTION_SLOPE) {
candidate.distance = distance;
candidate.target = target;
candidate.source = anchor;
candidate.x = tx;
candidate.y = ty;
}
}
Aggregations