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());
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations