Skip to content

Commit

Permalink
feat: Align Panel DPs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Sep 21, 2021
1 parent 2b2429e commit 1930257
Show file tree
Hide file tree
Showing 16 changed files with 429 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ private static void HandleSizePropertyChanged(DependencyObject d, DependencyProp
}
#endregion

#if !__ANDROID__ && !__IOS__ && !UNO_REFERENCE_API //In Uno, Padding is (incorrectly) defined on Panel
#region Padding DependencyProperty

public Thickness Padding
Expand All @@ -648,7 +647,6 @@ public Thickness Padding
DependencyProperty.Register("Padding", typeof(Thickness), typeof(StarStackPanel), new PropertyMetadata(default(Thickness), InvalidateLayoutOnChanged));

#endregion
#endif

#region struct Record
private struct Record
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
using Windows.UI.Xaml;
using Uno.UI.Xaml;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace Microsoft.UI.Xaml.Controls
{
partial class LayoutPanel
{
#region BorderBrush DependencyProperty

public Brush BorderBrush
{
get => GetBorderBrushValue();
set => SetBorderBrushValue(value);
}

private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent;

[GeneratedDependencyProperty(ChangedCallback = false, Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)]
public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty();

#endregion

#region BorderThickness DependencyProperty

public Thickness BorderThickness
{
get => GetBorderThicknessValue();
set => SetBorderThicknessValue(value);
}

private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty;

[GeneratedDependencyProperty(ChangedCallback = false)]
public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty();

#endregion

#region Padding DependencyProperty

public Thickness Padding
{
get => GetPaddingValue();
set => SetPaddingValue(value);
}

private static Thickness GetPaddingDefaultValue() => Thickness.Empty;

[GeneratedDependencyProperty(ChangedCallback = false)]
public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty();

#endregion

#region CornerRadius DependencyProperty

public CornerRadius CornerRadius
{
get => GetCornerRadiusValue();
set => SetCornerRadiusValue(value);
}

private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None;

[GeneratedDependencyProperty(ChangedCallback = false)]
public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty();

#endregion

public static DependencyProperty LayoutProperty { get; } = DependencyProperty.Register(
"Layout", typeof(Layout), typeof(LayoutPanel), new FrameworkPropertyMetadata(default(Layout)));

Expand Down
50 changes: 27 additions & 23 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/LayoutPanel/LayoutPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;

namespace Microsoft.UI.Xaml.Controls
{
Expand All @@ -27,31 +28,34 @@ void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
OnLayoutChanged(args.OldValue as Layout, args.NewValue as Layout);
}
#if USE_INTERNAL_SDK
else if (dependencyProperty == s_borderBrushProperty)
{
if (var panelProtected = try_as<Microsoft.UI.Xaml.Controls.IPanelProtectedFeature_WUXCPreviewTypes>())
{
panelProtected.BorderBrushProtected(Brush>(args.NewValue()));
}
}
else if (dependencyProperty == s_borderThicknessProperty)
{
if (var panelProtected = try_as<Microsoft.UI.Xaml.Controls.IPanelProtectedFeature_WUXCPreviewTypes>())
{
panelProtected.BorderThicknessProtected((Thickness)(args.NewValue()));
}
}
else if (dependencyProperty == s_cornerRadiusProperty)
{
if (var panelProtected = try_as<Microsoft.UI.Xaml.Controls.IPanelProtectedFeature_WUXCPreviewTypes>())
{
panelProtected.CornerRadiusProtected((CornerRadius)(args.NewValue()));
}
}
#endif
else if (dependencyProperty == BorderBrushProperty)
{
var newValue = (Brush)args.NewValue;

BorderBrushInternal = newValue;
OnBorderBrushChanged((Brush)args.OldValue, newValue);
}
else if (dependencyProperty == BorderThicknessProperty)
{
var newValue = (Thickness)args.NewValue;

BorderThicknessInternal = newValue;
OnBorderThicknessChanged((Thickness)args.OldValue, newValue);
}
else if (dependencyProperty == CornerRadiusProperty)
{
var newValue = (CornerRadius)args.NewValue;

CornerRadiusInternal = newValue;
OnCornerRadiusChanged((CornerRadius)args.OldValue, newValue);
}
else if (dependencyProperty == PaddingProperty)
{
var newValue = (Thickness)args.NewValue;

PaddingInternal = newValue;
OnPaddingChanged((Thickness)args.OldValue, newValue);

InvalidateMeasure();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/Mock/Panel.net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public override IEnumerable<View> GetChildren()
=> Children.OfType<View>().ToArray<View>();

bool ICustomClippingElement.AllowClippingToLayoutSlot => false;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None;
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/Mock/Panel.netstdref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ protected virtual void OnChildrenChanged()
}

bool ICustomClippingElement.AllowClippingToLayoutSlot => false;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None;
}
}
85 changes: 85 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Grid/Grid.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Uno.UI;
using Uno.UI.Extensions;
using Uno.UI.Xaml;
using Windows.UI.Xaml.Media;

#if XAMARIN_ANDROID
using View = Android.Views.View;
Expand Down Expand Up @@ -45,6 +46,90 @@ private void OnBackgroundSizingChanged(DependencyPropertyChangedEventArgs e)
}
#endregion

#region BorderBrush DependencyProperty

public Brush BorderBrush
{
get => GetBorderBrushValue();
set => SetBorderBrushValue(value);
}

private static Brush GetBorderBrushDefaultValue() => SolidColorBrushHelper.Transparent;

[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderBrushPropertyChanged), Options = FrameworkPropertyMetadataOptions.ValueInheritsDataContext)]
public static DependencyProperty BorderBrushProperty { get; } = CreateBorderBrushProperty();

private void OnBorderBrushPropertyChanged(Brush oldValue, Brush newValue)
{
BorderBrushInternal = newValue;
OnBorderBrushChanged(oldValue, newValue);
}

#endregion

#region BorderThickness DependencyProperty

public Thickness BorderThickness
{
get => GetBorderThicknessValue();
set => SetBorderThicknessValue(value);
}

private static Thickness GetBorderThicknessDefaultValue() => Thickness.Empty;

[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnBorderThicknessPropertyChanged))]
public static DependencyProperty BorderThicknessProperty { get; } = CreateBorderThicknessProperty();

private void OnBorderThicknessPropertyChanged(Thickness oldValue, Thickness newValue)
{
BorderThicknessInternal = newValue;
OnBorderThicknessChanged(oldValue, newValue);
}

#endregion

#region Padding DependencyProperty

public Thickness Padding
{
get => GetPaddingValue();
set => SetPaddingValue(value);
}

private static Thickness GetPaddingDefaultValue() => Thickness.Empty;

[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnPaddingPropertyChanged))]
public static DependencyProperty PaddingProperty { get; } = CreatePaddingProperty();

private void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
{
PaddingInternal = newValue;
OnPaddingChanged(oldValue, newValue);
}

#endregion

#region CornerRadius DependencyProperty

public CornerRadius CornerRadius
{
get => GetCornerRadiusValue();
set => SetCornerRadiusValue(value);
}

private static CornerRadius GetCornerRadiusDefaultValue() => CornerRadius.None;

[GeneratedDependencyProperty(ChangedCallbackName = nameof(OnCornerRadiusPropertyChanged))]
public static DependencyProperty CornerRadiusProperty { get; } = CreateCornerRadiusProperty();

private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius newValue)
{
CornerRadiusInternal = newValue;
OnCornerRadiusChanged(oldValue, newValue);
}

#endregion

#region Row Property
[GeneratedDependencyProperty(DefaultValue = 0, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, ChangedCallbackName = nameof(OnGenericPropertyChanged))]
public static DependencyProperty RowProperty { get ; } = CreateRowProperty();
Expand Down
12 changes: 6 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/Panel/Panel.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ private void UpdateBorder(bool willUpdateMeasures)
this,
Background,
InternalBackgroundSizing,
BorderThickness,
BorderBrush,
CornerRadius,
Padding,
BorderThicknessInternal,
BorderBrushInternal,
CornerRadiusInternal,
PaddingInternal,
willUpdateMeasures
);
}
Expand All @@ -75,7 +75,7 @@ protected override void OnLayoutCore(bool changed, int left, int top, int right,

protected override void OnDraw(Android.Graphics.Canvas canvas)
{
AdjustCornerRadius(canvas, CornerRadius);
AdjustCornerRadius(canvas, CornerRadiusInternal);
}

protected virtual void OnChildrenChanged()
Expand Down Expand Up @@ -147,6 +147,6 @@ public IEnumerator GetEnumerator()
}

bool ICustomClippingElement.AllowClippingToLayoutSlot => true;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadius != CornerRadius.None;
bool ICustomClippingElement.ForceClippingToLayoutSlot => CornerRadiusInternal != CornerRadius.None;
}
}
Loading

0 comments on commit 1930257

Please sign in to comment.