[C] unify Padding into IPaddingElement (#1276)

This commit is contained in:
Stephane Delcroix 2017-11-15 14:53:02 +01:00 коммит произвёл GitHub
Родитель b3a0e1f14f
Коммит 20ef50d1d3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 105 добавлений и 20 удалений

Просмотреть файл

@ -5,7 +5,7 @@ namespace Xamarin.Forms
{
[ContentProperty("Content")]
[RenderWith(typeof(_FrameRenderer))]
public class Frame : ContentView, IElementConfiguration<Frame>
public class Frame : ContentView, IElementConfiguration<Frame>, IPaddingElement
{
public static readonly BindableProperty OutlineColorProperty = BindableProperty.Create("OutlineColor", typeof(Color), typeof(Frame), Color.Default);
@ -21,7 +21,7 @@ namespace Xamarin.Forms
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Frame>>(() => new PlatformConfigurationRegistry<Frame>(this));
}
internal override Thickness CreateDefaultPadding()
Thickness IPaddingElement.PaddingDefaultValueCreator()
{
return 20d;
}

Просмотреть файл

@ -0,0 +1,12 @@
namespace Xamarin.Forms
{
interface IPaddingElement
{
//note to implementor: implement this property publicly
Thickness Padding { get; }
//note to implementor: but implement this method explicitly
void OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue);
Thickness PaddingDefaultValueCreator();
}
}

Просмотреть файл

@ -50,16 +50,11 @@ namespace Xamarin.Forms
}
}
public abstract class Layout : View, ILayout, ILayoutController
public abstract class Layout : View, ILayout, ILayoutController, IPaddingElement
{
public static readonly BindableProperty IsClippedToBoundsProperty = BindableProperty.Create("IsClippedToBounds", typeof(bool), typeof(Layout), false);
public static readonly BindableProperty PaddingProperty = BindableProperty.Create("Padding", typeof(Thickness), typeof(Layout), default(Thickness),
propertyChanged: (bindable, old, newValue) =>
{
var layout = (Layout)bindable;
layout.UpdateChildrenLayout();
}, defaultValueCreator: (bindable) => ((Layout)bindable).CreateDefaultPadding());
public static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
static IList<KeyValuePair<Layout, int>> s_resolutionList = new List<KeyValuePair<Layout, int>>();
static bool s_relayoutInProgress;
@ -87,15 +82,20 @@ namespace Xamarin.Forms
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
get { return (Thickness)GetValue(PaddingElement.PaddingProperty); }
set { SetValue(PaddingElement.PaddingProperty, value); }
}
internal virtual Thickness CreateDefaultPadding()
Thickness IPaddingElement.PaddingDefaultValueCreator()
{
return default(Thickness);
}
void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
{
UpdateChildrenLayout();
}
internal ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
internal override ReadOnlyCollection<Element> LogicalChildrenInternal

Просмотреть файл

@ -0,0 +1,65 @@
namespace Xamarin.Forms
{
static class PaddingElement
{
public static readonly BindableProperty PaddingProperty =
BindableProperty.Create(nameof(IPaddingElement.Padding), typeof(Thickness), typeof(IPaddingElement), default(Thickness),
propertyChanged: OnPaddingPropertyChanged,
defaultValueCreator: PaddingDefaultValueCreator);
static void OnPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
((IPaddingElement)bindable).OnPaddingPropertyChanged((Thickness)oldValue, (Thickness)newValue);
}
static object PaddingDefaultValueCreator(BindableObject bindable)
{
return ((IPaddingElement)bindable).PaddingDefaultValueCreator();
}
public static readonly BindableProperty PaddingLeftProperty =
BindableProperty.Create("PaddingLeft", typeof(double), typeof(IPaddingElement), default(double),
propertyChanged: OnPaddingLeftChanged);
static void OnPaddingLeftChanged(BindableObject bindable, object oldValue, object newValue)
{
var padding = (Thickness)bindable.GetValue(PaddingProperty);
padding.Left = (double)newValue;
bindable.SetValue(PaddingProperty, padding);
}
public static readonly BindableProperty PaddingTopProperty =
BindableProperty.Create("PaddingTop", typeof(double), typeof(IPaddingElement), default(double),
propertyChanged: OnPaddingTopChanged);
static void OnPaddingTopChanged(BindableObject bindable, object oldValue, object newValue)
{
var padding = (Thickness)bindable.GetValue(PaddingProperty);
padding.Top = (double)newValue;
bindable.SetValue(PaddingProperty, padding);
}
public static readonly BindableProperty PaddingRightProperty =
BindableProperty.Create("PaddingRight", typeof(double), typeof(IPaddingElement), default(double),
propertyChanged: OnPaddingRightChanged);
static void OnPaddingRightChanged(BindableObject bindable, object oldValue, object newValue)
{
var padding = (Thickness)bindable.GetValue(PaddingProperty);
padding.Right = (double)newValue;
bindable.SetValue(PaddingProperty, padding);
}
public static readonly BindableProperty PaddingBottomProperty =
BindableProperty.Create("PaddingBottom", typeof(double), typeof(IPaddingElement), default(double),
propertyChanged: OnPaddingBottomChanged);
static void OnPaddingBottomChanged(BindableObject bindable, object oldValue, object newValue)
{
var padding = (Thickness)bindable.GetValue(PaddingProperty);
padding.Bottom = (double)newValue;
bindable.SetValue(PaddingProperty, padding);
}
}
}

Просмотреть файл

@ -12,7 +12,7 @@ using Xamarin.Forms.Platform;
namespace Xamarin.Forms
{
[RenderWith(typeof(_PageRenderer))]
public class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>
public class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement
{
public const string BusySetSignalName = "Xamarin.BusySet";
@ -26,11 +26,7 @@ namespace Xamarin.Forms
public static readonly BindableProperty IsBusyProperty = BindableProperty.Create("IsBusy", typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged());
public static readonly BindableProperty PaddingProperty = BindableProperty.Create("Padding", typeof(Thickness), typeof(Page), default(Thickness), propertyChanged: (bindable, old, newValue) =>
{
var layout = (Page)bindable;
layout.UpdateChildrenLayout();
});
public static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty;
public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(Page), null);
@ -76,8 +72,18 @@ namespace Xamarin.Forms
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
get { return (Thickness)GetValue(PaddingElement.PaddingProperty); }
set { SetValue(PaddingElement.PaddingProperty, value); }
}
Thickness IPaddingElement.PaddingDefaultValueCreator()
{
return default(Thickness);
}
void IPaddingElement.OnPaddingPropertyChanged(Thickness oldValue, Thickness newValue)
{
UpdateChildrenLayout();
}
public string Title

Просмотреть файл

@ -476,6 +476,8 @@
<Compile Include="ReferenceTypeConverter.cs" />
<Compile Include="ITextAlignmentElement.cs" />
<Compile Include="TextAlignmentElement.cs" />
<Compile Include="PaddingElement.cs" />
<Compile Include="IPaddingElement.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>