use of com.codename1.charts.compat.Paint.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++;
}
}
use of com.codename1.charts.compat.Paint.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++;
}
}
}
}
use of com.codename1.charts.compat.Paint.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");
}
use of com.codename1.charts.compat.Paint.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;
}
}
}
use of com.codename1.charts.compat.Paint.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;
}
Aggregations