Skip to content

Commit d322267

Browse files
carldebillydavidjohnoliver
authored andcommitted
feat(shapes): Finished the implementation of GeometryGroup in Wasm/SVG
1 parent fe2c502 commit d322267

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

src/Uno.UI/UI/Xaml/Media/EllipseGeometry.wasm.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable enable
2+
using System;
23
using Uno.Extensions;
34
using Uno.UI.DataBinding;
45
using Windows.UI.Xaml.Wasm;
@@ -12,25 +13,31 @@ partial class EllipseGeometry
1213
partial void InitPartials()
1314
{
1415
this.RegisterDisposablePropertyChangedCallback(OnPropertyChanged);
16+
#if DEBUG
17+
_svgElement.SetAttribute("uno-geometry-type", "EllipseGeometry");
18+
#endif
1519
}
1620

1721
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
1822
{
19-
if(property == CenterProperty)
23+
if (property == CenterProperty)
2024
{
2125
var center = Center;
2226

2327
_svgElement.SetAttribute(
2428
("cx", center.X.ToStringInvariant()),
2529
("cy", center.Y.ToStringInvariant()));
30+
_svgElement.InvalidateMeasure();
2631
}
2732
else if (property == RadiusXProperty)
2833
{
2934
_svgElement.SetAttribute("rx", RadiusX.ToStringInvariant());
35+
_svgElement.InvalidateMeasure();
3036
}
3137
else if (property == RadiusYProperty)
3238
{
3339
_svgElement.SetAttribute("ry", RadiusY.ToStringInvariant());
40+
_svgElement.InvalidateMeasure();
3441
}
3542
}
3643

src/Uno.UI/UI/Xaml/Media/GeometryGroup.wasm.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#nullable enable
22
using System;
33
using Uno.UI.DataBinding;
4+
using Windows.Foundation.Collections;
45
using Windows.UI.Xaml.Wasm;
56

67
namespace Windows.UI.Xaml.Media
78
{
89
partial class GeometryGroup
910
{
10-
private SvgElement _svgElement = new SvgElement("ellipse");
11+
private SvgElement _svgElement = new SvgElement("g");
1112

1213
partial void InitPartials()
1314
{
1415
this.RegisterDisposablePropertyChangedCallback(OnPropertyChanged);
1516

17+
Children.VectorChanged += OnGeometriesChanged;
18+
1619
_svgElement.SetAttribute("fill-rule", "evenodd");
20+
#if DEBUG
21+
_svgElement.SetAttribute("uno-geometry-type", "GeometryGroup");
22+
#endif
1723
}
1824

1925
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
@@ -30,7 +36,34 @@ private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty
3036
}
3137
else if (property == ChildrenProperty)
3238
{
33-
// TODO!!
39+
_svgElement.ClearChildren();
40+
41+
if(args.OldValue is GeometryCollection oldGeometries)
42+
{
43+
oldGeometries.VectorChanged -= OnGeometriesChanged;
44+
}
45+
46+
if(args.NewValue is GeometryCollection newGeometries)
47+
{
48+
newGeometries.VectorChanged += OnGeometriesChanged;
49+
50+
newGeometries.SetParent(this);
51+
52+
foreach (var child in Children)
53+
{
54+
_svgElement.AddChild(child.GetSvgElement());
55+
}
56+
}
57+
}
58+
}
59+
60+
private void OnGeometriesChanged(IObservableVector<Geometry> sender, IVectorChangedEventArgs @event)
61+
{
62+
_svgElement.ClearChildren();
63+
64+
foreach (var child in Children)
65+
{
66+
_svgElement.AddChild(child.GetSvgElement());
3467
}
3568
}
3669

src/Uno.UI/UI/Xaml/Media/LineGeometry.wasm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ partial class LineGeometry
1212
partial void InitPartials()
1313
{
1414
this.RegisterDisposablePropertyChangedCallback(OnPropertyChanged);
15+
#if DEBUG
16+
_svgElement.SetAttribute("uno-geometry-type", "LineGeometry");
17+
#endif
1518
}
1619

17-
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
20+
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)
1821
{
1922
if (property == StartPointProperty)
2023
{

src/Uno.UI/UI/Xaml/Media/PathGeometry.wasm.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ partial void InitPartials()
1818
this.RegisterDisposablePropertyChangedCallback(OnPropertyChanged);
1919

2020
_svgElement.SetAttribute("fill-rule", "evenodd");
21+
#if DEBUG
22+
_svgElement.SetAttribute("uno-geometry-type", "PathGeometry");
23+
#endif
2124
}
2225

2326
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)

src/Uno.UI/UI/Xaml/Media/RectangleGeometry.wasm.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ partial class RectangleGeometry
1212
partial void InitPartials()
1313
{
1414
this.RegisterDisposablePropertyChangedCallback(OnPropertyChanged);
15+
#if DEBUG
16+
_svgElement.SetAttribute("uno-geometry-type", "RectangleGeometry");
17+
#endif
1518
}
1619

1720
private void OnPropertyChanged(ManagedWeakReference instance, DependencyProperty property, DependencyPropertyChangedEventArgs args)

0 commit comments

Comments
 (0)