Skip to content

Commit

Permalink
Change IDrawable.Children type
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Dec 1, 2024
1 parent ef1b17a commit 4c978ef
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/LiveChartsCore/Drawing/IDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Painting;

namespace LiveChartsCore.Drawing;
Expand Down Expand Up @@ -148,7 +149,7 @@ public interface IDrawable<TDrawingContext> : IDrawable
/// <summary>
/// Gers or sets the children.
/// </summary>
IDrawable<TDrawingContext>[] Children { get; set; }
IEnumerable<IDrawable<TDrawingContext>> Children { get; set; }

/// <summary>
/// Draws the instance in the user interface with for the specified context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand All @@ -31,7 +31,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class ArcGeometry : CoreArcGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand All @@ -33,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class BoxGeometry : CoreBoxGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand All @@ -33,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class CandlestickGeometry : CoreCandlestickGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -32,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class CircleGeometry : CoreSizedGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -30,7 +31,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class DoughnutGeometry : CoreDoughnutGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public LabelGeometry()
}

/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand All @@ -31,7 +31,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class LineGeometry : CoreLineGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand All @@ -30,7 +30,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class NeedleGeometry : CoreNeedleGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -32,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class OvalGeometry : CoreSizedGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Measure;
using SkiaSharp;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class PopUpGeometry : CoreSizedGeometry, ISkiaGeometry
public PopUpPlacement Placement { get; set; } = PopUpPlacement.Bottom;

/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -32,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class RectangleGeometry : CoreSizedGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -32,7 +33,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public class RoundedRectangleGeometry : CoreRoundedRectangleGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="IDrawable{TDrawingContext}.Draw(TDrawingContext)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.Collections.Generic;
using LiveChartsCore.Drawing;
using SkiaSharp;

Expand All @@ -29,7 +30,7 @@ namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
public abstract class SizedGeometry : CoreSizedGeometry, ISkiaGeometry
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <inheritdoc cref="ISkiaGeometry.OnDraw(SkiaSharpDrawingContext, SKPaint)" />
public void Draw(SkiaSharpDrawingContext ctx) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// The MIT License(MIT)
//
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using LiveChartsCore.Drawing;
using LiveChartsCore.Drawing.Layouts;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;

/// <inheritdoc cref="CoreStackLayout{TBackgroundGeometry, TDrawingContext}"/>
public class StackLayout : CoreStackLayout<RectangleGeometry, SkiaSharpDrawingContext>
{ }

/// <inheritdoc cref="CoreStackLayout{TBackgroundGeometry, TDrawingContext}"/>
public class StackLayout<TBackgroundGeometry>
: CoreStackLayout<TBackgroundGeometry, SkiaSharpDrawingContext>
where TBackgroundGeometry : CoreSizedGeometry, IDrawable<SkiaSharpDrawingContext>, new()
{
/// <summary>
/// Initializes a new instance of the <see cref="StackLayout{TBackgroundGeometry}"/> class.
/// </summary>
public StackLayout()
{ }

/// <summary>
/// Initializes a new instance of the <see cref="StackLayout{TBackgroundGeometry}"/> class,
/// using the specified geometry as background.
/// </summary>
/// <param name="backgroundGeometry"></param>
public StackLayout(TBackgroundGeometry backgroundGeometry)
: base(backgroundGeometry)
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// The MIT License(MIT)
//
// Copyright(c) 2021 Alberto Rodriguez Orozco & LiveCharts Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using LiveChartsCore.Drawing;
using LiveChartsCore.Drawing.Layouts;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;

/// <inheritdoc cref="CoreTableLayout{TBackgroundGeometry, TDrawingContext}"/>
public class TableLayout : CoreTableLayout<RectangleGeometry, SkiaSharpDrawingContext>
{
/// <summary>
/// Initializes a new instance of the <see cref="TableLayout"/> class.
/// </summary>
public TableLayout()
{ }
}

/// <inheritdoc cref="CoreTableLayout{TBackgroundGeometry, TDrawingContext}"/>
public class TableLayout<TBackgroundGeometry> : CoreTableLayout<TBackgroundGeometry, SkiaSharpDrawingContext>
where TBackgroundGeometry : CoreSizedGeometry, IDrawable<SkiaSharpDrawingContext>, new()
{
/// <summary>
/// Initializes a new instance of the <see cref="TableLayout{TBackgroundGeometry}"/> class.
/// </summary>
public TableLayout()
{ }

/// <summary>
/// Initializes a new instance of the <see cref="TableLayout{TBackgroundGeometry}"/> class,
/// </summary>
/// <param name="backgroundGeometry">The background geometry.</param>
public TableLayout(TBackgroundGeometry backgroundGeometry)
: base(backgroundGeometry)
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class VectorGeometry<TSegment> : CoreVectorGeometry<TSegment>, I
where TSegment : Segment
{
/// <inheritdoc cref="IDrawable{TDrawingContext}.Children" />
public IDrawable<SkiaSharpDrawingContext>[] Children { get; set; } = [];
public IEnumerable<IDrawable<SkiaSharpDrawingContext>> Children { get; set; } = [];

/// <summary>
/// Called when the area begins the draw.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,8 @@ public override void Draw(IDrawable drawable, float opacity)
else DrawByPaint(element.Fill, element, opacity);
}

if (element.Children is not null && element.Children.Length > 0)
foreach (var child in element.Children)
Draw(child, opacity * child.Opacity);
foreach (var child in element.Children)
Draw(child, opacity * child.Opacity);

if (element.HasTransform) Canvas.Restore();
}
Expand Down

0 comments on commit 4c978ef

Please sign in to comment.