本文整理汇总了C#中nfloat.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# nfloat.Sum方法的具体用法?C# nfloat.Sum怎么用?C# nfloat.Sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nfloat
的用法示例。
在下文中一共展示了nfloat.Sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateColumnWidths
private nfloat[] CalculateColumnWidths(CGSize availableSpace)
{
var widthsByRow = new List<nfloat[]>();
foreach (var row in rows)
{
for (var i = 0; i < widths.Length; i++)
{
var width = widths[i];
var sizeRow = new nfloat[widths.Length];
switch (width.Style)
{
case TableWidthStyle.SizeToFit:
sizeRow[i] = (nfloat)row[i].SizeThatFits(new CGSize(nfloat.MaxValue, nfloat.MaxValue)).Width;
break;
case TableWidthStyle.Fixed:
sizeRow[i] = width.Value;
break;
case TableWidthStyle.Percentage:
case TableWidthStyle.Weight:
sizeRow[i] = 0;
break;
}
widthsByRow.Add(sizeRow);
}
}
var calculatedWidths = new nfloat[widths.Length];
for (var i = 0; i < widths.Length; i++)
{
calculatedWidths[i] = (nfloat)widthsByRow.Max(x => x[i]);
}
var bespokeWidth = calculatedWidths.Sum(x => x) + GetPaddingAndSpacingWidth();
var remainingWidth = availableSpace.Width - bespokeWidth;
var weightWidth = (nfloat)(remainingWidth - (nfloat)((nfloat)remainingWidth * widths.Where(x => x.Style == TableWidthStyle.Percentage).Sum(x => x.Value) / 100));
var totalWeight = widths.Where(x => x.Style == TableWidthStyle.Weight).Sum(x => x.Value);
var individualWeightWidth = weightWidth / totalWeight;
var oddManOutWeightWidth = weightWidth - individualWeightWidth * totalWeight;
var result = new nfloat[widths.Length];
for (var i = 0; i < result.Length; i++)
{
var width = widths[i];
switch (width.Style)
{
case TableWidthStyle.Fixed:
case TableWidthStyle.SizeToFit:
result[i] = calculatedWidths[i];
break;
case TableWidthStyle.Percentage:
result[i] = (nfloat)((nfloat)width.Value / 100 * remainingWidth);
break;
case TableWidthStyle.Weight:
result[i] = individualWeightWidth * width.Value + oddManOutWeightWidth;
oddManOutWeightWidth = 0;
break;
}
}
return result;
}