Search in sources :

Example 1 with Constraint

use of com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint in project android by JetBrains.

the class GuidelinePainter method paintCycle.

/**
   * Paints a constraint cycle
   */
private static void paintCycle(GuidelineHandler myState, NlGraphics g, List<Constraint> cycle) {
    assert cycle.size() > 0;
    NlComponent from = cycle.get(0).from.node;
    assert from != null;
    Rectangle fromBounds = new Rectangle(from.x, from.y, from.w, from.h);
    if (myState.myDraggedNodes.contains(from)) {
        fromBounds = myState.myBounds;
    }
    Point fromCenter = center(fromBounds);
    List<Point> points = new ArrayList<Point>();
    points.add(fromCenter);
    for (Constraint constraint : cycle) {
        assert constraint.from.node == from;
        NlComponent to = constraint.to.node;
        assert to != null;
        Point toCenter = new Point(to.x + to.w / 2, to.y + to.h / 2);
        points.add(toCenter);
        // Also go through the dragged node bounds
        boolean isDragged = myState.myDraggedNodes.contains(to);
        if (isDragged) {
            toCenter = center(myState.myBounds);
            points.add(toCenter);
        }
        from = to;
        fromCenter = toCenter;
    }
    points.add(fromCenter);
    points.add(points.get(0));
    g.useStyle(CYCLE);
    for (int i = 1, n = points.size(); i < n; i++) {
        Point a = points.get(i - 1);
        Point b = points.get(i);
        g.drawLine(a.x, a.y, b.x, b.y);
    }
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Constraint(com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint) ArrayList(java.util.ArrayList) Constraint(com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint)

Example 2 with Constraint

use of com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint in project android by JetBrains.

the class GuidelineHandler method addClosest.

protected void addClosest(Segment draggedEdge, List<Segment> edges, List<Match> closest) {
    int at = draggedEdge.at;
    int closestDelta = closest.size() > 0 ? closest.get(0).delta : Integer.MAX_VALUE;
    int closestDistance = Math.abs(closestDelta);
    for (Segment edge : edges) {
        assert draggedEdge.edgeType.isHorizontal() == edge.edgeType.isHorizontal();
        int delta = edge.at - at;
        int distance = Math.abs(delta);
        if (distance > closestDistance) {
            continue;
        }
        if (!isEdgeTypeCompatible(edge.edgeType, draggedEdge.edgeType, delta)) {
            continue;
        }
        boolean withParent = edge.component == layout;
        ConstraintType type = ConstraintType.forMatch(withParent, draggedEdge.edgeType, edge.edgeType);
        if (type == null) {
            continue;
        }
        // constraint can only apply to the non-margin bounds.
        if (type.relativeToMargin && edge.marginType == WITHOUT_MARGIN || !type.relativeToMargin && edge.marginType == WITH_MARGIN) {
            continue;
        }
        Match match = new Match(edge, draggedEdge, type, delta);
        if (distance < closestDistance) {
            closest.clear();
            closestDistance = distance;
            closestDelta = delta;
        } else if (delta * closestDelta < 0) {
            // on opposite sides; can't accept them both
            continue;
        }
        closest.add(match);
    }
}
Also used : Constraint(com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint)

Aggregations

Constraint (com.android.tools.idea.uibuilder.handlers.relative.DependencyGraph.Constraint)2 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 ArrayList (java.util.ArrayList)1