Remove loop to calculate maximum (target) width, remove capturing lambda

This commit is contained in:
MarcinZiabek
2023-03-07 21:22:45 +01:00
parent c3c0d7631c
commit 458b379208
+7 -3
View File
@@ -87,6 +87,7 @@ namespace QuestPDF.Elements
private ICollection<ColumnItemRenderingCommand> PlanLayout(Size availableSpace)
{
var topOffset = 0f;
var targetWidth = 0f;
var commands = new List<ColumnItemRenderingCommand>();
foreach (var item in Items)
@@ -113,15 +114,18 @@ namespace QuestPDF.Elements
Offset = new Position(0, topOffset)
});
if (measurement.Width > targetWidth)
targetWidth = measurement.Width;
if (measurement.Type == SpacePlanType.PartialRender)
break;
topOffset += measurement.Height + Spacing;
}
var targetWidth = commands.Select(x => x.Size.Width).DefaultIfEmpty(0).Max();
commands.ForEach(x => x.Size = new Size(targetWidth, x.Size.Height));
foreach (var command in commands)
command.Size = new Size(targetWidth, command.Size.Height);
return commands;
}
}