Search in sources :

Example 1 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class Border method getMinimumWidth.

/**
 * Returns the minimum size required to properly display this border, normally this
 * is 0 but a border might deem itself undisplayable with too small a size e.g. for
 * the case of an image border the minimum height would be top + bottom and the minimum
 * width would be left+right
 *
 * @return 0 if not applicable or a dimension if it is.
 */
public int getMinimumWidth() {
    if (images != null) {
        if (images.length < 4) {
            if (type == TYPE_IMAGE_HORIZONTAL) {
                return images[0].getWidth() + images[1].getWidth();
            } else {
                return images[0].getWidth();
            }
        }
        Image topLeft = images[4];
        Image topRight = images[5];
        return topLeft.getWidth() + topRight.getWidth();
    }
    return 0;
}
Also used : RGBImage(com.codename1.ui.RGBImage) Image(com.codename1.ui.Image)

Example 2 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class Border method getMinimumHeight.

/**
 * Returns the minimum size required to properly display this border, normally this
 * is 0 but a border might deem itself undisplayable with too small a size e.g. for
 * the case of an image border the minimum height would be top + bottom and the minimum
 * width would be left+right
 *
 * @return 0 if not applicable or a dimension if it is.
 */
public int getMinimumHeight() {
    if (images != null) {
        if (images.length < 4) {
            if (type == TYPE_IMAGE_HORIZONTAL) {
                return images[0].getHeight();
            } else {
                return images[0].getHeight() + images[1].getHeight();
            }
        }
        Image topLeft = images[4];
        Image bottomRight = images[7];
        return topLeft.getHeight() + bottomRight.getHeight();
    }
    return 0;
}
Also used : RGBImage(com.codename1.ui.RGBImage) Image(com.codename1.ui.Image)

Example 3 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getTextAreaSize.

/**
 * {@inheritDoc}
 */
public Dimension getTextAreaSize(TextArea ta, boolean pref) {
    int prefW = 0;
    int prefH = 0;
    Style style = ta.getStyle();
    Font f = style.getFont();
    // if this is a text field the preferred size should be the text width
    if (ta.getRows() == 1) {
        prefW = f.stringWidth(ta.getText());
    } else {
        prefW = f.charWidth(TextArea.getWidestChar()) * ta.getColumns();
    }
    int rows;
    if (pref) {
        rows = ta.getActualRows();
    } else {
        rows = ta.getLines();
    }
    prefH = (f.getHeight() + ta.getRowsGap()) * rows;
    if (!ta.isActAsLabel()) {
        int columns = ta.getColumns();
        String str = "";
        for (int iter = 0; iter < columns; iter++) {
            str += TextArea.getWidestChar();
        }
        if (columns > 0) {
            prefW = Math.max(prefW, f.stringWidth(str));
        }
    }
    prefH = Math.max(prefH, rows * f.getHeight());
    prefW += style.getPaddingRightNoRTL() + style.getPaddingLeftNoRTL();
    prefH += style.getPaddingTop() + style.getPaddingBottom();
    if (style.getBorder() != null) {
        prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
        prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
    }
    if (isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        prefW = Math.max(style.getBgImage().getWidth(), prefW);
        prefH = Math.max(style.getBgImage().getHeight(), prefH);
    }
    return new Dimension(prefW, prefH);
}
Also used : Dimension(com.codename1.ui.geom.Dimension) Font(com.codename1.ui.Font)

Example 4 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getListPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getListPreferredSize(List l) {
    Dimension d = getListPreferredSizeImpl(l);
    Style style = l.getStyle();
    if (style.getBorder() != null) {
        d.setWidth(Math.max(style.getBorder().getMinimumWidth(), d.getWidth()));
        d.setHeight(Math.max(style.getBorder().getMinimumHeight(), d.getHeight()));
    }
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 5 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class DefaultLookAndFeel method getRadioButtonPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getRadioButtonPreferredSize(Button rb) {
    if (rb.isToggle()) {
        return getButtonPreferredSize(rb);
    }
    threeImageCache[0] = rb.getMaskedIcon();
    threeImageCache[1] = rb.getRolloverIcon();
    threeImageCache[2] = rb.getPressedIcon();
    if (rButtonImages != null) {
        return getPreferredSize(rb, threeImageCache, rButtonImages[0]);
    }
    Dimension d = getPreferredSize(rb, threeImageCache, null);
    // radio button radius needs to be of the size of the font height even
    // when no text is in the radio button this is a good indication of phone DPI
    int height = rb.getStyle().getFont().getHeight();
    // allow for radio buttons without a string within them
    d.setHeight(Math.max(height, d.getHeight()));
    if (rButtonImages != null && rButtonImages.length > 0) {
        d.setWidth(rButtonImages[0].getWidth() + d.getWidth() + rb.getGap());
    } else {
        d.setWidth(d.getWidth() + height + rb.getGap());
    }
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)74 Style (com.codename1.ui.plaf.Style)27 Component (com.codename1.ui.Component)16 Image (com.codename1.ui.Image)16 Rectangle (com.codename1.ui.geom.Rectangle)9 EncodedImage (com.codename1.ui.EncodedImage)8 Label (com.codename1.ui.Label)7 Container (com.codename1.ui.Container)6 FileEncodedImage (com.codename1.components.FileEncodedImage)5 StorageImage (com.codename1.components.StorageImage)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Form (com.codename1.ui.Form)4 Dimension (java.awt.Dimension)4 Font (com.codename1.ui.Font)3 FontImage (com.codename1.ui.FontImage)3 TextArea (com.codename1.ui.TextArea)3 ActionListener (com.codename1.ui.events.ActionListener)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Border (com.codename1.ui.plaf.Border)3