private (int[] widths, int[] heights) WithExpandable(params Spacer[] spacers) { var total = Inner?.DesiredSize ?? Size.Empty; var widthExpandable = Inner?.Width.IsUnlimited ?? false ? 1 : 0; var heightExpandable = Inner?.Height.IsUnlimited ?? false ? 1 : 0; foreach (var s in spacers) { if (s.Left.IsUnlimited) { ++widthExpandable; } if (s.Right.IsUnlimited) { ++widthExpandable; } if (s.Top.IsUnlimited) { ++heightExpandable; } if (s.Bottom.IsUnlimited) { ++heightExpandable; } total += s.GetAbsoluteSize(); } var remaining = Layout.Size - total; return(SizeUnit.Distribute(remaining.Width, widthExpandable), SizeUnit.Distribute(remaining.Height, heightExpandable)); }
private (Size alignmentShift, int[] unlimitedBuffers) MeasureRemainingSpace() { var unlimited = 0; var remaining = Layout.Width; foreach (var child in GetChildren()) { remaining -= child.DesiredSize.Width; if (child.Width.IsUnlimited) { ++unlimited; } } if (unlimited > 0) { return(Size.Empty, SizeUnit.Distribute(Math.Max(0, remaining), unlimited)); } return(Size.Empty, Array.Empty <int>()); }
public void Distribute_returns_proper_values() { SizeUnit.Distribute(100, 7).ShouldBe(new[] { 14, 14, 14, 15, 14, 14, 15 }); SizeUnit.Distribute(100, 999999).Sum().ShouldBe(100); }