Search in sources :

Example 1 with LayeredLayoutConstraint

use of com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint in project CodenameOne by codenameone.

the class LayeredLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    int numOfcomponents = parent.getComponentCount();
    tmpLaidOut.clear();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        calcPreferredValues(cmp);
        LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
        int vInsets = 0;
        int hInsets = 0;
        if (constraint != null) {
            vInsets += constraint.insets[Component.TOP].preferredValue + constraint.insets[Component.BOTTOM].preferredValue;
            hInsets += constraint.insets[Component.LEFT].preferredValue + constraint.insets[Component.RIGHT].preferredValue;
        }
        maxHeight = Math.max(maxHeight, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom() + vInsets);
        maxWidth = Math.max(maxWidth, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL() + hInsets);
    }
    Style s = parent.getStyle();
    Dimension d = new Dimension(maxWidth + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), maxHeight + s.getPaddingTop() + s.getPaddingBottom());
    if (preferredWidthMM > 0) {
        int minW = Display.getInstance().convertToPixels(preferredWidthMM);
        if (d.getWidth() < minW) {
            d.setWidth(minW);
        }
    }
    if (preferredHeightMM > 0) {
        int minH = Display.getInstance().convertToPixels(preferredHeightMM);
        if (d.getHeight() < Display.getInstance().convertToPixels(preferredHeightMM)) {
            d.setHeight(minH);
        }
    }
    return d;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 2 with LayeredLayoutConstraint

use of com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint in project CodenameOne by codenameone.

the class LayeredLayout method layoutComponent.

/**
 * Lays out the specific component within the container.  This will first lay out any components that it depends on.
 * @param parent The parent container being laid out.
 * @param cmp The component being laid out.
 * @param top
 * @param left
 * @param bottom
 * @param right
 */
private void layoutComponent(Container parent, Component cmp, int top, int left, int bottom, int right) {
    if (tmpLaidOut.contains(cmp)) {
        return;
    }
    tmpLaidOut.add(cmp);
    LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
    if (constraint != null) {
        constraint.fixDependencies(parent);
        for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
            if (inset.referenceComponent != null && inset.referenceComponent.getParent() == parent) {
                layoutComponent(parent, inset.referenceComponent, top, left, bottom, right);
            }
        }
    }
    Style s = cmp.getStyle();
    if (constraint != null) {
        // int innerTop = top;
        // int innerBottom = bottom;
        // left = 0;
        // right = parent.getLayoutWidth();
        int leftInset = constraint.insets[Component.LEFT].calculate(cmp, top, left, bottom, right);
        int rightInset = constraint.insets[Component.RIGHT].calculate(cmp, top, left, bottom, right);
        int topInset = constraint.insets[Component.TOP].calculate(cmp, top, left, bottom, right);
        int bottomInset = constraint.insets[Component.BOTTOM].calculate(cmp, top, left, bottom, right);
        cmp.setX(left + leftInset + s.getMarginLeft(parent.isRTL()));
        cmp.setY(top + topInset + s.getMarginTop());
        cmp.setWidth(Math.max(0, right - cmp.getX() - s.getMarginRight(parent.isRTL()) - rightInset));
        // cmp.setWidth(Math.max(0, right - left - s.getHorizontalMargins() - rightInset - leftInset));
        // cmp.setHeight(Math.max(0, bottom - top - s.getVerticalMargins() - bottomInset - topInset));
        cmp.setHeight(Math.max(0, bottom - cmp.getY() - s.getMarginBottom() - bottomInset));
    } else {
        int x = left + s.getMarginLeft(parent.isRTL());
        int y = top + s.getMarginTop();
        int w = right - left - s.getHorizontalMargins();
        int h = bottom - top - s.getVerticalMargins();
        cmp.setX(x);
        cmp.setY(y);
        cmp.setWidth(Math.max(0, w));
        cmp.setHeight(Math.max(0, h));
    // System.out.println("Component laid out "+cmp);
    }
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset) Style(com.codename1.ui.plaf.Style)

Example 3 with LayeredLayoutConstraint

use of com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint in project CodenameOne by codenameone.

the class SplitPane method initDividerInset.

private LayeredLayoutConstraint initDividerInset(LayeredLayoutConstraint cnst, String insetVal) {
    getFixedInset(cnst).setValueAsString(insetVal);
    getAutoInset(cnst).setValueAsString("auto");
    for (Inset i : getZeroInsets(cnst)) {
        i.setValueAsString("0");
    }
    return cnst;
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)

Example 4 with LayeredLayoutConstraint

use of com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint in project CodenameOne by codenameone.

the class LayeredLayout method calcPreferredValues.

private void calcPreferredValues(Component cmp) {
    if (tmpLaidOut.contains(cmp)) {
        return;
    }
    tmpLaidOut.add(cmp);
    LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
    if (constraint != null) {
        constraint.fixDependencies(cmp.getParent());
        for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
            if (inset.referenceComponent != null && inset.referenceComponent.getParent() == cmp.getParent()) {
                calcPreferredValues(inset.referenceComponent);
            }
            inset.calcPreferredValue(cmp.getParent(), cmp);
        }
    }
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)

Aggregations

Inset (com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset)3 Style (com.codename1.ui.plaf.Style)2 Component (com.codename1.ui.Component)1 Dimension (com.codename1.ui.geom.Dimension)1