Skip to content

Commit

Permalink
Remove IBoxView (#2619)
Browse files Browse the repository at this point in the history
* Remove IBoxView

* Fix device tests

Co-authored-by: Rui Marinho <me@ruimarinho.net>
  • Loading branch information
mattleibow and rmarinho authored Sep 22, 2021
1 parent 15ba091 commit 7cac05a
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@
x:Class="Maui.Controls.Sample.Pages.BoxViewPage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="BoxView">
<views:BasePage.Content>
<VerticalStackLayout
Margin="12">
<ScrollView>
<VerticalStackLayout Padding="12" Spacing="6">

<Label
Text="Default"
Style="{StaticResource Headline}"/>
<BoxView
BackgroundColor="CornflowerBlue"
<BoxView
BackgroundColor="CornflowerBlue"
WidthRequest="160"
HeightRequest="160"
VerticalOptions="Center"
VerticalOptions="Center"
HorizontalOptions="Center" />

<Label
Text="Using Color"
Style="{StaticResource Headline}"/>
<BoxView
Color="Purple"
<BoxView
Color="Purple"
WidthRequest="160"
HeightRequest="160"
VerticalOptions="Center"
VerticalOptions="Center"
HorizontalOptions="Center" />

<Label
Text="Using CornerRadius"
Style="{StaticResource Headline}"/>
<BoxView
Color="LightGreen"
<BoxView
Color="LightGreen"
CornerRadius="10"
WidthRequest="160"
HeightRequest="160"
VerticalOptions="Center"
VerticalOptions="Center"
HorizontalOptions="Center" />

<Label
Text="Using Complex CornerRadius"
Style="{StaticResource Headline}"/>
<BoxView
Color="Orange"
CornerRadius="10, 0, 5, 20"
WidthRequest="160"
HeightRequest="160"
VerticalOptions="Center"
HorizontalOptions="Center" />

</VerticalStackLayout>
</views:BasePage.Content>
</ScrollView>
</views:BasePage>
148 changes: 76 additions & 72 deletions src/Controls/samples/Controls.Sample/Pages/Controls/ShapesPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,80 @@
x:Class="Maui.Controls.Sample.Pages.ShapesPage"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="Shapes">
<views:BasePage.Content>
<ScrollView>
<VerticalStackLayout
Margin="12">
<Label
Text="Ellipse"
Style="{StaticResource Headline}" />
<Ellipse
Fill="DarkBlue"
Stroke="Red"
StrokeThickness="4"
WidthRequest="150"
HeightRequest="50"
HorizontalOptions="Start" />
<Label
Text="Rectangle"
Style="{StaticResource Headline}" />
<Rectangle
Fill="DarkBlue"
Stroke="Red"
StrokeThickness="4"
StrokeDashArray="1,1"
StrokeDashOffset="6"
WidthRequest="150"
HeightRequest="50"
HorizontalOptions="Start" />
<Label
Text="Line"
Style="{StaticResource Headline}" />
<Line
X1="0"
Y1="20"
X2="300"
Y2="20"
StrokeLineCap="Round"
Stroke="Red"
StrokeThickness="12"
WidthRequest="300"
HeightRequest="20" />
<Label
Text="Polyline"
Style="{StaticResource Headline}" />
<Polyline
Points="20 20,250 50,20 120"
Stroke="DarkBlue"
StrokeThickness="20"
StrokeLineJoin="Round"
WidthRequest="250"
HeightRequest="250" />
<Label
Text="Polygon"
Style="{StaticResource Headline}" />
<Polygon
Points="0 48, 0 144, 96 150, 100 0, 192 0, 192 96, 50 96, 48 192, 150 200 144 48"
Fill="Blue"
Stroke="Red"
StrokeThickness="3"
WidthRequest="250"
HeightRequest="250" />
<Label
Text="Path"
Style="{StaticResource Headline}" />
<Path
Data="M 10,100 L 100,100 100,50Z"
Stroke="Black"
Aspect="Uniform"
HorizontalOptions="Start"
WidthRequest="150"
HeightRequest="150" />
</VerticalStackLayout>
</ScrollView>
</views:BasePage.Content>
<ScrollView>
<VerticalStackLayout Padding="12" Spacing="6">

<Label
Text="Ellipse"
Style="{StaticResource Headline}" />
<Ellipse
Fill="DarkBlue"
Stroke="Red"
StrokeThickness="4"
WidthRequest="150"
HeightRequest="50"
HorizontalOptions="Start" />

<Label
Text="Rectangle"
Style="{StaticResource Headline}" />
<Rectangle
Fill="DarkBlue"
Stroke="Red"
StrokeThickness="4"
StrokeDashArray="1,1"
StrokeDashOffset="6"
WidthRequest="150"
HeightRequest="50"
HorizontalOptions="Start" />

<Label
Text="Line"
Style="{StaticResource Headline}" />
<Line
X1="0"
Y1="20"
X2="300"
Y2="20"
StrokeLineCap="Round"
Stroke="Red"
StrokeThickness="12"
WidthRequest="300"
HeightRequest="20" />

<Label
Text="Polyline"
Style="{StaticResource Headline}" />
<Polyline
Points="20 20,250 50,20 120"
Stroke="DarkBlue"
StrokeThickness="20"
StrokeLineJoin="Round"
WidthRequest="250"
HeightRequest="250" />

<Label
Text="Polygon"
Style="{StaticResource Headline}" />
<Polygon
Points="0 48, 0 144, 96 150, 100 0, 192 0, 192 96, 50 96, 48 192, 150 200 144 48"
Fill="Blue"
Stroke="Red"
StrokeThickness="3"
WidthRequest="250"
HeightRequest="250" />

<Label
Text="Path"
Style="{StaticResource Headline}" />
<Path
Data="M 10,100 L 100,100 100,50Z"
Stroke="Black"
Aspect="Uniform"
HorizontalOptions="Start"
WidthRequest="150"
HeightRequest="150" />

</VerticalStackLayout>
</ScrollView>
</views:BasePage>
47 changes: 45 additions & 2 deletions src/Controls/src/Core/HandlerImpl/BoxView.Impl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
namespace Microsoft.Maui.Controls
#nullable enable
using System.Runtime.CompilerServices;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls
{
public partial class BoxView : IBoxView
public partial class BoxView : IShapeView, IShape
{
protected override void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
base.OnPropertyChanged(propertyName);

if (propertyName == ColorProperty.PropertyName ||
propertyName == CornerRadiusProperty.PropertyName)
Handler?.UpdateValue(nameof(IShapeView.Shape));
}

IShape? IShapeView.Shape => this;

PathAspect IShapeView.Aspect => PathAspect.None;

Paint? IShapeView.Fill => Color?.AsPaint() ?? ((IView)this).Background;

Paint? IShapeView.Stroke => null;

double IShapeView.StrokeThickness => 0;

LineCap IShapeView.StrokeLineCap => LineCap.Butt;

LineJoin IShapeView.StrokeLineJoin => LineJoin.Miter;

float[]? IShapeView.StrokeDashPattern => null;

float IShapeView.StrokeMiterLimit => 0;

PathF IShape.PathForBounds(Rectangle bounds)
{
var path = new PathF();

path.AppendRoundedRectangle(
bounds,
(float)CornerRadius.TopLeft,
(float)CornerRadius.TopRight,
(float)CornerRadius.BottomLeft,
(float)CornerRadius.BottomRight);

return path;
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static partial class AppHostBuilderExtensions
{ typeof(Shell), typeof(ShellHandler) },
#endif
{ typeof(ActivityIndicator), typeof(ActivityIndicatorHandler) },
{ typeof(BoxView), typeof(BoxViewHandler) },
{ typeof(BoxView), typeof(ShapeViewHandler) },
{ typeof(Button), typeof(ButtonHandler) },
{ typeof(CheckBox), typeof(CheckBoxHandler) },
{ typeof(DatePicker), typeof(DatePickerHandler) },
Expand Down
20 changes: 0 additions & 20 deletions src/Core/src/Core/IBoxView.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Microsoft.Maui.Graphics
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui
{
/// <summary>
/// Represents a View that enables you to draw a shape to the screen.
Expand Down
69 changes: 0 additions & 69 deletions src/Core/src/Graphics/BoxViewDrawable.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Core/src/Graphics/ShapeDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Draw(ICanvas canvas, RectangleF dirtyRect)

void DrawStrokePath(ICanvas canvas, RectangleF dirtyRect, PathF path)
{
if (ShapeView == null || ShapeView.Shape == null)
if (ShapeView == null || ShapeView.Shape == null || ShapeView.StrokeThickness <= 0 || ShapeView.Stroke == null)
return;

canvas.SaveState();
Expand Down
Loading

0 comments on commit 7cac05a

Please sign in to comment.