Search in sources :

Example 91 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class GridLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container parent) {
    Style s = parent.getStyle();
    int width = parent.getLayoutWidth() - parent.getSideGap() - s.getHorizontalPadding();
    int height = parent.getLayoutHeight() - parent.getBottomGap() - s.getVerticalPadding();
    int numOfcomponents = parent.getComponentCount();
    boolean landscapeMode = isLandscapeMode();
    autoSizeCols(parent, width, landscapeMode);
    int rows, columns;
    if (landscapeMode) {
        rows = landscapeRows;
        columns = landscapeColumns;
    } else {
        rows = portraitRows;
        columns = portraitColumns;
    }
    int x = s.getPaddingLeft(parent.isRTL());
    int y = s.getPaddingTop();
    boolean rtl = parent.isRTL();
    if (rtl) {
        x += parent.getSideGap();
    }
    int localColumns = columns;
    int cmpWidth = width / columns;
    int cmpHeight;
    if (numOfcomponents > rows * columns) {
        // actual rows number
        cmpHeight = height / (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
    } else {
        cmpHeight = height / rows;
    }
    int row = 0;
    int offset = 0;
    for (int iter = 0; iter < numOfcomponents; iter++) {
        Component cmp = parent.getComponentAt(iter);
        Style cmpStyle = cmp.getStyle();
        int marginLeft = cmpStyle.getMarginLeft(parent.isRTL());
        int marginTop = cmpStyle.getMarginTop();
        if (hideZeroSized) {
            if (cmp.isHidden()) {
                continue;
            }
        }
        cmp.setWidth(cmpWidth - marginLeft - cmpStyle.getMarginRight(parent.isRTL()));
        cmp.setHeight(cmpHeight - marginTop - cmpStyle.getMarginBottom());
        if (rtl) {
            cmp.setX(x + (localColumns - 1 - (offset % localColumns)) * cmpWidth + marginLeft);
        } else {
            cmp.setX(x + (offset % localColumns) * cmpWidth + marginLeft);
        }
        cmp.setY(y + row * cmpHeight + marginTop);
        if ((offset + 1) % columns == 0) {
            row++;
            // check if we need to recalculate component widths
            if (fillLastRow && row == rows - 1) {
                localColumns = numOfcomponents % columns;
                if (localColumns == 0) {
                    localColumns = columns;
                }
                cmpWidth = width / localColumns;
            }
        }
        offset++;
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 92 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class GridLayout method autoSizeCols.

private void autoSizeCols(Container parent, int width, boolean landscapeMode) {
    if (isAutoFit()) {
        int numOfcomponents = parent.getComponentCount();
        int maxWidth = 0;
        for (int iter = 0; iter < numOfcomponents; iter++) {
            Component cmp = parent.getComponentAt(iter);
            Style s = cmp.getStyle();
            maxWidth = Math.max(cmp.getPreferredW() + s.getHorizontalMargins(), maxWidth);
        }
        if (width < maxWidth) {
            width = Display.getInstance().getDisplayWidth();
        }
        if (landscapeMode) {
            // prevent arithmentic exception
            if (maxWidth <= 0) {
                landscapeColumns = 1;
            } else {
                landscapeColumns = Math.max(width / maxWidth, 1);
            }
            landscapeRows = Math.max(1, numOfcomponents / landscapeColumns);
            if (numOfcomponents % landscapeColumns > 0 && numOfcomponents > landscapeColumns) {
                landscapeRows++;
            }
        } else {
            // prevent arithmentic exception
            if (maxWidth <= 0) {
                portraitColumns = 1;
            } else {
                portraitColumns = Math.max(width / maxWidth, 1);
            }
            portraitRows = Math.max(1, numOfcomponents / portraitColumns);
            if (numOfcomponents % portraitColumns > 0 && numOfcomponents > portraitColumns) {
                portraitRows++;
            }
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 93 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class TimeSpinner method addComponents.

void addComponents() {
    setLayout(new LayeredLayout());
    LayeredLayout ll = (LayeredLayout) getLayout();
    Container content = new Container(BoxLayout.x());
    Style allStyles = content.getAllStyles();
    allStyles.setMargin(0, 0, 0, 0);
    allStyles.setPadding(0, 0, 0, 0);
    allStyles.setBgTransparency(0);
    allStyles.setBorder(Border.createEmpty());
    if (amPM != null) {
        content.addComponent(hour);
        hourComponents.add(hour);
        if (durationMode) {
            Label l = new Label(getUIManager().localize("hours", "hours"));
            l.setUIID("TimeSpinnerHoursLabel");
            hourComponents.add(l);
            content.addComponent(l);
        }
        content.addComponent(createSeparator());
        content.addComponent(minute);
        minuteComponents.add(minute);
        if (durationMode) {
            Label l = new Label(getUIManager().localize("minutes", "minutes"));
            l.setUIID("TimeSpinnerMinutesLabel");
            minuteComponents.add(l);
            content.addComponent(l);
        }
        if (showMeridiem) {
            content.addComponent(createSeparator());
            content.addComponent(amPM);
        }
    }
    setHoursVisible(showHours);
    setMinutesVisible(showMinutes);
    addComponent(content);
    ll.setInsets(content, "0 auto 0 auto");
}
Also used : Container(com.codename1.ui.Container) Label(com.codename1.ui.Label) Style(com.codename1.ui.plaf.Style) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 94 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class BoxLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container parent) {
    Style ps = parent.getStyle();
    int width = parent.getLayoutWidth() - parent.getSideGap() - ps.getHorizontalPadding();
    int height = parent.getLayoutHeight() - parent.getBottomGap() - ps.getVerticalPadding();
    int x = ps.getPaddingLeft(parent.isRTL());
    int y = ps.getPaddingTop();
    int numOfcomponents = parent.getComponentCount();
    boolean rtl = parent.isRTL();
    if (rtl) {
        x += parent.getSideGap();
    }
    int initX = x;
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        Style stl = cmp.getStyle();
        switch(axis) {
            case Y_AXIS:
                int cmpBottom = height;
                cmp.setWidth(width - stl.getHorizontalMargins());
                int cmpH = cmp.getPreferredH();
                y += stl.getMarginTop();
                if (y - ps.getPaddingTop() >= cmpBottom && !parent.isScrollableY()) {
                    cmpH = 0;
                } else if (y + cmpH - ps.getPaddingTop() > cmpBottom) {
                    if (!parent.isScrollableY()) {
                        cmpH = cmpBottom - y - stl.getMarginBottom();
                    }
                }
                cmp.setHeight(cmpH);
                cmp.setX(x + stl.getMarginLeft(parent.isRTL()));
                cmp.setY(y);
                y += cmp.getHeight() + stl.getMarginBottom();
                break;
            case X_AXIS_NO_GROW:
                {
                    int cmpRight = width;
                    height = Math.min(getPreferredSize(parent).getHeight(), height);
                    int cmpW = cmp.getPreferredW();
                    x += stl.getMarginLeftNoRTL();
                    if (x >= cmpRight && !parent.isScrollableX()) {
                        cmpW = 0;
                    } else {
                        if (x + cmpW - ps.getPaddingLeftNoRTL() > cmpRight) {
                            cmpW = cmpRight - x - stl.getMarginRightNoRTL();
                        }
                    }
                    cmp.setWidth(cmpW);
                    cmp.setHeight(height - stl.getMarginTop() - stl.getMarginBottom());
                    if (rtl) {
                        cmp.setX(width + initX - (x - initX) - cmpW);
                    } else {
                        cmp.setX(x);
                    }
                    cmp.setY(y + stl.getMarginTop());
                    x += cmp.getWidth() + stl.getMarginRightNoRTL();
                    break;
                }
            default:
                int cmpRight = width;
                int cmpW = cmp.getPreferredW();
                x += stl.getMarginLeftNoRTL();
                if (x >= cmpRight && !parent.isScrollableX()) {
                    cmpW = 0;
                } else {
                    if (x + cmpW - ps.getPaddingLeftNoRTL() > cmpRight) {
                        cmpW = cmpRight - x - stl.getMarginRightNoRTL();
                    }
                }
                cmp.setWidth(cmpW);
                cmp.setHeight(height - stl.getVerticalMargins());
                if (rtl) {
                    cmp.setX(width + initX - (x - initX) - cmpW);
                } else {
                    cmp.setX(x);
                }
                cmp.setY(y + stl.getMarginTop());
                x += cmp.getWidth() + stl.getMarginRightNoRTL();
                break;
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 95 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class BoxLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int width = 0;
    int height = 0;
    int numOfcomponents = parent.getComponentCount();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        Style stl = cmp.getStyle();
        if (axis == Y_AXIS) {
            int cmpH = cmp.getPreferredH() + stl.getVerticalMargins();
            height += cmpH;
            width = Math.max(width, cmp.getPreferredW() + stl.getHorizontalMargins());
        } else {
            int cmpW = cmp.getPreferredW() + stl.getHorizontalMargins();
            width += cmpW;
            height = Math.max(height, cmp.getPreferredH() + stl.getVerticalMargins());
        }
    }
    Style s = parent.getStyle();
    dim.setWidth(width + s.getHorizontalPadding());
    dim.setHeight(height + s.getVerticalPadding());
    return dim;
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3