Skip to content

Commit

Permalink
Converted CircleFrame to CircleBorder.
Browse files Browse the repository at this point in the history
  • Loading branch information
DashTheDev committed Jun 20, 2024
1 parent ab3fe5c commit 96e6097
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion PanCardView/Common/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static MauiAppBuilder UseCardsView(this MauiAppBuilder builder)
ArrowControl.Preserve();
LeftArrowControl.Preserve();
RightArrowControl.Preserve();
CircleFrame.Preserve();
CircleBorder.Preserve();
IndicatorItemView.Preserve();
IndicatorsControl.Preserve();
TabsControl.Preserve();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using System.ComponentModel;
using Microsoft.Maui.Controls.Shapes;
using PanCardView.Extensions;
using static System.Math;

namespace PanCardView.Controls
{
public class CircleFrame : Frame
public class CircleBorder : Border
{
public static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(double), typeof(CircleFrame), 10.0, propertyChanged: (bindable, oldValue, newValue) =>
public static readonly BindableProperty SizeProperty = BindableProperty.Create(nameof(Size), typeof(double), typeof(CircleBorder), 25.0, propertyChanged: (bindable, oldValue, newValue) =>
{
bindable.AsCircleFrame().OnSizeUpdated();
bindable.AsCircleBorder().OnSizeUpdated();
});

public CircleFrame()
public CircleBorder()
{
VerticalOptions = LayoutOptions.Center;
HorizontalOptions = LayoutOptions.Center;
HasShadow = false;
Padding = 0;
StrokeShape = new Ellipse();

// NOTE: Default Size was set either by bindable property default or
// applied style which doesn't call property changed. Need to manually update.
Expand All @@ -34,15 +33,6 @@ public double Size
set => SetValue(SizeProperty, value);
}

protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if(width > 0 && height > 0)
{
SetCornerRadius(Min(width, height));
}
}

protected void OnSizeUpdated()
{
var size = Size;
Expand All @@ -56,15 +46,11 @@ protected void OnSizeUpdated()
BatchBegin();
HeightRequest = size;
WidthRequest = size;
SetCornerRadius(size);
}
finally
{
BatchCommit();
}
}

private void SetCornerRadius(double size)
=> CornerRadius = (float)size / 2;
}
}
2 changes: 1 addition & 1 deletion PanCardView/Common/Controls/IndicatorItemView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PanCardView.Controls
{
public class IndicatorItemView : CircleFrame
public class IndicatorItemView : CircleBorder
{
[EditorBrowsable(EditorBrowsableState.Never)]
public new static void Preserve()
Expand Down
4 changes: 2 additions & 2 deletions PanCardView/Common/Extensions/CardViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static CoverFlowView AsCoverFlowView(this BindableObject bindable)
public static IndicatorsControl AsIndicatorsControl(this BindableObject bindable)
=> bindable as IndicatorsControl;

public static CircleFrame AsCircleFrame(this BindableObject bindable)
=> bindable as CircleFrame;
public static CircleBorder AsCircleBorder(this BindableObject bindable)
=> bindable as CircleBorder;

public static ArrowControl AsArrowControl(this BindableObject bindable)
=> bindable as ArrowControl;
Expand Down
10 changes: 5 additions & 5 deletions PanCardView/Common/Styles/DefaultIndicatorItemStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ static DefaultIndicatorItemStyles()
}

public static Style DefaultSelectedIndicatorItemStyle
=> _defaultSelectedIndicatorItemStyle ?? (_defaultSelectedIndicatorItemStyle = new Style(typeof(Frame))
=> _defaultSelectedIndicatorItemStyle ??= new Style(typeof(Frame))
{
Setters = {
new Setter { Property = VisualElement.BackgroundColorProperty, Value = Colors.White.MultiplyAlpha(.8f) }
}
});
};

public static Style DefaultUnselectedIndicatorItemStyle
=> _defaultUnselectedIndicatorItemStyle ?? (_defaultUnselectedIndicatorItemStyle = new Style(typeof(Frame))
=> _defaultUnselectedIndicatorItemStyle ??= new Style(typeof(Frame))
{
Setters = {
new Setter { Property = VisualElement.BackgroundColorProperty, Value = Colors.Transparent },
new Setter { Property = Frame.BorderColorProperty, Value = Colors.White.MultiplyAlpha(.8f) }
new Setter { Property = Border.StrokeProperty, Value = Colors.White.MultiplyAlpha(.8f) }
}
});
};
}
}

0 comments on commit 96e6097

Please sign in to comment.