Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Shapes (Path) #9264

Merged
merged 59 commits into from Jun 9, 2020
Merged

[Enhancement] Shapes (Path) #9264

merged 59 commits into from Jun 9, 2020

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Jan 20, 2020

Description of Change

Shapes support is added:

  • Path

This PR is a continuation of #9218

Issues Resolved

fixes (partially) #2452
fixes #9178

API Changes

Added:

public class Path : Shape
{
    public Geometry Data {get; set; }
}

Segment:

  • ArcSegment
  • BezierSegment
  • LineSegment
  • PolylineSegment
  • PolyQuadraticBezierSegment
  • QuadraticBezierSegment
  • PathSegment

Geometry:

  • GeometryGroup
  • EllipseGeometry
  • PathGeometry
  • RectangleGeometry

Path Transformations:

  • TransformGroup
  • RotateTransform
  • ScaleTransform
  • SkewTransform
  • TranslateTransform

Platforms Affected

  • Core/XAML (all platforms)
  • iOS
  • Android
  • macOS
  • UWP
  • WPF

Behavioral/Visual Changes

None

Screenshots

path-ios

path-droid

Path Transformations Playground:
path-transformations

path-wpf

clip-views

(Clip Views)

Testing Procedure

Launch Core Gallery and navigate to the new Shapes Gallery.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

Copy link
Member

@samhouts samhouts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Need to fix namespaces to Xamarin.Forms.Shapes
  2. I'm not sure how else we would implement the Clip, but I do know that we try to avoid overriding Draw and its platform equivalents because it can cause performance degradation and potentially wipe out any custom effects that customers may have implemented.

Otherwise, looks great!

Xamarin.Forms.Core/LineGeometry.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/LineGeometry.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Path.cs Outdated Show resolved Hide resolved
Xamarin.Forms.Core/Shape.cs Outdated Show resolved Hide resolved
@@ -219,6 +220,13 @@ protected override void OnLayout(bool changed, int left, int top, int right, int
_hasLayoutOccurred = true;
}

public override void Draw(Canvas canvas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a measure for how this is going to affect performance? (same question for all new override Draw instances)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new sample in Core Gallery.
clip-performance
The sample load hundreds of images first and then the same images using EllipseGeometry to Clip it.
The results from iOS are the following (Debug Mode):

  • 100 images: 18.82ms slower using Clip.
  • 1000 images: 212.87ms slower using Clip.

On Android, the differences are lower (practically same times). I will take more measurements in addition to sharing data from other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think about Custom Effects too, it can have an impact.

Copy link
Member

@StephaneDelcroix StephaneDelcroix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is massive. I'd like a plan to have both Shape and Geometries APIs a bit more in-line

@@ -0,0 +1,140 @@
namespace Xamarin.Forms.Shapes
{
public sealed class CompositeTransform : Transform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we reuse the Transform we already have, that's also hardware accelerated in some cases ?


void OnTransformPropertyChanged()
{
TransformGroup xformGroup = new TransformGroup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a pre-computed MatrixTransform ?

BindableProperty.Create(nameof(RadiusX), typeof(double), typeof(EllipseGeometry), 0.0);

public static readonly BindableProperty RadiusYProperty =
BindableProperty.Create(nameof(RadiusY), typeof(double), typeof(EllipseGeometry), 0.0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the Geometry API over the Shape ones. can't we unify ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can review and unify. Right now the Spec is based on the WPF API (allow porting code, etc). For this reason, Line has X1, X2, Y1, Y2 properties: https://docs.microsoft.com/en-us/dotnet/api/system.windows.shapes.line?view=netcore-3.1 while LineGeometry has two points: https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.linegeometry?view=netcore-3.1
In this case, personally I like more to have the two points.

public static readonly BindableProperty EndPointProperty =
BindableProperty.Create(nameof(EndPoint), typeof(Point), typeof(LineGeometry), new Point());

public Point StartPoint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's even nicer than X!,X2

@samhouts samhouts merged commit 9a9f71d into 4.7.0 Jun 9, 2020
4.7.0 automation moved this from In Review to Done Jun 9, 2020
Sprint 171 automation moved this from Ready for Review (PRs) to Done Jun 9, 2020
@samhouts samhouts deleted the path branch June 9, 2020 14:14
@samhouts samhouts added this to the 4.7.0 milestone Jun 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
4.7.0
  
Done
Sprint 170
  
Continued in next sprint
Sprint 171
  
Done
Development

Successfully merging this pull request may close these issues.

[Spec] Shapes & Paths Xamarin.Forms Drawing Spec
4 participants