From 18ab92cf3a89a7fbdd951a69c1b82a53726fc635 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 16 May 2020 22:58:13 +0200 Subject: [PATCH 1/2] Document Shape class. --- src/Avalonia.Controls/Shapes/Shape.cs | 78 ++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index 371b5d92f7..fc939d2a38 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -4,36 +4,63 @@ using Avalonia.Media; namespace Avalonia.Controls.Shapes { + /// + /// Provides a base class for shape elements, such as , and . + /// public abstract class Shape : Control { + /// + /// Defines the property. + /// public static readonly StyledProperty FillProperty = AvaloniaProperty.Register(nameof(Fill)); + /// + /// Defines the property. + /// public static readonly StyledProperty StretchProperty = AvaloniaProperty.Register(nameof(Stretch)); + /// + /// Defines the property. + /// public static readonly StyledProperty StrokeProperty = AvaloniaProperty.Register(nameof(Stroke)); + /// + /// Defines the property. + /// public static readonly StyledProperty> StrokeDashArrayProperty = AvaloniaProperty.Register>(nameof(StrokeDashArray)); + /// + /// Defines the property. + /// public static readonly StyledProperty StrokeDashOffsetProperty = AvaloniaProperty.Register(nameof(StrokeDashOffset)); + /// + /// Defines the property. + /// public static readonly StyledProperty StrokeThicknessProperty = AvaloniaProperty.Register(nameof(StrokeThickness)); + /// + /// Defines the property. + /// public static readonly StyledProperty StrokeLineCapProperty = AvaloniaProperty.Register(nameof(StrokeLineCap), PenLineCap.Flat); + /// + /// Defines the property. + /// public static readonly StyledProperty StrokeJoinProperty = AvaloniaProperty.Register(nameof(StrokeJoin), PenLineJoin.Miter); private Matrix _transform = Matrix.Identity; private Geometry _definingGeometry; private Geometry _renderedGeometry; - bool _calculateTransformOnArrange = false; + private bool _calculateTransformOnArrange; static Shape() { @@ -43,6 +70,9 @@ namespace Avalonia.Controls.Shapes StrokeThicknessProperty, StrokeLineCapProperty, StrokeJoinProperty); } + /// + /// Gets a value that represents the of the shape. + /// public Geometry DefiningGeometry { get @@ -56,12 +86,9 @@ namespace Avalonia.Controls.Shapes } } - public IBrush Fill - { - get { return GetValue(FillProperty); } - set { SetValue(FillProperty, value); } - } - + /// + /// Gets a value that represents the final rendered of the shape. + /// public Geometry RenderedGeometry { get @@ -93,42 +120,72 @@ namespace Avalonia.Controls.Shapes } } + /// + /// Gets or sets the that specifies how the shape's interior is painted. + /// + public IBrush Fill + { + get { return GetValue(FillProperty); } + set { SetValue(FillProperty, value); } + } + + /// + /// Gets or sets a enumeration value that describes how the shape fills its allocated space. + /// public Stretch Stretch { get { return GetValue(StretchProperty); } set { SetValue(StretchProperty, value); } } + /// + /// Gets or sets the that specifies how the shape's outline is painted. + /// public IBrush Stroke { get { return GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } } + /// + /// Gets or sets a collection of values that indicate the pattern of dashes and gaps that is used to outline shapes. + /// public AvaloniaList StrokeDashArray { get { return GetValue(StrokeDashArrayProperty); } set { SetValue(StrokeDashArrayProperty, value); } } + /// + /// Gets or sets a value that specifies the distance within the dash pattern where a dash begins. + /// public double StrokeDashOffset { get { return GetValue(StrokeDashOffsetProperty); } set { SetValue(StrokeDashOffsetProperty, value); } } + /// + /// Gets or sets the width of the shape outline. + /// public double StrokeThickness { get { return GetValue(StrokeThicknessProperty); } set { SetValue(StrokeThicknessProperty, value); } } + /// + /// Gets or sets a enumeration value that describes the shape at the ends of a line. + /// public PenLineCap StrokeLineCap { get { return GetValue(StrokeLineCapProperty); } set { SetValue(StrokeLineCapProperty, value); } } + /// + /// Gets or sets a enumeration value that specifies the type of join that is used at the vertices of a Shape. + /// public PenLineJoin StrokeJoin { get { return GetValue(StrokeJoinProperty); } @@ -170,8 +227,15 @@ namespace Avalonia.Controls.Shapes } } + /// + /// Creates the shape's defining geometry. + /// + /// Defining of the shape. protected abstract Geometry CreateDefiningGeometry(); + /// + /// Invalidates of this shape. + /// protected void InvalidateGeometry() { _renderedGeometry = null; From b6923f8089f85a9826927affc728535acb07c3b6 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 16 May 2020 23:13:05 +0200 Subject: [PATCH 2/2] Enable nullable annotations for Shape. --- src/Avalonia.Controls/Shapes/Shape.cs | 37 +++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Controls/Shapes/Shape.cs b/src/Avalonia.Controls/Shapes/Shape.cs index fc939d2a38..7d1525afc4 100644 --- a/src/Avalonia.Controls/Shapes/Shape.cs +++ b/src/Avalonia.Controls/Shapes/Shape.cs @@ -2,6 +2,8 @@ using System; using Avalonia.Collections; using Avalonia.Media; +#nullable enable + namespace Avalonia.Controls.Shapes { /// @@ -12,8 +14,8 @@ namespace Avalonia.Controls.Shapes /// /// Defines the property. /// - public static readonly StyledProperty FillProperty = - AvaloniaProperty.Register(nameof(Fill)); + public static readonly StyledProperty FillProperty = + AvaloniaProperty.Register(nameof(Fill)); /// /// Defines the property. @@ -24,14 +26,14 @@ namespace Avalonia.Controls.Shapes /// /// Defines the property. /// - public static readonly StyledProperty StrokeProperty = - AvaloniaProperty.Register(nameof(Stroke)); + public static readonly StyledProperty StrokeProperty = + AvaloniaProperty.Register(nameof(Stroke)); /// /// Defines the property. /// - public static readonly StyledProperty> StrokeDashArrayProperty = - AvaloniaProperty.Register>(nameof(StrokeDashArray)); + public static readonly StyledProperty?> StrokeDashArrayProperty = + AvaloniaProperty.Register?>(nameof(StrokeDashArray)); /// /// Defines the property. @@ -58,8 +60,8 @@ namespace Avalonia.Controls.Shapes AvaloniaProperty.Register(nameof(StrokeJoin), PenLineJoin.Miter); private Matrix _transform = Matrix.Identity; - private Geometry _definingGeometry; - private Geometry _renderedGeometry; + private Geometry? _definingGeometry; + private Geometry? _renderedGeometry; private bool _calculateTransformOnArrange; static Shape() @@ -73,7 +75,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets a value that represents the of the shape. /// - public Geometry DefiningGeometry + public Geometry? DefiningGeometry { get { @@ -89,7 +91,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets a value that represents the final rendered of the shape. /// - public Geometry RenderedGeometry + public Geometry? RenderedGeometry { get { @@ -123,7 +125,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets the that specifies how the shape's interior is painted. /// - public IBrush Fill + public IBrush? Fill { get { return GetValue(FillProperty); } set { SetValue(FillProperty, value); } @@ -141,7 +143,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets the that specifies how the shape's outline is painted. /// - public IBrush Stroke + public IBrush? Stroke { get { return GetValue(StrokeProperty); } set { SetValue(StrokeProperty, value); } @@ -150,7 +152,7 @@ namespace Avalonia.Controls.Shapes /// /// Gets or sets a collection of values that indicate the pattern of dashes and gaps that is used to outline shapes. /// - public AvaloniaList StrokeDashArray + public AvaloniaList? StrokeDashArray { get { return GetValue(StrokeDashArrayProperty); } set { SetValue(StrokeDashArrayProperty, value); } @@ -231,15 +233,16 @@ namespace Avalonia.Controls.Shapes /// Creates the shape's defining geometry. /// /// Defining of the shape. - protected abstract Geometry CreateDefiningGeometry(); + protected abstract Geometry? CreateDefiningGeometry(); /// - /// Invalidates of this shape. + /// Invalidates the geometry of this shape. /// protected void InvalidateGeometry() { _renderedGeometry = null; _definingGeometry = null; + InvalidateMeasure(); } @@ -385,8 +388,8 @@ namespace Avalonia.Controls.Shapes // portion changes. if (e.Property == BoundsProperty) { - var oldBounds = (Rect)e.OldValue; - var newBounds = (Rect)e.NewValue; + var oldBounds = (Rect)e.OldValue!; + var newBounds = (Rect)e.NewValue!; if (oldBounds.Size == newBounds.Size) {