Browse Source

Cleanup Points collection usage, make it use IList

pull/11073/head
Max Katz 3 years ago
parent
commit
ec19a0876e
  1. 10
      src/Avalonia.Base/Media/PolyLineSegment.cs
  2. 18
      src/Avalonia.Base/Media/PolylineGeometry.cs
  3. 14
      src/Avalonia.Base/Points.cs
  4. 16
      src/Avalonia.Controls/Shapes/Polygon.cs
  5. 15
      src/Avalonia.Controls/Shapes/Polyline.cs

10
src/Avalonia.Base/Media/PolyLineSegment.cs

@ -10,8 +10,8 @@ namespace Avalonia.Media
/// <summary>
/// Defines the <see cref="Points"/> property.
/// </summary>
public static readonly StyledProperty<Points> PointsProperty
= AvaloniaProperty.Register<PolyLineSegment, Points>(nameof(Points));
public static readonly StyledProperty<IList<Point>> PointsProperty
= AvaloniaProperty.Register<PolyLineSegment, IList<Point>>(nameof(Points));
/// <summary>
/// Gets or sets the points.
@ -19,7 +19,7 @@ namespace Avalonia.Media
/// <value>
/// The points.
/// </value>
public Points Points
public IList<Point> Points
{
get => GetValue(PointsProperty);
set => SetValue(PointsProperty, value);
@ -37,9 +37,9 @@ namespace Avalonia.Media
/// Initializes a new instance of the <see cref="PolyLineSegment"/> class.
/// </summary>
/// <param name="points">The points.</param>
public PolyLineSegment(IEnumerable<Point> points) : this()
public PolyLineSegment(IEnumerable<Point> points)
{
Points.AddRange(points);
Points = new Points(points);
}
protected internal override void ApplyTo(StreamGeometryContext ctx)

18
src/Avalonia.Base/Media/PolylineGeometry.cs

@ -14,8 +14,8 @@ namespace Avalonia.Media
/// <summary>
/// Defines the <see cref="Points"/> property.
/// </summary>
public static readonly DirectProperty<PolylineGeometry, Points> PointsProperty =
AvaloniaProperty.RegisterDirect<PolylineGeometry, Points>(nameof(Points), g => g.Points, (g, f) => g.Points = f);
public static readonly DirectProperty<PolylineGeometry, IList<Point>> PointsProperty =
AvaloniaProperty.RegisterDirect<PolylineGeometry, IList<Point>>(nameof(Points), g => g.Points, (g, f) => g.Points = f);
/// <summary>
/// Defines the <see cref="IsFilled"/> property.
@ -23,13 +23,13 @@ namespace Avalonia.Media
public static readonly StyledProperty<bool> IsFilledProperty =
AvaloniaProperty.Register<PolylineGeometry, bool>(nameof(IsFilled));
private Points _points;
private IList<Point> _points;
private IDisposable? _pointsObserver;
static PolylineGeometry()
{
AffectsGeometry(IsFilledProperty);
PointsProperty.Changed.AddClassHandler<PolylineGeometry>((s, e) => s.OnPointsChanged(e.NewValue as Points));
PointsProperty.Changed.AddClassHandler<PolylineGeometry>((s, e) => s.OnPointsChanged(e.NewValue as IList<Point>));
}
/// <summary>
@ -43,9 +43,9 @@ namespace Avalonia.Media
/// <summary>
/// Initializes a new instance of the <see cref="PolylineGeometry"/> class.
/// </summary>
public PolylineGeometry(IEnumerable<Point> points, bool isFilled) : this()
public PolylineGeometry(IEnumerable<Point> points, bool isFilled)
{
Points.AddRange(points);
_points = new Points(points);
IsFilled = isFilled;
}
@ -56,7 +56,7 @@ namespace Avalonia.Media
/// The points.
/// </value>
[Content]
public Points Points
public IList<Point> Points
{
get => _points;
set => SetAndRaise(PointsProperty, ref _points, value);
@ -97,10 +97,10 @@ namespace Avalonia.Media
return geometry;
}
private void OnPointsChanged(Points? newValue)
private void OnPointsChanged(IList<Point>? newValue)
{
_pointsObserver?.Dispose();
_pointsObserver = newValue?.ForEachItem(
_pointsObserver = (newValue as IAvaloniaList<Point>)?.ForEachItem(
_ => InvalidateGeometry(),
_ => InvalidateGeometry(),
InvalidateGeometry);

14
src/Avalonia.Base/Points.cs

@ -1,6 +1,18 @@
using System.Collections.Generic;
using Avalonia.Collections;
namespace Avalonia
{
public sealed class Points : AvaloniaList<Point> { }
public sealed class Points : AvaloniaList<Point>
{
public Points()
{
}
public Points(IEnumerable<Point> points) : base(points)
{
}
}
}

16
src/Avalonia.Controls/Shapes/Polygon.cs

@ -1,21 +1,27 @@
using System.Collections.Generic;
using Avalonia.Media;
namespace Avalonia.Controls.Shapes
{
public class Polygon : Shape
{
public static readonly StyledProperty<Points?> PointsProperty =
AvaloniaProperty.Register<Polygon, Points?>("Points");
public static readonly StyledProperty<IList<Point>> PointsProperty =
AvaloniaProperty.Register<Polygon, IList<Point>>("Points");
static Polygon()
{
AffectsGeometry<Polygon>(PointsProperty);
}
public Points? Points
public Polygon()
{
get { return GetValue(PointsProperty); }
set { SetValue(PointsProperty, value); }
Points = new Points();
}
public IList<Point> Points
{
get => GetValue(PointsProperty);
set => SetValue(PointsProperty, value);
}
protected override Geometry CreateDefiningGeometry()

15
src/Avalonia.Controls/Shapes/Polyline.cs

@ -5,8 +5,8 @@ namespace Avalonia.Controls.Shapes
{
public class Polyline: Shape
{
public static readonly StyledProperty<Points?> PointsProperty =
AvaloniaProperty.Register<Polyline, Points?>("Points");
public static readonly StyledProperty<IList<Point>> PointsProperty =
AvaloniaProperty.Register<Polyline, IList<Point>>("Points");
static Polyline()
{
@ -14,10 +14,15 @@ namespace Avalonia.Controls.Shapes
AffectsGeometry<Polyline>(PointsProperty);
}
public Points? Points
public Polyline()
{
get { return GetValue(PointsProperty); }
set { SetValue(PointsProperty, value); }
Points = new Points();
}
public IList<Point> Points
{
get => GetValue(PointsProperty);
set => SetValue(PointsProperty, value);
}
protected override Geometry CreateDefiningGeometry()

Loading…
Cancel
Save