/// <summary>
        /// Calculates the relative point in the Grid for the available space for this measure
        /// </summary>
        /// <returns>The upper left edge.</returns>
        /// <param name="measure">Measure.</param>
        private PointF CalculateUpperLeftEdge(GridSubViewMeasure measure)
        {
            float x = 0, y = 0;

            for (int i = 0; i < measure.Row && i < __rows.Count; i++)
                y = y + __rows[i].RealHeight;

            for (int j = 0; j < measure.Column && j < __columns.Count; j++)
                x = x + __columns[j].RealWidth;

            PointF upperLeftEdge = new PointF(x, y);

            return upperLeftEdge;
        }
        /// <summary>
        /// Calculates the available space in the Grid for this measure
        /// </summary>
        /// <returns>The boundary frame.</returns>
        /// <param name="measure">Measure.</param>
        private SizeF CalculateBoundaryFrame(GridSubViewMeasure measure)
        {
            float width = 0, height = 0;
            int lastRow = measure.Row + measure.RowSpan;
            int lastColumn = measure.Column + measure.ColumnSpan;

            for (int i = measure.Row; i < lastRow && i < __rows.Count; i++)
                height = height + __rows[i].RealHeight;

            for (int j = measure.Column; j < lastColumn && j < __columns.Count; j++)
                width = width + __columns[j].RealWidth;

            SizeF boundaryFrame = new SizeF(width, height);
            return boundaryFrame;
        }
        private RectangleF CalculateMeasure(GridSubViewMeasure measure)
        {
            PointF originPoint = this.CalculateUpperLeftEdge(measure);
            SizeF boundaryFrame = this.CalculateBoundaryFrame(measure);

            float relativeWidth = measure.HorizontalAlignment.CalculateWidth(boundaryFrame.Width, measure.Width, measure.AutoWidth, measure.Margin);
            float relativeXPosition = measure.HorizontalAlignment.CalculateXPosition(boundaryFrame.Width, relativeWidth, measure.Margin);

            float relativeHeight = measure.VerticalAlignment.CalculateHeight(boundaryFrame.Height, measure.Height, measure.AutoHeight, measure.Margin);
            float relativeYPosition = measure.VerticalAlignment.CalculateYPosition(boundaryFrame.Height, relativeHeight, measure.Margin);

            PointF subViewLocation = new PointF(originPoint.X + relativeXPosition, originPoint.Y + relativeYPosition);
            SizeF subViewSize = new SizeF(relativeWidth, relativeHeight);

            RectangleF subViewRectangle = new RectangleF(subViewLocation, subViewSize);
            return subViewRectangle;
        }
示例#4
0
        public void AddChild(UIView subView, int row = 0, int column = 0, int rowSpan = 1, int columnSpan = 1, 
                               bool autoHeight = true, bool autoWidth = true, GridHorizontalAlignment horizontalAlingment = GridHorizontalAlignment.Stretch, 
                               GridVerticalAlignment verticalAlingment = GridVerticalAlignment.Stretch, 
                               SubViewThickness margin = default(SubViewThickness))
        {
            GridSubViewMeasure subViewMeasure = new GridSubViewMeasure()
            {Row = row, Column = column, RowSpan = rowSpan, ColumnSpan = columnSpan,
                AutoWidth = autoWidth, AutoHeight = autoHeight, 
                HorizontalAlignment = horizontalAlingment, VerticalAlignment = verticalAlingment,
                Margin = margin, Width = subView.Frame.Width, Height = subView.Frame.Height
            };

            __measures.Add(subView, subViewMeasure);
            RectangleF subViewFrame = this.CalculateMeasure(subViewMeasure);
            subView.Frame = subViewFrame;
            this.Add(subView);
        }