예제 #1
0
 public Rect(Point location, Size size)
 {
     this.x = location.X;
     this.y = location.Y;
     this.width = size.Width;
     this.height = size.Height;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rect"/> structure.
 /// </summary>
 /// <param name="size">The size of the rectangle.</param>
 public Rect(Size size)
 {
     _x = 0;
     _y = 0;
     _width = size.Width;
     _height = size.Height;
 }
        protected override Avalonia.Size ArrangeOverride(Avalonia.Size finalSize)
        {
            if (Element == null)
            {
                return(finalSize);
            }

            Element.IsInNativeLayout = true;

            for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
            {
                var child = ElementController.LogicalChildren[i] as VisualElement;
                if (child == null)
                {
                    continue;
                }

                IVisualElementRenderer renderer = Platform.GetRenderer(child);
                if (renderer == null)
                {
                    continue;
                }

                Rectangle bounds     = child.Bounds;
                Control   control    = renderer.GetNativeElement();
                Rect      childFinal = new Rect(bounds.X, bounds.Y, Math.Max(0, bounds.Width), Math.Max(0, bounds.Height));
                control.Arrange(childFinal);
            }

            Element.IsInNativeLayout = false;

            return(finalSize);
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Rect"/> structure.
 /// </summary>
 /// <param name="position">The position of the rectangle.</param>
 /// <param name="size">The size of the rectangle.</param>
 public Rect(Point position, Size size)
 {
     _x = position.X;
     _y = position.Y;
     _width = size.Width;
     _height = size.Height;
 }
예제 #5
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (double.IsNaN(Width))
            {
                Width = 0;
            }

            return new Size(Width, 0);
        }
        protected override Avalonia.Size MeasureOverride(Avalonia.Size availableSize)
        {
            if (Element == null || availableSize.Width * availableSize.Height == 0)
            {
                return(new Avalonia.Size(0, 0));
            }

            Element.IsInNativeLayout = true;

            for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
            {
                var child = ElementController.LogicalChildren[i] as VisualElement;
                if (child == null)
                {
                    continue;
                }

                IVisualElementRenderer renderer = Platform.GetOrCreateRenderer(child);
                if (renderer == null)
                {
                    continue;
                }

                Control control = renderer.GetNativeElement();
                if (control.Bounds.Width != child.Width || control.Bounds.Height != child.Height)
                {
                    double width  = child.Width <= -1 ? Bounds.Width : child.Width;
                    double height = child.Height <= -1 ? Bounds.Height : child.Height;
                    control.Measure(new Avalonia.Size(width, height));
                }
            }

            Avalonia.Size result;
            if (double.IsInfinity(availableSize.Width) || double.IsPositiveInfinity(availableSize.Height))
            {
                Size request = Element.Measure(availableSize.Width, availableSize.Height, MeasureFlags.IncludeMargins).Request;
                result = new Avalonia.Size(request.Width, request.Height);
            }
            else
            {
                result = availableSize;
            }
            Element.IsInNativeLayout = false;

            if (Double.IsPositiveInfinity(result.Height))
            {
                result.WithHeight(0.0);
            }
            if (Double.IsPositiveInfinity(result.Width))
            {
                result.WithWidth(0.0);
            }

            return(result);
        }
예제 #7
0
        private A.Point GetTextOrigin(ShapeStyle style, ref Rect2 rect, ref A.Size size)
        {
            double ox, oy;

            switch (style.TextStyle.TextHAlignment)
            {
            case TextHAlignment.Left:
                ox = rect.X;
                break;

            case TextHAlignment.Right:
                ox = rect.Right - size.Width;
                break;

            case TextHAlignment.Center:
            default:
                ox = (rect.Left + rect.Width / 2.0) - (size.Width / 2.0);
                break;
            }

            switch (style.TextStyle.TextVAlignment)
            {
            case TextVAlignment.Top:
                oy = rect.Y;
                break;

            case TextVAlignment.Bottom:
                oy = rect.Bottom - size.Height;
                break;

            case TextVAlignment.Center:
            default:
                oy = (rect.Bottom - rect.Height / 2f) - (size.Height / 2f);
                break;
            }

            return(new A.Point(ox, oy));
        }
예제 #8
0
        public virtual SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (Control == null)
            {
                return(new SizeRequest());
            }

            var constraint = new Avalonia.Size(widthConstraint, heightConstraint);

            if (Element.HeightRequest == -1)
            {
                Control.Height = double.NaN;
            }

            if (Element.WidthRequest == -1)
            {
                Control.Width = double.NaN;
            }

            Control.Measure(constraint);

            return(new SizeRequest(new Size(Math.Ceiling(Control.DesiredSize.Width), Math.Ceiling(Control.DesiredSize.Height))));
        }
예제 #9
0
 /// <summary>
 /// Convert from WPF size to core size.
 /// </summary>
 public static RSize Convert(Size s)
 {
     return new RSize(s.Width, s.Height);
 }
예제 #10
0
 protected virtual Size ArrangeOverride(Size finalSize)
 {
     return finalSize;
 }
예제 #11
0
        protected sealed override void ArrangeCore(Rect finalRect)
        {
            Point origin = new Point(
                finalRect.Left + this.Margin.Left,
                finalRect.Top + this.Margin.Top);
            
            Size size = new Size(
                Math.Max(0, finalRect.Width - this.Margin.Left - this.Margin.Right),
                Math.Max(0, finalRect.Height - this.Margin.Top - this.Margin.Bottom));

            if (this.HorizontalAlignment != HorizontalAlignment.Stretch)
            {
                size = new Size(Math.Min(size.Width, this.DesiredSize.Width), size.Height);
            }

            if (this.VerticalAlignment != VerticalAlignment.Stretch)
            {
                size = new Size(size.Width, Math.Min(size.Height, this.DesiredSize.Height));
            }

            Size taken = this.ArrangeOverride(size);

            size = new Size(
                Math.Min(taken.Width, size.Width),
                Math.Min(taken.Height, size.Height));

            switch (this.HorizontalAlignment)
            {
                case HorizontalAlignment.Center:
                    origin.X += (finalRect.Width - size.Width) / 2;
                    break;
                case HorizontalAlignment.Right:
                    origin.X += finalRect.Width - size.Width;
                    break;
            }

            switch (this.VerticalAlignment)
            {
                case VerticalAlignment.Center:
                    origin.Y += (finalRect.Height - size.Height) / 2;
                    break;
                case VerticalAlignment.Bottom:
                    origin.Y += finalRect.Height - size.Height;
                    break;
            }

            base.ArrangeCore(new Rect(origin, size));
        }
예제 #12
0
 protected virtual Size MeasureCore(Size availableSize)
 {
     return new Size();
 }
예제 #13
0
 /// <summary>
 /// Constrains the size.
 /// </summary>
 /// <param name="constraint">The size to constrain to.</param>
 /// <returns>The constrained size.</returns>
 public Size Constrain(Size constraint)
 {
     return new Size(
         Math.Min(_width, constraint._width),
         Math.Min(_height, constraint._height));
 }
예제 #14
0
 public static Rect Inflate(Rect rect, Size size)
 {
     return Rect.Inflate(rect, size.Width, size.Height);
 }
예제 #15
0
 protected override Size ArrangeOverride(Size finalSize)
 {
     _viewport = new Size(finalSize.Width, finalSize.Height / _lineSize.Height);
     _extent = new Size(_lineSize.Width, itemCount + 1);
     InvalidateScroll?.Invoke();
     return finalSize;
 }
예제 #16
0
 public static bool Equals(Size size1, Size size2)
 {
     return size1.Equals(size2);
 }
예제 #17
0
 public bool Equals(Size value)
 {
     return this.width == value.Width && this.height == value.Height;
 }
예제 #18
0
 protected override Size MeasureOverride(Size availableSize)
 {
     using (var line = new FormattedText(
         "Item 100",
         TextBlock.GetFontFamily(this),
         TextBlock.GetFontSize(this),
         TextBlock.GetFontStyle(this),
         TextAlignment.Left,
         TextBlock.GetFontWeight(this)))
     {
         line.Constraint = availableSize;
         _lineSize = line.Measure();
         return new Size(_lineSize.Width, _lineSize.Height * itemCount);
     }
 }
예제 #19
0
 public Rect(Size size)
 {
     this.x = this.y = 0.0;
     this.width = size.Width;
     this.height = size.Height;
 }
예제 #20
0
        public static AM.Geometry?ToGeometry(this Path path, bool isFilled)
        {
            if (path.Commands == null)
            {
                return(null);
            }

            var streamGeometry = new AM.StreamGeometry();

            using var streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.SetFillRule(path.FillType.ToSKPathFillType());

            bool endFigure  = false;
            bool haveFigure = false;

            for (int i = 0; i < path.Commands.Count; i++)
            {
                var pathCommand = path.Commands[i];
                var isLast      = i == path.Commands.Count - 1;

                switch (pathCommand)
                {
                case MoveToPathCommand moveToPathCommand:
                {
                    if (endFigure == true && haveFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == true)
                    {
                        streamGeometryContext.EndFigure(false);
                    }
                    if (isLast == true)
                    {
                        return(streamGeometry);
                    }
                    else
                    {
                        if (path.Commands[i + 1] is MoveToPathCommand)
                        {
                            return(streamGeometry);
                        }

                        if (path.Commands[i + 1] is ClosePathCommand)
                        {
                            return(streamGeometry);
                        }
                    }
                    endFigure  = true;
                    haveFigure = false;
                    var x     = moveToPathCommand.X;
                    var y     = moveToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.BeginFigure(point, isFilled);         // TODO: isFilled
                }
                break;

                case LineToPathCommand lineToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x     = lineToPathCommand.X;
                    var y     = lineToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.LineTo(point);
                }
                break;

                case ArcToPathCommand arcToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x             = arcToPathCommand.X;
                    var y             = arcToPathCommand.Y;
                    var point         = new A.Point(x, y);
                    var rx            = arcToPathCommand.Rx;
                    var ry            = arcToPathCommand.Ry;
                    var size          = new A.Size(rx, ry);
                    var rotationAngle = arcToPathCommand.XAxisRotate;
                    var isLargeArc    = arcToPathCommand.LargeArc == PathArcSize.Large;
                    var sweep         = arcToPathCommand.Sweep.ToSweepDirection();
                    streamGeometryContext.ArcTo(point, size, rotationAngle, isLargeArc, sweep);
                }
                break;

                case QuadToPathCommand quadToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0       = quadToPathCommand.X0;
                    var y0       = quadToPathCommand.Y0;
                    var x1       = quadToPathCommand.X1;
                    var y1       = quadToPathCommand.Y1;
                    var control  = new A.Point(x0, y0);
                    var endPoint = new A.Point(x1, y1);
                    streamGeometryContext.QuadraticBezierTo(control, endPoint);
                }
                break;

                case CubicToPathCommand cubicToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0     = cubicToPathCommand.X0;
                    var y0     = cubicToPathCommand.Y0;
                    var x1     = cubicToPathCommand.X1;
                    var y1     = cubicToPathCommand.Y1;
                    var x2     = cubicToPathCommand.X2;
                    var y2     = cubicToPathCommand.Y2;
                    var point1 = new A.Point(x0, y0);
                    var point2 = new A.Point(x1, y1);
                    var point3 = new A.Point(x2, y2);
                    streamGeometryContext.CubicBezierTo(point1, point2, point3);
                }
                break;

                case ClosePathCommand _:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == false)
                    {
                        return(null);
                    }
                    endFigure  = false;
                    haveFigure = false;
                    streamGeometryContext.EndFigure(true);
                }
                break;

                default:
                    break;
                }
            }

            if (endFigure)
            {
                if (haveFigure == false)
                {
                    return(null);
                }
                streamGeometryContext.EndFigure(false);
            }

            return(streamGeometry);
        }
예제 #21
0
 public void Inflate(Size size)
 {
     this.Inflate(size.Width, size.Height);
 }
예제 #22
0
        protected sealed override Size MeasureCore(Size availableSize)
        {
            this.ApplyTemplate();

            availableSize = new Size(
                Math.Max(0, availableSize.Width - this.Margin.Left - this.Margin.Right),
                Math.Max(0, availableSize.Height - this.Margin.Top - this.Margin.Bottom));

            Size size = this.MeasureOverride(availableSize);

            size = new Size(
                Math.Min(availableSize.Width, size.Width + this.Margin.Left + this.Margin.Right),
                Math.Min(availableSize.Height, size.Height + this.Margin.Top + this.Margin.Bottom));

            return size;
        }
예제 #23
0
 protected virtual Size MeasureOverride(Size constraint)
 {
     return new Size();
 }
예제 #24
0
 public void Measure(Size availableSize)
 {
     this.measureCalled = true;
     this.previousMeasureSize = availableSize;
     this.DesiredSize = this.MeasureCore(availableSize);
     this.IsMeasureValid = true;
     this.IsArrangeValid = false;
 }