Search in sources :

Example 26 with ConstraintAnchor

use of android.support.constraint.solver.widgets.ConstraintAnchor in project android by JetBrains.

the class ScoutWidget method setEdgeCentered.

/**
     * set a centered constraint if possible return true if it did
     *
     * @param dir   direction 0 = vertical
     * @param to1   first widget  to connect to
     * @param cDir1 the side of first widget to connect to
     * @return true if it was able to connect
     */
boolean setEdgeCentered(int dir, ScoutWidget to1, Direction cDir1) {
    Direction ori = (dir == 0) ? Direction.NORTH : Direction.WEST;
    ConstraintAnchor anchor1 = mConstraintWidget.getAnchor(lookupType(ori));
    ConstraintAnchor anchor2 = mConstraintWidget.getAnchor(lookupType(ori.getOpposite()));
    if (mKeepExistingConnections && (anchor1.isConnected() || anchor2.isConnected())) {
        if (anchor1.isConnected() ^ anchor2.isConnected()) {
            return false;
        }
        if (anchor1.isConnected() && (anchor1.getTarget().getOwner() != to1.mConstraintWidget)) {
            return false;
        }
    }
    if (anchor1.isConnectionAllowed(to1.mConstraintWidget)) {
        connect(mConstraintWidget, lookupType(ori), to1.mConstraintWidget, lookupType(cDir1), 0);
        connect(mConstraintWidget, lookupType(ori.getOpposite()), to1.mConstraintWidget, lookupType(cDir1), 0);
    }
    return true;
}
Also used : ConstraintAnchor(android.support.constraint.solver.widgets.ConstraintAnchor)

Aggregations

ConstraintAnchor (android.support.constraint.solver.widgets.ConstraintAnchor)26 ConstraintWidget (android.support.constraint.solver.widgets.ConstraintWidget)10 Guideline (android.support.constraint.solver.widgets.Guideline)8 Point (java.awt.Point)7 ConstraintHandle (com.android.tools.sherpa.interaction.ConstraintHandle)4 ConstraintWidgetContainer (android.support.constraint.solver.widgets.ConstraintWidgetContainer)3 WidgetCompanion (com.android.tools.sherpa.structure.WidgetCompanion)3 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 ConstraintTableLayout (android.support.constraint.solver.widgets.ConstraintTableLayout)1 WidgetDecorator (com.android.tools.sherpa.drawing.decorator.WidgetDecorator)1 WidgetInteractionTargets (com.android.tools.sherpa.interaction.WidgetInteractionTargets)1