private void ComputeTableWidth() { Width = (TableStyle.Left == char.MinValue ? 0 : 1) // length of the left border + ColumnDefinitions.Sum(cd => cd.Width) //sum of the column widths + ((ColumnDefinitions.Count - 1) * TableStyle.Separator.Length) // sum of the space occupied by column separators; + (TableStyle.Right == char.MinValue ? 0 : 1) // length of the right border ; }
// Do measurement when in horizontal orientation private void MeasureHorizontal(nfloat parentWidth, nfloat parentHeight) { // Work out our height nfloat layoutWidth = LayoutParameters.TryResolveWidth(this, parentWidth, parentHeight); nfloat layoutHeight = LayoutParameters.TryResolveHeight(this, parentWidth, parentHeight); // Work out the total fixed size var paddings = Padding.TotalWidth(); _goneViews = new List <View>(); _arrangedViews = new View[RowDefinitions.Count, ColumnDefinitions.Count]; var columnWidthFillParentSubviews = new List <View>(); //calculating columns var minWidth = (nfloat)ColumnDefinitions.Sum(x => x.MinWidth); foreach (var v in SubViews.Where(x => !x.Gone)) { _arrangedViews[v.Row, v.Column] = v; var columnDefinition = ColumnDefinitions[v.Column]; var rowDefinition = RowDefinitions[v.Column]; nfloat width; if (columnDefinition.Width > 0) { width = columnDefinition.Width; } else if (columnDefinition.MaxWidth > 0) { width = columnDefinition.MaxWidth; } else { width = parentWidth - paddings; } nfloat height; if (rowDefinition.Height > 0) { height = rowDefinition.Height; } else { height = adjustLayoutHeight(layoutHeight, v); } if (v.LayoutParameters.WidthUnits != Units.ParentRatio) { v.Measure(width - v.LayoutParameters.Margins.TotalWidth(), height); } else { v._measuredSize = new CGSize(0, 0); v._measuredSizeValid = true; columnWidthFillParentSubviews.Add(v); } } { nfloat totalWeight = 0; nfloat totalWidth = 0; var columnId = -1; foreach (var column in ColumnDefinitions) { columnId++; column.CalculatedWidth = 0; if (column.Width > 0) { column.CalculatedWidth = column.Width; } else if (column.Width == AutoSize.WrapContent) { for (int rowId = 0; rowId < RowDefinitions.Count; rowId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { column.CalculatedWidth = NMath.Max(column.CalculatedWidth, v.GetMeasuredSize().Width + v.LayoutParameters.Margins.TotalWidth()); } } } else if (column.Width == AutoSize.FillParent) { totalWeight += column.Weight; } totalWidth += column.CalculatedWidth; } var room = layoutWidth - totalWidth; foreach (var column in ColumnDefinitions.Where(x => x.Width == AutoSize.FillParent)) { columnId++; column.CalculatedWidth = room * column.Weight / totalWeight; } } { var totalWeight = 0; var totalHeight = 0; var rowId = -1; foreach (var row in RowDefinitions) { rowId++; if (row.Height > 0) { row.CalculatedHeight = row.Height; continue; } if (row.Height == AutoSize.WrapContent) { row.CalculatedHeight = 0; for (int columnId = 0; columnId < ColumnDefinitions.Count; columnId++) { var v = _arrangedViews[rowId, columnId]; if (v != null) { row.CalculatedHeight = NMath.Max(row.CalculatedHeight, v.GetMeasuredSize().Height); } } } } var room = layoutHeight - totalHeight; foreach (var row in RowDefinitions.Where(x => x.Height == AutoSize.FillParent)) { row.CalculatedHeight = room * row.Weight / totalWeight; } } CGSize sizeMeasured = CGSize.Empty; foreach (var item in ColumnDefinitions) { sizeMeasured.Width += item.CalculatedWidth; } sizeMeasured.Width += ColSpacing * (ColumnDefinitions.Count - 1); foreach (var item in RowDefinitions) { sizeMeasured.Height += item.CalculatedHeight; } sizeMeasured.Height += RowSpacing * (RowDefinitions.Count - 1); foreach (var v in columnWidthFillParentSubviews) { v.Measure(ColumnDefinitions[v.Column].CalculatedWidth, RowDefinitions[v.Row].CalculatedHeight); } // And finally, set our measure dimensions SetMeasuredSize(LayoutParameters.ResolveSize(new CGSize(layoutWidth, layoutHeight), sizeMeasured)); }