Search in sources :

Example 1 with ConstraintTableLayout

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

the class TableDecorator method mousePressed.

/**
     * Handle mouse press event to add click targets. TODO: clean this up.
     *
     * @param x         mouse x coordinate
     * @param y         mouse y coordinate
     * @param transform view transform
     * @param selection the current selection of widgets
     */
@Override
public ConstraintWidget mousePressed(float x, float y, ViewTransform transform, Selection selection) {
    ConstraintTableLayout table = (ConstraintTableLayout) mWidget;
    mTableClickTargets.clear();
    ArrayList<Guideline> vertical = table.getVerticalGuidelines();
    int l = transform.getSwingX(table.getDrawX());
    int t = transform.getSwingY(table.getDrawY());
    int column = 0;
    TableClickTarget firstTarget = new TableClickTarget(table, column++, l, t - 20 - 4, 20, 20);
    mTableClickTargets.add(firstTarget);
    for (ConstraintWidget v : vertical) {
        int bx = transform.getSwingX(v.getX()) + l;
        TableClickTarget target = new TableClickTarget(table, column++, bx, t - 20 - 4, 20, 20);
        mTableClickTargets.add(target);
    }
    ConstraintWidget widgetHit = null;
    if (mTableClickTargets.size() > 0) {
        for (TableClickTarget tableClickTarget : mTableClickTargets) {
            if (tableClickTarget.contains(x, y)) {
                widgetHit = tableClickTarget.getTable();
                break;
            }
        }
        if (selection.isEmpty()) {
            mTableClickTargets.clear();
        }
    }
    return widgetHit;
}
Also used : ConstraintWidget(android.support.constraint.solver.widgets.ConstraintWidget) ConstraintTableLayout(android.support.constraint.solver.widgets.ConstraintTableLayout) Guideline(android.support.constraint.solver.widgets.Guideline)

Example 2 with ConstraintTableLayout

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

the class Scout method inferGroup.

/**
     * Given a collection of widgets infer a good group choice
     *
     * @param widgets
     */
public static ConstraintTableLayout inferGroup(ArrayList<ConstraintWidget> widgets) {
    ScoutGroup group = new ScoutGroup(widgets.toArray(new ConstraintWidget[widgets.size()]));
    ConstraintTableLayout ret = new ConstraintTableLayout();
    if (group.mCols * group.mRows >= widgets.size()) {
        ret.setNumRows(group.mRows);
        ret.setNumCols(group.mCols);
    }
    if (group.mSupported) {
        for (int i = 0; i < group.mCols; i++) {
            ret.setColumnAlignment(i, group.mColAlign[i]);
        }
    }
    return ret;
}
Also used : ConstraintWidget(android.support.constraint.solver.widgets.ConstraintWidget) ConstraintTableLayout(android.support.constraint.solver.widgets.ConstraintTableLayout)

Example 3 with ConstraintTableLayout

use of android.support.constraint.solver.widgets.ConstraintTableLayout 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);
}
Also used : ConstraintAnchor(android.support.constraint.solver.widgets.ConstraintAnchor) ConstraintWidgetContainer(android.support.constraint.solver.widgets.ConstraintWidgetContainer) ConstraintTableLayout(android.support.constraint.solver.widgets.ConstraintTableLayout) Guideline(android.support.constraint.solver.widgets.Guideline)

Example 4 with ConstraintTableLayout

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

the class TableDecorator method onPaint.

/**
     * Override the default paint method to draw the table controls when selected
     *
     * @param transform the view transform
     * @param g         the graphics context
     * @return          true if we need to be called again (i.e. if we are animating)
     */
@Override
public boolean onPaint(ViewTransform transform, Graphics2D g) {
    boolean needsRepaint = super.onPaint(transform, g);
    if (isSelected()) {
        ConstraintTableLayout table = (ConstraintTableLayout) mWidget;
        WidgetDraw.drawTableControls(transform, g, table);
    }
    return needsRepaint;
}
Also used : ConstraintTableLayout(android.support.constraint.solver.widgets.ConstraintTableLayout)

Example 5 with ConstraintTableLayout

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

the class TableDecorator method mouseRelease.

/**
     * Handle mouse release event to check for our table click targets
     *
     * @param x         mouse x coordinate
     * @param y         mouse y coordinate
     * @param transform view transform
     * @param selection the current selection of widgets
     */
@Override
public void mouseRelease(int x, int y, ViewTransform transform, Selection selection) {
    for (TableClickTarget target : mTableClickTargets) {
        if (target.contains(x, y)) {
            ConstraintTableLayout table = target.getTable();
            int column = target.getColumn();
            table.cycleColumnAlignment(column);
        }
    }
}
Also used : ConstraintTableLayout(android.support.constraint.solver.widgets.ConstraintTableLayout)

Aggregations

ConstraintTableLayout (android.support.constraint.solver.widgets.ConstraintTableLayout)5 ConstraintWidget (android.support.constraint.solver.widgets.ConstraintWidget)2 Guideline (android.support.constraint.solver.widgets.Guideline)2 ConstraintAnchor (android.support.constraint.solver.widgets.ConstraintAnchor)1 ConstraintWidgetContainer (android.support.constraint.solver.widgets.ConstraintWidgetContainer)1