Skip to content

Commit

Permalink
Fix ShapeView (dotnet#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot committed Aug 25, 2022
1 parent 360bfa9 commit 375c330
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
21 changes: 21 additions & 0 deletions src/Controls/src/Core/Handlers/Shapes/Path/PathHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Handlers
{
public partial class PathHandler
{
public static void MapShape(IShapeViewHandler handler, Path path)
{
handler.PlatformView?.UpdateShape(path);
}

public static void MapData(IShapeViewHandler handler, Path path)
{
handler.PlatformView?.InvalidateShape(path);
}

public static void MapRenderTransform(IShapeViewHandler handler, Path path)
{
IDrawable drawable = handler.PlatformView?.Drawable;

if (drawable == null)
return;

if (drawable is ShapeDrawable shapeDrawable)
{
Matrix? matrix = path.RenderTransform?.Value;

if (matrix != null)
{
shapeDrawable.UpdateRenderTransform(matrix.Value.ToMatrix3X2());
}
}

handler.PlatformView?.InvalidateShape(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void MapFillRule(IShapeViewHandler handler, Polygon polygon)
return;

if (drawable is ShapeDrawable shapeDrawable)
shapeDrawable.WindingMode = polygon.FillRule == FillRule.EvenOdd ? Graphics.WindingMode.EvenOdd : Graphics.WindingMode.NonZero;
shapeDrawable.UpdateWindingMode(polygon.FillRule == FillRule.EvenOdd ? WindingMode.EvenOdd : WindingMode.NonZero);

handler.PlatformView?.InvalidateShape(polygon);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void MapFillRule(IShapeViewHandler handler, Polyline polyline)
return;

if (drawable is ShapeDrawable shapeDrawable)
shapeDrawable.WindingMode = polyline.FillRule == FillRule.EvenOdd ? Graphics.WindingMode.EvenOdd : Graphics.WindingMode.NonZero;
shapeDrawable.UpdateWindingMode(polyline.FillRule == FillRule.EvenOdd ? WindingMode.EvenOdd : WindingMode.NonZero);

handler.PlatformView?.InvalidateShape(polyline);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5534,6 +5534,7 @@ Microsoft.Maui.Controls.TappedEventArgs.TappedEventArgs(object? parameter) -> vo
~static Microsoft.Maui.Controls.Handlers.LineHandler.MapY1(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Line line) -> void
~static Microsoft.Maui.Controls.Handlers.LineHandler.MapY2(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Line line) -> void
~static Microsoft.Maui.Controls.Handlers.PathHandler.MapData(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Path path) -> void
~static Microsoft.Maui.Controls.Handlers.PathHandler.MapShape(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Path path) -> void
~static Microsoft.Maui.Controls.Handlers.PathHandler.Mapper -> Microsoft.Maui.IPropertyMapper<Microsoft.Maui.Controls.Shapes.Path, Microsoft.Maui.Handlers.IShapeViewHandler>
~static Microsoft.Maui.Controls.Handlers.PathHandler.MapRenderTransform(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Path path) -> void
~static Microsoft.Maui.Controls.Handlers.PolygonHandler.MapFillRule(Microsoft.Maui.Handlers.IShapeViewHandler handler, Microsoft.Maui.Controls.Shapes.Polygon polygon) -> void
Expand Down
10 changes: 3 additions & 7 deletions src/Core/src/Handlers/ViewHandlerExtensions.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Microsoft.Maui.Graphics;
using Tizen.UIExtensions.NUI;
using NView = Tizen.NUI.BaseComponents.View;
using IMeasurable = Tizen.UIExtensions.Common.IMeasurable;

namespace Microsoft.Maui
Expand Down Expand Up @@ -60,10 +59,8 @@ internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, do
double availableWidth = (availableWidthAsInt < 0 || availableWidthAsInt == int.MaxValue) ? double.PositiveInfinity : availableWidthAsInt;
double availableHeight = (availableHeightAsInt < 0 || availableHeightAsInt == int.MaxValue) ? double.PositiveInfinity : availableHeightAsInt;

var explicitWidth = virtualView.Width;
var explicitHeight = virtualView.Height;
var hasExplicitWidth = explicitWidth >= 0;
var hasExplicitHeight = explicitHeight >= 0;
double? explicitWidth = (virtualView.Width >= 0) ? virtualView.Width : null;
double? explicitHeight = (virtualView.Height >=0) ? virtualView.Height : null;

Size measured;
if (platformView is IMeasurable platformViewMeasurable)
Expand All @@ -75,8 +72,7 @@ internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, do
measured = platformView.NaturalSize2D.ToCommon().ToDP();
}

return new Size(hasExplicitWidth ? explicitWidth : measured.Width,
hasExplicitHeight ? explicitHeight : measured.Height);
return new Size(explicitWidth ?? measured.Width, explicitHeight ?? measured.Height);
}

internal static void PlatformArrangeHandler(this IViewHandler viewHandler, Rect frame)
Expand Down
9 changes: 3 additions & 6 deletions src/Core/src/Platform/Tizen/MauiShapeView.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using Tizen.UIExtensions.NUI.GraphicsView;
using Tizen.UIExtensions.Common;
using GSize = Microsoft.Maui.Graphics.Size;
using Tizen.UIExtensions.Common;
using Tizen.UIExtensions.NUI.GraphicsView;

namespace Microsoft.Maui.Platform
{
public class MauiShapeView : SkiaGraphicsView, IMeasurable
{
protected virtual double DefaultSize => 40d;

Size IMeasurable.Measure(double availableWidth, double availableHeight)
{
return new GSize(DefaultSize, DefaultSize).ToPixel();
return new Size(0, 0);
}
}
}
1 change: 0 additions & 1 deletion src/Core/src/PublicAPI/net-tizen/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,6 @@ virtual Microsoft.Maui.Handlers.ViewHandler<TVirtualView, TPlatformView>.Measure
virtual Microsoft.Maui.Handlers.ViewHandler<TVirtualView, TPlatformView>.SetVirtualView(Microsoft.Maui.IView! view) -> void
virtual Microsoft.Maui.Handlers.WebViewHandler.MinimumSize.get -> double
virtual Microsoft.Maui.Platform.MauiImageSource.Dispose(bool disposing) -> void
virtual Microsoft.Maui.Platform.MauiShapeView.DefaultSize.get -> double
virtual Microsoft.Maui.Platform.StackNavigationManager.Connect(Microsoft.Maui.IView! navigationView) -> void
virtual Microsoft.Maui.Platform.StackNavigationManager.Disconnect() -> void
virtual Microsoft.Maui.Platform.StackNavigationManager.RequestNavigation(Microsoft.Maui.NavigationRequest! e) -> void
Expand Down

0 comments on commit 375c330

Please sign in to comment.