@Test public void testDistributeMainLineSpace() { FlexboxLayout.FlexLine flexLine = new FlexboxLayout.FlexLine(); flexLine.setMinMainSize(100); flexLine.setGrow(2); DefaultFlexItem flexItemImpl = DefaultFlexItem.builder() .width(50).height(50).flexGrow(1).maxWidth(60).build(); flexItemImpl.setMainTargetSize(50); DefaultFlexItem flexItemImpl2 = DefaultFlexItem.builder() .width(50).height(50).flexGrow(1).build(); flexItemImpl2.setMainTargetSize(50); flexLine.addFlexItem(flexItemImpl); flexLine.addFlexItem(flexItemImpl2); FlexboxLayout flexboxLayout = new FlexboxLayout(); flexboxLayout.distributeMainLineSpace(flexLine, true, 200); Assert.assertEquals(140, flexItemImpl2.getMainTargetSize(), 0.01); Assert.assertEquals(60, flexItemImpl.getMainTargetSize(), 0.01); flexboxLayout.clearItems(); }
void distributeMainLineSpace(FlexLine line, boolean horizontal, double mainSize) { List<FlexItem> flexItems = line.flexItems; double freeSpace = mainSize - line.minMainSize; double growUnit = 0; if (freeSpace > 0) { if (line.getGrow() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getGrow(); growUnit = freeSpace / line.getGrow(); while (totalGrow > 0 && growUnit > 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, flexItem.getFlexGrow(), 0f)) { continue; } double grow = flexItem.getFlexGrow() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMaxWidth() : flexItem.getMaxHeight(); if (grownSize > clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexGrow(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } else if (freeSpace < 0) { if (line.getShrink() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getShrink(); growUnit = freeSpace / line.getShrink(); while (totalGrow > 0 && growUnit < 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, totalGrow, 1f)) { continue; } double grow = flexItem.getFlexShrink() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMinWidth() : flexItem.getMinHeight(); if (grownSize < clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexShrink(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } }
FlexboxLayout { void distributeMainLineSpace(FlexLine line, boolean horizontal, double mainSize) { List<FlexItem> flexItems = line.flexItems; double freeSpace = mainSize - line.minMainSize; double growUnit = 0; if (freeSpace > 0) { if (line.getGrow() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getGrow(); growUnit = freeSpace / line.getGrow(); while (totalGrow > 0 && growUnit > 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, flexItem.getFlexGrow(), 0f)) { continue; } double grow = flexItem.getFlexGrow() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMaxWidth() : flexItem.getMaxHeight(); if (grownSize > clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexGrow(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } else if (freeSpace < 0) { if (line.getShrink() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getShrink(); growUnit = freeSpace / line.getShrink(); while (totalGrow > 0 && growUnit < 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, totalGrow, 1f)) { continue; } double grow = flexItem.getFlexShrink() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMinWidth() : flexItem.getMinHeight(); if (grownSize < clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexShrink(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } } }
FlexboxLayout { void distributeMainLineSpace(FlexLine line, boolean horizontal, double mainSize) { List<FlexItem> flexItems = line.flexItems; double freeSpace = mainSize - line.minMainSize; double growUnit = 0; if (freeSpace > 0) { if (line.getGrow() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getGrow(); growUnit = freeSpace / line.getGrow(); while (totalGrow > 0 && growUnit > 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, flexItem.getFlexGrow(), 0f)) { continue; } double grow = flexItem.getFlexGrow() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMaxWidth() : flexItem.getMaxHeight(); if (grownSize > clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexGrow(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } else if (freeSpace < 0) { if (line.getShrink() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getShrink(); growUnit = freeSpace / line.getShrink(); while (totalGrow > 0 && growUnit < 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, totalGrow, 1f)) { continue; } double grow = flexItem.getFlexShrink() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMinWidth() : flexItem.getMinHeight(); if (grownSize < clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexShrink(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } }  }
FlexboxLayout { void distributeMainLineSpace(FlexLine line, boolean horizontal, double mainSize) { List<FlexItem> flexItems = line.flexItems; double freeSpace = mainSize - line.minMainSize; double growUnit = 0; if (freeSpace > 0) { if (line.getGrow() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getGrow(); growUnit = freeSpace / line.getGrow(); while (totalGrow > 0 && growUnit > 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, flexItem.getFlexGrow(), 0f)) { continue; } double grow = flexItem.getFlexGrow() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMaxWidth() : flexItem.getMaxHeight(); if (grownSize > clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexGrow(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } else if (freeSpace < 0) { if (line.getShrink() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getShrink(); growUnit = freeSpace / line.getShrink(); while (totalGrow > 0 && growUnit < 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, totalGrow, 1f)) { continue; } double grow = flexItem.getFlexShrink() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMinWidth() : flexItem.getMinHeight(); if (grownSize < clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexShrink(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } }  double getMinMainSize(); double getMinCrossSize(); void layoutSubViews(double mainSize, double crossSize); boolean isHorizontal(); FlexDirection getFlexDirection(); void setFlexDirection(FlexDirection flexDirection); FlexWrap getFlexWrap(); void setFlexWrap(FlexWrap flexWrap); JustifyContent getJustifyContent(); void setJustifyContent(JustifyContent justifyContent); AlignItems getAlignItems(); void setAlignItems(AlignItems alignItems); AlignContent getAlignContent(); void setAlignContent(AlignContent alignContent); void add(FlexItem flexItem); void clearItems(); }
FlexboxLayout { void distributeMainLineSpace(FlexLine line, boolean horizontal, double mainSize) { List<FlexItem> flexItems = line.flexItems; double freeSpace = mainSize - line.minMainSize; double growUnit = 0; if (freeSpace > 0) { if (line.getGrow() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getGrow(); growUnit = freeSpace / line.getGrow(); while (totalGrow > 0 && growUnit > 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, flexItem.getFlexGrow(), 0f)) { continue; } double grow = flexItem.getFlexGrow() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMaxWidth() : flexItem.getMaxHeight(); if (grownSize > clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexGrow(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } else if (freeSpace < 0) { if (line.getShrink() > 0) { HashSet<FlexItem> frozen = new HashSet<>(); float totalGrow = line.getShrink(); growUnit = freeSpace / line.getShrink(); while (totalGrow > 0 && growUnit < 0) { double rest = 0; for (FlexItem flexItem : flexItems) { if (checkSkipItem(frozen, flexItem, totalGrow, 1f)) { continue; } double grow = flexItem.getFlexShrink() * growUnit; double grownSize = grow + flexItem.getMainTargetSize(); double clampedSize = horizontal ? flexItem.getMinWidth() : flexItem.getMinHeight(); if (grownSize < clampedSize) { rest += grownSize - clampedSize; grownSize = clampedSize; frozen.add(flexItem); totalGrow -= flexItem.getFlexShrink(); } double distributed = grownSize - flexItem.getMainTargetSize(); flexItem.setMainTargetSize(grownSize); line.minMainSize += distributed; } if (rest > 0) { growUnit = getNewGrowUnit(totalGrow, rest); } else { break; } } } } }  double getMinMainSize(); double getMinCrossSize(); void layoutSubViews(double mainSize, double crossSize); boolean isHorizontal(); FlexDirection getFlexDirection(); void setFlexDirection(FlexDirection flexDirection); FlexWrap getFlexWrap(); void setFlexWrap(FlexWrap flexWrap); JustifyContent getJustifyContent(); void setJustifyContent(JustifyContent justifyContent); AlignItems getAlignItems(); void setAlignItems(AlignItems alignItems); AlignContent getAlignContent(); void setAlignContent(AlignContent alignContent); void add(FlexItem flexItem); void clearItems();  }