private static int getTotalSizeSerial(ArrayList<CompWrap> compWraps, int sType, boolean isHor) { int totSize = 0; for (int i = 0, iSz = compWraps.size(), lastGapAfter = 0; i < iSz; i++) { CompWrap wrap = compWraps.get(i); int gapBef = wrap.getGapBefore(sType, isHor); if (gapBef > lastGapAfter) totSize += gapBef - lastGapAfter; totSize += wrap.getSize(sType, isHor); totSize += (lastGapAfter = wrap.getGapAfter(sType, isHor)); if (totSize >= LayoutUtil.INF) return LayoutUtil.INF; } return constrainSize(totSize); }
/** The maximum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC maxWidth(String size) { hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true))); return this; }
/** Sets the vertical dimension constraint for this component constraint. It has constraints for the vertical size * and grow/shrink priorities and weights. * @param v The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code> */ public void setVertical(DimConstraint v) { ver = v != null ? v : new DimConstraint(); }
int gp = dc.getGrowPriority(); if (gp != 100) { if (asAPI) { Float gw = dc.getGrow(); if (gw != null) { String g = gw != 100f ? floatToString(gw, asAPI) : ""; int sp = dc.getShrinkPriority(); if (sp != 100) { if (asAPI) { Float sw = dc.getShrink(); if (sw != null && sw.intValue() != 100) { String s = floatToString(sw, asAPI); String eg = dc.getEndGroup(); if (eg != null) { if (asAPI) { String sg = dc.getSizeGroup(); if (sg != null) { if (asAPI) { appendBoundSize(dc.getSize(), sb, isHor, asAPI); UnitValue al = dc.getAlign(); if (al != null) { if (asAPI) {
int gp = dc.getGrowPriority(); BoundSize size = dc.getSize(); if (size.isUnset() == false) { if (asAPI) { Float gw = dc.getGrow(); if (gw != null) { String g = gw != 100f ? floatToString(gw, asAPI) : ""; int sp = dc.getShrinkPriority(); if (sp != 100) { if (asAPI) { Float sw = dc.getShrink(); if (sw != null && sw.intValue() != 100) { String s = floatToString(sw, asAPI); String eg = dc.getEndGroup(); if (eg != null) { if (asAPI) { String sg = dc.getSizeGroup(); if (sg != null) { if (asAPI) { UnitValue al = dc.getAlign(); if (al != null) { if (asAPI) {
DimConstraint dimConstraint = new DimConstraint(); dimConstraint.setGapBefore(gapBefore); dimConstraint.setGapAfter(gapAfter); dimConstraint.setFill(true); dimConstraint.setNoGrid(true); continue; ix = startsWithLenient(part, new String[] {"sizegroup", "sg"}, new int[] {5, 2}, true); if (ix > -1) { dimConstraint.setSizeGroup(part.substring(ix).trim()); continue; dimConstraint.setShrinkPriority(Integer.parseInt(part.substring(ix).trim())); continue; dimConstraint.setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); continue; ix = startsWithLenient(part, new String[] {"growpriority", "gp"}, new int[] {5, 2}, true); if (ix > -1) { dimConstraint.setGrowPriority(Integer.parseInt(part.substring(ix).trim())); continue; dimConstraint.setGrow(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); continue;
cc.getHorizontal().setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); continue; cc.getVertical().setShrink(parseFloat(part.substring(ix).trim(), ResizeConstraint.WEIGHT_100)); continue; if (ix > -1) { String[] shrinks = toTrimmedTokens(part.substring(ix).trim(), ' '); cc.getHorizontal().setShrink(parseFloat(shrinks[0], ResizeConstraint.WEIGHT_100)); if (shrinks.length > 1) cc.getVertical().setShrink(parseFloat(shrinks[1], ResizeConstraint.WEIGHT_100)); continue; String sp = part.substring(ix).trim(); if (sp.startsWith("x") || sp.startsWith("y")) { // To handle "gpx", "gpy", "shrinkpriorityx", shrinkpriorityy" (sp.startsWith("x") ? cc.getHorizontal() : cc.getVertical()).setShrinkPriority(Integer.parseInt(sp.substring(2))); } else { String[] shrinks = toTrimmedTokens(sp, ' '); cc.getHorizontal().setShrinkPriority(Integer.parseInt(shrinks[0])); if (shrinks.length > 1) cc.getVertical().setShrinkPriority(Integer.parseInt(shrinks[1])); char lc = part.charAt(ix - 1); if (lc != 'y') cc.getHorizontal().setSizeGroup(sg); if (lc != 'x') cc.getVertical().setSizeGroup(sg); continue;
BoundSize dimSize = allDCs[r].getSize(); addToSizeGroup(sizeGroupMap, allDCs[r].getSizeGroup(), rowColSizes); if (allDCs[r].getSizeGroup() != null) rowColBoundSizes[r] = sizeGroupMap.get(allDCs[r].getSizeGroup());
if (rootCc.getHorizontal().getSizeGroup() != null) sizeGroupsX++; if (rootCc.getVertical().getSizeGroup() != null) sizeGroupsY++; final boolean isRowInGridMode = !lc.isNoGrid() && !((DimConstraint) LayoutUtil.getIndexSafe(specs, lc.isFlowX() ? cellXY[1] : cellXY[0])).isNoGrid(); if (cc.getHorizontal().getSizeGroup() != null) sizeGroupsX++; if (cc.getVertical().getSizeGroup() != null) sizeGroupsY++; for (int i = 0; i < cell.compWraps.size(); i++) { CompWrap cw = cell.compWraps.get(i); String sgx = cw.cc.getHorizontal().getSizeGroup(); String sgy = cw.cc.getVertical().getSizeGroup(); cw.setForcedSizes(sizeGroupMapX.get(cw.cc.getHorizontal().getSizeGroup()), true); // Target method handles null sizes if (sizeGroupMapY != null) cw.setForcedSizes(sizeGroupMapY.get(cw.cc.getVertical().getSizeGroup()), false); // Target method handles null sizes
private static void layoutParallel(ContainerWrapper parent, ArrayList<CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, boolean fromEnd) { int[][] sizes = new int[compWraps.size()][]; // [compIx][gapBef,compSize,gapAft] for (int i = 0; i < sizes.length; i++) { CompWrap cw = compWraps.get(i); DimConstraint cDc = cw.cc.getDimConstraint(isHor); ResizeConstraint[] resConstr = new ResizeConstraint[] { cw.isPushGap(isHor, true) ? GAP_RC_CONST_PUSH : GAP_RC_CONST, cDc.resize, cw.isPushGap(isHor, false) ? GAP_RC_CONST_PUSH : GAP_RC_CONST, }; int[][] sz = new int[][] { cw.getGaps(isHor, true), cw.getSizes(isHor), cw.getGaps(isHor, false) }; Float[] pushW = dc.isFill() ? GROW_100 : null; sizes[i] = LayoutUtil.calculateSerial(sz, resConstr, pushW, LayoutUtil.PREF, size); } UnitValue rowAlign = dc.getAlignOrDefault(isHor); setCompWrapBounds(parent, sizes, compWraps, rowAlign, start, size, isHor, fromEnd); }
private static void layoutBaseline(ContainerWrapper parent, ArrayList<CompWrap> compWraps, DimConstraint dc, int start, int size, int sizeType, int spanCount) { AboveBelow aboveBelow = getBaselineAboveBelow(compWraps, sizeType, true); int blRowSize = aboveBelow.sum(); CC cc = compWraps.get(0).cc; // Align for the whole baseline component array UnitValue align = cc.getVertical().getAlign(); if (spanCount == 1 && align == null) align = dc.getAlignOrDefault(false); if (align == UnitValue.BASELINE_IDENTITY) align = UnitValue.CENTER; int offset = start + aboveBelow.maxAbove + (align != null ? Math.max(0, align.getPixels(size - blRowSize, parent, null)) : 0); for (CompWrap cw : compWraps) { cw.y += offset; if (cw.y + cw.h > start + size) cw.h = start + size - cw.y; } }
private static UnitValue correctAlign(CC cc, UnitValue rowAlign, boolean isHor, boolean fromEnd) { UnitValue align = (isHor ? cc.getHorizontal() : cc.getVertical()).getAlign(); if (align == null) align = rowAlign; if (align == UnitValue.BASELINE_IDENTITY) align = UnitValue.CENTER; if (fromEnd) { if (align == UnitValue.LEFT) align = UnitValue.RIGHT; else if (align == UnitValue.RIGHT) align = UnitValue.LEFT; } return align; }
doAgain |= doAbsoluteCorrections(cw, bounds); if (!doAgain) { // If we are going to do this again, do not bother this time around if (cw.cc.getHorizontal().getEndGroup() != null) endGrpXMap = addToEndGroup(endGrpXMap, cw.cc.getHorizontal().getEndGroup(), cw.x + cw.w); if (cw.cc.getVertical().getEndGroup() != null) endGrpYMap = addToEndGroup(endGrpYMap, cw.cc.getVertical().getEndGroup(), cw.y + cw.h); if (cw.cc.getHorizontal().getEndGroup() != null) cw.w = endGrpXMap.get(cw.cc.getHorizontal().getEndGroup()) - cw.x; if (cw.cc.getVertical().getEndGroup() != null) cw.h = endGrpYMap.get(cw.cc.getVertical().getEndGroup()) - cw.y;
for (int cwIx = 0; cwIx < cell.compWraps.size(); cwIx++) { CompWrap cw = cell.compWraps.get(cwIx); boolean rowBaselineAlign = (isRows && lc.isTopToBottom() && dc.getAlignOrDefault(!isRows) == UnitValue.BASELINE_IDENTITY); // Disable baseline for bottomToTop since I can not verify it working. boolean isBaseline = isRows && cw.isBaselineAlign(rowBaselineAlign);
private static void layoutSerial(ContainerWrapper parent, ArrayList<CompWrap> compWraps, DimConstraint dc, int start, int size, boolean isHor, int spanCount, boolean fromEnd) { FlowSizeSpec fss = mergeSizesGapsAndResConstrs( getComponentResizeConstraints(compWraps, isHor), getComponentGapPush(compWraps, isHor), getComponentSizes(compWraps, isHor), getGaps(compWraps, isHor)); Float[] pushW = dc.isFill() ? GROW_100 : null; int[] sizes = LayoutUtil.calculateSerial(fss.sizes, fss.resConstsInclGaps, pushW, LayoutUtil.PREF, size); setCompWrapBounds(parent, sizes, compWraps, dc.getAlignOrDefault(isHor), start, size, isHor, fromEnd); }
private static AboveBelow getBaselineAboveBelow(ArrayList<CompWrap> compWraps, int sType, boolean centerBaseline) { int maxAbove = Integer.MIN_VALUE; int maxBelow = Integer.MIN_VALUE; for (CompWrap cw : compWraps) { int height = cw.getSize(sType, false); if (height >= LayoutUtil.INF) return new AboveBelow(LayoutUtil.INF / 2, LayoutUtil.INF / 2); int baseline = cw.getBaseline(sType); int above = baseline + cw.getGapBefore(sType, false); maxAbove = Math.max(above, maxAbove); maxBelow = Math.max(height - baseline + cw.getGapAfter(sType, false), maxBelow); if (centerBaseline) cw.setDimBounds(-baseline, height, false); } return new AboveBelow(maxAbove, maxBelow); }
/** The minimum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC minHeight(String size) { ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null)); return this; }
/** Sets the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size * and grow/shrink priorities and weights. * @param h The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code> */ public void setHorizontal(DimConstraint h) { hor = h != null ? h : new DimConstraint(); }
BoundSize gap = dc.getGapAfter(); gap = dims[i + 1].getGapBefore();
/** The minimum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC minWidth(String size) { hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null)); return this; }