Search in sources :

Example 71 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ScaleImageLabel method calcPreferredSize.

/**
 * {@inheritDoc}
 */
@Override
protected Dimension calcPreferredSize() {
    Image i = getIcon();
    if (i == null) {
        return new Dimension();
    }
    int dw = Display.getInstance().getDisplayWidth();
    int iw = i.getWidth();
    int ih = i.getHeight();
    // a scrollable container the vertical height might be granted providing so much space as to make this unrealistic...
    if (iw > dw) {
        float ratio = ((float) iw) / ((float) dw);
        iw = (int) (((float) iw) / ((float) ratio));
        ih = (int) (((float) ih) / ((float) ratio));
    }
    Style s = getStyle();
    return new Dimension(iw + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), ih + s.getPaddingTop() + s.getPaddingBottom());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image)

Example 72 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class FloatingActionButton method styleChanged.

/**
 * We override this method to track style changes to the background color and map them to the border
 *
 * {@inheritDoc}
 */
@Override
public void styleChanged(String propertyName, Style source) {
    if (propertyName.equals(Style.BG_COLOR)) {
        updateBorder();
    }
    if (getIcon() instanceof FontImage && propertyName.equals(Style.FG_COLOR)) {
        FontImage i = (FontImage) getIcon();
        FontImage image = FontImage.createMaterial(i.getText().charAt(0), "FloatingActionButton", sizeMm);
        setIcon(image);
    }
}
Also used : FontImage(com.codename1.ui.FontImage)

Example 73 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class FloatingActionButton method setUIID.

/**
 * Overriden to update the icon
 * {@inheritDoc}
 */
@Override
public void setUIID(String id) {
    super.setUIID(id);
    FontImage i = (FontImage) getIcon();
    if (i != null) {
        Style all = getAllStyles();
        all.setAlignment(CENTER);
        updateBorder();
        FontImage image = FontImage.createMaterial(i.getText().charAt(0), id, sizeMm);
        setIcon(image);
    }
}
Also used : Style(com.codename1.ui.plaf.Style) FontImage(com.codename1.ui.FontImage)

Example 74 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ImageViewer method updatePositions.

private void updatePositions() {
    if (zoom == 1) {
        imageAspectCalc(image);
        imageDrawWidth = prefW;
        imageDrawHeight = prefH;
        imageX = prefX;
        imageY = prefY;
        return;
    }
    int iW = image.getWidth();
    int iH = image.getHeight();
    Style s = getStyle();
    int width = getWidth() - s.getHorizontalPadding();
    int height = getHeight() - s.getVerticalPadding();
    float r2;
    if (imageInitialPosition == IMAGE_FIT) {
        r2 = Math.min(((float) width) / ((float) iW), ((float) height) / ((float) iH));
    } else {
        r2 = Math.max(((float) width) / ((float) iW), ((float) height) / ((float) iH));
    }
    imageDrawWidth = (int) (((float) iW) * r2 * zoom);
    imageDrawHeight = (int) (((float) iH) * r2 * zoom);
    imageX = (int) (s.getPaddingLeftNoRTL() + (width - imageDrawWidth) * panPositionX);
    imageY = (int) (s.getPaddingTop() + (height - imageDrawHeight) * panPositionY);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 75 with Style

use of com.codename1.charts.compat.Paint.Style in project CodenameOne by codenameone.

the class ImageViewer method imageAspectCalc.

private void imageAspectCalc(Image img) {
    if (img == null) {
        return;
    }
    int iW = img.getWidth();
    int iH = img.getHeight();
    Style s = getStyle();
    int width = getWidth() - s.getHorizontalPadding();
    int height = getHeight() - s.getVerticalPadding();
    float r2;
    if (imageInitialPosition == IMAGE_FIT) {
        r2 = Math.min(((float) width) / ((float) iW), ((float) height) / ((float) iH));
    } else {
        r2 = Math.max(((float) width) / ((float) iW), ((float) height) / ((float) iH));
    }
    // calculate the image position to fit
    prefW = (int) (((float) iW) * r2);
    prefH = (int) (((float) iH) * r2);
    prefX = s.getPaddingLeftNoRTL() + (width - prefW) / 2;
    prefY = s.getPaddingTop() + (height - prefH) / 2;
}
Also used : Style(com.codename1.ui.plaf.Style)

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