-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Spec] Shapes & Paths #9178
Comments
This seems to me to reinvent the wheel by creating yet another vector graphics library. There is already a popular vector graphics markup language (svg) and corresponding .net objects (e.g. vvvv/svg). So the questions are: How is this superior to svg, and how is it better than putting an svg in an image view? If it's superior to svg, why would it take a Xamarin forms dependency rather than being available to the whole world? :) |
One way to tackle this is basing it on XGraphics. XGraphics has primitives like those above (and more). And it addresses some of the points that @charlesroddie raises:
Why not just use SVG? That's actually something I thought long and hard about with XGraphics. I ended up deciding that using XAML as the native graphics format is best since:
Instead, XGraphics supports SVG like this (which I've just been finishing up):
Anyway, feedback from the community is definitely welcome here, on what path we should go down, what features are most valued, etc. Thanks. |
Thank you, finally I don't have to use a frame corner radius that is a crutch. |
It is kinda annoying to write code using Skia or any other library when all you want is a rectangle with round corners and a border (for example), so I think this is a cool idea. Being able to add and customise basic shapes directly in XAML seems quite useful to me. |
@BretJohnson Count on it!. This Shapes concept is not a new concept, is very similar to XAML shape primitives available in UWP/WinUI/WPF/Silverlight. This Spec proposes an implementation very close to the WPF implementation for example.
Again, good question. On the other hand, having Shapes help the possibility of support SVGs in Xamarin.Forms too. @TopSkillDeveloper @ernestoyaquello Thanks for your feedback! |
I support this 100%. The first thing I noticed and felt like was missing was a proper way of creating different shapes when I started with Xamarin.Forms . This is because I was so used to the easy way of doing it in WPF. My company is using svg vector graphics for our WPF based product, and we wanted a similar way of doing it in Xamarin.Forms. This will enable it for us and will be greatly appreciated. |
@jsuarezruiz ,why there is no bush? |
Dear Microsoft, You already own Visio... Take that code and modularize it. Make it X-Platform and put in in Xamarin. Thanks for listening. |
@juepiezhongren you can see the brushes Spec here #7293 and the implementation in progress here #9220 |
@jsuarezruiz ,all apis for XF 5.0? |
cant wait to see this feature released |
Is it will have Viewbox Control which can scale child shapes like wpf? |
this is huge! is a big step forward to create complex UI/UX with the same output on iOS/Android. |
Shape class should probably be abstract And now, all of this would make more sense if we had a Canvas Layout... |
Thanks for the feedback Stephane! I agree to make Shapes an abstract class. About a Canvas layout, I thought about it. But will be similar to an AbsoluteLayout, right?. I mean, allow to position shapes with coordinates, etc. |
Drawing a |
* Added Path definition in Core (Shapes) Implemented Path in Android and iOS * Fixed Android build errors * Fixed UWP Build * Fixed WPF Build * Implemented PathRenderer on UWP * Added unit tests * Fixed namespaces conflicts in Platform projects * Changes to fix the build errors * Implemented Path Transformations in Android and iOS * Fixed Build error in WPF and UWP * Implemented Path Transformations in UWP * Fixed iOS Build error * Changes to fix the Build (Path namespace conflict) * More changes to fix the build error * Fixed Windows Build errors * Fixed Path size issue on UWP * Added Shapes_Experimental flag * Updated path sample * Updated Android ShapeRenderer size logic * Added Shape Aspect sample in Core Gallery * Added more Shapes samples * Updated UWP PathRenderer size logic * Updated droid and iOS pathRenderer size logic (same behavior in all the platforms) * Updated UWP ShapeRenderer * Implemented Path in WPF Backend * Fixed build error * Initial Clip implementation in WPF and UWP (work in progress) * Added Path implementation on macOS * Added Clip implementation in Android, iOS and macOS * Fixed broken unit tests * Notify the change of Geometry if any of the child properties changed * Added new sample clipping different views * Fixed flipped shape issue on macOS * Added support to Clip using EllipseGeometry, LineGeometry and RectangleGeometry in UWP * Changed Shape class to be abstract * Moved Shapes to Xamarin.Forms.Shapes in Android, iOS and macOS * Moved Shapes to Xamarin.Forms.Shapes namespace in Windows (UWP and WPF) * Fixed wrong property in LineGeometry * Fixed build error * Added Clip Performance sample in Core Gallery * Update Matrix.cs * Update RectangleGeometry.cs * Update Xamarin.Forms.Platform.macOS.csproj * Some duplicate classes * Update PointCollectionTests.cs * Update ImageButtonRenderer.cs * Update Xamarin.Forms.Platform.iOS.csproj * Update Xamarin.Forms.Platform.iOS.csproj * Fixed tabs error Co-authored-by: Samantha Houts <[email protected]> fixes #2452 (partially) fixes #9178
Thank you for this! |
Thanks for the fantastic work! |
Unfortunately the edits to the clipping code probably broke frames: #11031 So just a heads-up for anyone thinking about updating. |
Shapes
A Shape is a type of View that enables you to draw a shape to the screen.
But, hey, why Shapes?
Currently there are Views such as BoxView or Frame that allow us to create elements such as rectangles or ellipses but, there are many more complex shapes. Having a set of Shapes (lines, polygons, etc.) allows a greater number of possibilities when creating attractive and rich user interfaces.
Notice that in the design there are:
API
Next, the Shapes API definition.
NOTE: This API definition is based on WPF Shapes API: https://docs.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/shapes-and-basic-drawing-in-wpf-overview
Shape
To render a Shape, must set the Fill property of the Shape to the Color you want. A Shape can also have a Stroke, which is a line that is drawn around the shape's perimeter. A Stroke also requires a Color that defines its appearance, and should have a non-zero value for StrokeThickness. StrokeThickness is a property that defines the perimeter's thickness around the shape edge.
Ellipse
An Ellipse is a shape with a curved perimeter. To create a basic Ellipse, specify a WidthRequest, HeightRequest, and a Color for the Fill.
Example:
Rectangle
A Rectangle is a four-sided shape with its opposite sides being equal. To create a basic Rectangle, specify a WidthRequest, a HeightRequest, and a Fill.
You can round the corners of a Rectangle. To create rounded corners, specify a value for the RadiusX and RadiusY properties. These properties specify the x-axis and y-axis of an ellipse that defines the curve of the corners.
Example:
Polygon
A Polygon is a shape with a boundary defined by an arbitrary number of points. The boundary is created by connecting a line from one point to the next, with the last point connected to the first point. The Points property defines the collection of points that make up the boundary.
The FillRule property specifies a "rule" which the composite shape uses to determine whether a given point is part of the geometry. There are two possible values for FillRule: EvenOdd and Nonzero.
Example:
Line
A Line is simply a line drawn between two points in coordinate space. For a Line, make sure to specify values for the Stroke and StrokeThickness properties, because otherwise the Line won't render.
Example:
Polyline
A Polyline is similar to a Polygon in that the boundary of the shape is defined by a set of points, except the last point in a Polyline is not connected to the first point.
Example:
Path
A Path is the most versatile Shape because you can use it to define an arbitrary geometry. But with this versatility comes complexity. Define the geometry of a path with the Data property.
Geometry
Where Geometry provides a base class for objects that define geometric shapes.
There will be:
LineGeometry
Represents the geometry of a line.
EllipseGeometry
Represents the geometry of a circle or ellipse.
RectangleGeometry
Describes a two-dimensional rectangle.
PathGeometry
Represents a complex shape that may be composed of arcs, curves, ellipses, lines, and rectangles.
Example:
Clip Views
All views (inherited from VisualElement) have the Clip property of type
Geometry
.(In the previous sample, the header background image is clipped to achieve the diagonal effect).
The following example shows an Image without a defined clip region.
In the next example, an identical Image is created, except that it has a defined clip region.
Applying Styles
We can customize the appearance of Shapes using styles. We can create the styles using XAML or CSS.
Using XAML:
Using CSS:
Difficulty : Medium
More info
This Spec is related to #2452
The text was updated successfully, but these errors were encountered: