protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) { SizeRequest desiredSize = base.OnMeasure(double.PositiveInfinity, double.PositiveInfinity); return(ImageElement.Measure(this, desiredSize, widthConstraint, heightConstraint)); }
void CalculateNaiveLayout(LayoutInformation layout, StackOrientation orientation, double x, double y, double widthConstraint, double heightConstraint) { layout.CompressionSpace = 0; double xOffset = x; double yOffset = y; double boundsWidth = 0; double boundsHeight = 0; double minimumWidth = 0; double minimumHeight = 0; double spacing = Spacing; if (orientation == StackOrientation.Vertical) { View expander = null; for (var i = 0; i < LogicalChildrenInternal.Count; i++) { var child = (View)LogicalChildrenInternal[i]; if (!child.IsVisible) { continue; } if (child.VerticalOptions.Expands) { layout.Expanders++; if (expander != null) { // we have multiple expanders, make sure previous expanders are reset to not be fixed because they no logner are ComputeConstraintForView(child, false); } expander = child; } SizeRequest request = child.Measure(widthConstraint, double.PositiveInfinity, MeasureFlags.IncludeMargins); var bounds = new Rectangle(x, yOffset, request.Request.Width, request.Request.Height); layout.Plots[i] = bounds; layout.Requests[i] = request; layout.CompressionSpace += Math.Max(0, request.Request.Height - request.Minimum.Height); yOffset = bounds.Bottom + spacing; boundsWidth = Math.Max(boundsWidth, request.Request.Width); boundsHeight = bounds.Bottom - y; minimumHeight += request.Minimum.Height + spacing; minimumWidth = Math.Max(minimumWidth, request.Minimum.Width); } minimumHeight -= spacing; if (expander != null) { ComputeConstraintForView(expander, layout.Expanders == 1); // warning : slightly obtuse, but we either need to setup the expander or clear the last one } } else { View expander = null; for (var i = 0; i < LogicalChildrenInternal.Count; i++) { var child = (View)LogicalChildrenInternal[i]; if (!child.IsVisible) { continue; } if (child.HorizontalOptions.Expands) { layout.Expanders++; if (expander != null) { ComputeConstraintForView(child, false); } expander = child; } SizeRequest request = child.Measure(double.PositiveInfinity, heightConstraint, MeasureFlags.IncludeMargins); var bounds = new Rectangle(xOffset, y, request.Request.Width, request.Request.Height); layout.Plots[i] = bounds; layout.Requests[i] = request; layout.CompressionSpace += Math.Max(0, request.Request.Width - request.Minimum.Width); xOffset = bounds.Right + spacing; boundsWidth = bounds.Right - x; boundsHeight = Math.Max(boundsHeight, request.Request.Height); minimumWidth += request.Minimum.Width + spacing; minimumHeight = Math.Max(minimumHeight, request.Minimum.Height); } minimumWidth -= spacing; if (expander != null) { ComputeConstraintForView(expander, layout.Expanders == 1); } } layout.Bounds = new Rectangle(x, y, boundsWidth, boundsHeight); layout.MinimumSize = new Size(minimumWidth, minimumHeight); }
double MeasuredStarredColumns(double widthConstraint, double heightConstraint) { double starColWidth; for (var iteration = 0; iteration < 2; iteration++) { for (var colspan = 1; colspan <= _columns.Count; colspan++) { for (var i = 0; i < _columns.Count; i++) { ColumnDefinition col = _columns[i]; if (!col.Width.IsStar) { continue; } if (col.ActualWidth >= 0) // if Actual is already set (by a smaller span), skip { continue; } double actualWidth = col.ActualWidth; double minimumWidth = col.MinimumWidth; for (var index = 0; index < InternalChildren.Count; index++) { var child = (View)InternalChildren[index]; if (!child.IsVisible || GetColumnSpan(child) != colspan || !IsInColumn(child, i) || NumberOfUnsetColumnWidth(child) > 1) { continue; } double assignedWidth = GetAssignedColumnWidth(child); SizeRequest sizeRequest = child.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins); actualWidth = Math.Max(actualWidth, sizeRequest.Request.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing); minimumWidth = Math.Max(minimumWidth, sizeRequest.Minimum.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing); } if (actualWidth >= 0) { col.ActualWidth = actualWidth; } if (minimumWidth >= 0) { col.MinimumWidth = minimumWidth; } } } } //Measure the stars starColWidth = 1; for (var index = 0; index < _columns.Count; index++) { ColumnDefinition col = _columns[index]; if (!col.Width.IsStar) { continue; } starColWidth = col.Width.Value != 0 ? Math.Max(starColWidth, col.ActualWidth / col.Width.Value) : 0; } return(starColWidth); }
double MeasureStarredRows() { double starRowHeight; for (var iteration = 0; iteration < 2; iteration++) { for (var rowspan = 1; rowspan <= _rows.Count; rowspan++) { for (var i = 0; i < _rows.Count; i++) { RowDefinition row = _rows[i]; if (!row.Height.IsStar) { continue; } if (row.ActualHeight >= 0) // if Actual is already set (by a smaller span), skip till pass 3 { continue; } double actualHeight = row.ActualHeight; double minimumHeight = row.MinimumHeight; for (var index = 0; index < InternalChildren.Count; index++) { var child = (View)InternalChildren[index]; if (!child.IsVisible || GetRowSpan(child) != rowspan || !IsInRow(child, i) || NumberOfUnsetRowHeight(child) > 1) { continue; } double assignedHeight = GetAssignedRowHeight(child); double assignedWidth = GetAssignedColumnWidth(child); SizeRequest sizeRequest = child.Measure(assignedWidth, double.PositiveInfinity, MeasureFlags.IncludeMargins); actualHeight = Math.Max(actualHeight, sizeRequest.Request.Height - assignedHeight - RowSpacing * (GetRowSpan(child) - 1)); minimumHeight = Math.Max(minimumHeight, sizeRequest.Minimum.Height - assignedHeight - RowSpacing * (GetRowSpan(child) - 1)); } if (actualHeight >= 0) { row.ActualHeight = actualHeight; } if (minimumHeight >= 0) { row.MinimumHeight = minimumHeight; } } } } // 3. Star columns: //Measure the stars starRowHeight = 1; for (var index = 0; index < _rows.Count; index++) { RowDefinition row = _rows[index]; if (!row.Height.IsStar) { continue; } starRowHeight = row.Height.Value != 0 ? Math.Max(starRowHeight, row.ActualHeight / row.Height.Value) : 0; } return(starRowHeight); }
void CalculateAutoCells(double width, double height) { // this require multiple passes. First process the 1-span, then 2, 3, ... // And this needs to be run twice, just in case a lower-span column can be determined by a larger span for (var iteration = 0; iteration < 2; iteration++) { for (var rowspan = 1; rowspan <= _rows.Count; rowspan++) { for (var i = 0; i < _rows.Count; i++) { RowDefinition row = _rows[i]; if (!row.Height.IsAuto) { continue; } if (row.ActualHeight >= 0) // if Actual is already set (by a smaller span), skip till pass 3 { continue; } double actualHeight = row.ActualHeight; double minimumHeight = row.MinimumHeight; for (var index = 0; index < InternalChildren.Count; index++) { var child = (View)InternalChildren[index]; if (!child.IsVisible || GetRowSpan(child) != rowspan || !IsInRow(child, i) || NumberOfUnsetRowHeight(child) > 1) { continue; } double assignedWidth = GetAssignedColumnWidth(child); double assignedHeight = GetAssignedRowHeight(child); double widthRequest = assignedWidth + GetUnassignedWidth(width); double heightRequest = double.IsPositiveInfinity(height) ? double.PositiveInfinity : assignedHeight + GetUnassignedHeight(height); SizeRequest sizeRequest = child.Measure(widthRequest, heightRequest, MeasureFlags.IncludeMargins); actualHeight = Math.Max(actualHeight, sizeRequest.Request.Height - assignedHeight - RowSpacing * (GetRowSpan(child) - 1)); minimumHeight = Math.Max(minimumHeight, sizeRequest.Minimum.Height - assignedHeight - RowSpacing * (GetRowSpan(child) - 1)); } if (actualHeight >= 0) { row.ActualHeight = actualHeight; } if (minimumHeight >= 0) { row.MinimumHeight = minimumHeight; } } } for (var colspan = 1; colspan <= _columns.Count; colspan++) { for (var i = 0; i < _columns.Count; i++) { ColumnDefinition col = _columns[i]; if (!col.Width.IsAuto) { continue; } if (col.ActualWidth >= 0) // if Actual is already set (by a smaller span), skip { continue; } double actualWidth = col.ActualWidth; double minimumWidth = col.MinimumWidth; for (var index = 0; index < InternalChildren.Count; index++) { var child = (View)InternalChildren[index]; if (!child.IsVisible || GetColumnSpan(child) != colspan || !IsInColumn(child, i) || NumberOfUnsetColumnWidth(child) > 1) { continue; } double assignedWidth = GetAssignedColumnWidth(child); double assignedHeight = GetAssignedRowHeight(child); double widthRequest = double.IsPositiveInfinity(width) ? double.PositiveInfinity : assignedWidth + GetUnassignedWidth(width); double heightRequest = assignedHeight + GetUnassignedHeight(height); SizeRequest sizeRequest = child.Measure(widthRequest, heightRequest, MeasureFlags.IncludeMargins); actualWidth = Math.Max(actualWidth, sizeRequest.Request.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing); minimumWidth = Math.Max(minimumWidth, sizeRequest.Minimum.Width - assignedWidth - (GetColumnSpan(child) - 1) * ColumnSpacing); } if (actualWidth >= 0) { col.ActualWidth = actualWidth; } if (minimumWidth >= 0) { col.MinimumWidth = minimumWidth; } } } } }