protected virtual void ArrangeContent(SizeF finalSize)
        {
            Thickness nativePadding = this.GetNativePadding();

            var totalLeftOffset   = this.Padding.LeftF() + nativePadding.LeftF();
            var totalTopOffset    = this.Padding.TopF() + nativePadding.TopF();
            var totalRightOffset  = this.Padding.RightF() + nativePadding.RightF();
            var totalBottomOffset = this.Padding.BottomF() + nativePadding.BottomF();
            var rawWidthOfRect    = finalSize.Width - this.Margin.HorizontalThicknessF();
            var rawHeigthOfRect   = finalSize.Height - this.Margin.VerticalThicknessF();

            var x      = (nfloat)totalLeftOffset;
            var y      = (nfloat)totalTopOffset;
            var width  = this.contentSize.Width;
            var heigth = this.contentSize.Height;

            if ((rawWidthOfRect - totalLeftOffset - totalRightOffset - this.contentSize.Width) > 0)
            {
                x    += (rawWidthOfRect - totalLeftOffset - totalRightOffset - this.contentSize.Width) / 2;
                width = this.contentSize.Width;
            }

            if ((rawHeigthOfRect - totalTopOffset - totalBottomOffset - this.contentSize.Height) > 0)
            {
                y     += (rawHeigthOfRect - totalTopOffset - totalBottomOffset - this.contentSize.Height) / 2;
                heigth = this.contentSize.Height;
            }

            var contentFrame = new RectangleF(x, y, width, heigth);

            if (this.contentTemplateInstance == null)
            {
                this.NativeArrangeContent(contentFrame);
            }
            else
            {
                this.contentTemplateInstance.Arrange(contentFrame);
            }
        }
Пример #2
0
            private void DrawRect(CGContext g, CGRect rect, Thickness borderThickness, Brush borderBrush, Brush fill, CornerRadius cornerRadius)
            {
                var center      = new CGPoint(rect.Left + cornerRadius.TopLeft + borderThickness.Left / 2, rect.Top + cornerRadius.TopLeft + borderThickness.Top / 2);
                var strokeColor = borderBrush != null?borderBrush.ToUIColor(rect.Size).CGColor : UIColor.Black.CGColor;

                g.SetStrokeColor(strokeColor);
                g.SetFillColor(strokeColor);
                List <Arc> innerArcs = new List <Arc>();

                if (cornerRadius.TopLeft != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.TopLeft, center, borderThickness.LeftF(), borderThickness.TopF(), 180f, 270f));
                }
                else
                {
                    innerArcs.Add(new Arc()
                    {
                        Center = center
                    });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.TopF());
                g.MoveTo((nfloat)cornerRadius.TopLeft, borderThickness.TopF() / 2);
                g.AddLineToPoint(rect.Right - (nfloat)cornerRadius.TopRight - borderThickness.RightF() / 2, borderThickness.TopF() / 2);
                g.StrokePath();
                center = new CGPoint(rect.Right - cornerRadius.TopRight - borderThickness.Right / 2, rect.Top + cornerRadius.TopRight + borderThickness.Top / 2);
                if (cornerRadius.TopRight != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.TopRight, center, borderThickness.TopF(), borderThickness.RightF(), -90f, 0f));
                }
                else
                {
                    innerArcs.Add(new Arc {
                        Center = center
                    });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.RightF());
                g.MoveTo(rect.Right - borderThickness.RightF() / 2, (nfloat)cornerRadius.TopRight);
                g.AddLineToPoint(rect.Right - borderThickness.RightF() / 2, rect.Height - (nfloat)cornerRadius.BottomRight);
                g.StrokePath();
                center = new CGPoint(rect.Right - cornerRadius.BottomRight - borderThickness.Right / 2, rect.Bottom - cornerRadius.BottomRight - borderThickness.Bottom / 2);
                if (cornerRadius.BottomRight != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.BottomRight, center, borderThickness.RightF(), borderThickness.BottomF(), 0f, 90f));
                }
                else
                {
                    innerArcs.Add(new Arc()
                    {
                        Center = center
                    });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.BottomF());
                g.MoveTo(rect.Right - (nfloat)cornerRadius.BottomRight, rect.Bottom - borderThickness.BottomF() / 2);
                g.AddLineToPoint(rect.Left + (nfloat)cornerRadius.BottomLeft, rect.Bottom - borderThickness.BottomF() / 2);
                g.StrokePath();
                center = new CGPoint((rect.Left + cornerRadius.BottomLeft + borderThickness.Left / 2), (rect.Bottom - cornerRadius.BottomLeft - borderThickness.Bottom / 2));
                if (cornerRadius.BottomLeft != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.BottomLeft, center, borderThickness.BottomF(), borderThickness.LeftF(), 90f, 180f));
                }
                else
                {
                    innerArcs.Add(new Arc()
                    {
                        Center = center
                    });
                }
                g.SetLineWidth((nfloat)borderThickness.Left);
                g.MoveTo(rect.Left + borderThickness.LeftF() / 2, rect.Bottom - (nfloat)cornerRadius.BottomLeft);
                g.AddLineToPoint(rect.Left + borderThickness.LeftF() / 2, rect.Top + (nfloat)cornerRadius.TopLeft);
                g.StrokePath();
                if (fill != null)
                {
                    var fillColor = fill.ToUIColor(rect.Size).CGColor;
                    g.SetFillColor(fillColor);
                    g.SetLineWidth(0);
                    using (CGPath path = new CGPath())
                    {
                        path.AddArc(
                            innerArcs[0].Center.X,
                            innerArcs[0].Center.Y,
                            innerArcs[0].Radius,
                            innerArcs[0].EndingAngle,
                            innerArcs[0].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[1].Center.X,
                            innerArcs[1].Center.Y,
                            innerArcs[1].Radius,
                            innerArcs[1].EndingAngle,
                            innerArcs[1].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[2].Center.X,
                            innerArcs[2].Center.Y,
                            innerArcs[2].Radius,
                            innerArcs[2].EndingAngle,
                            innerArcs[2].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[3].Center.X,
                            innerArcs[3].Center.Y,
                            innerArcs[3].Radius,
                            innerArcs[3].EndingAngle,
                            innerArcs[3].StartingAngle,
                            false);

                        g.AddPath(path);
                        g.DrawPath(CGPathDrawingMode.Fill);
                    }
                }
            }