Permalink
Switch branches/tags
tag-test3 tag-test2 tag-test1 rui-3.0.0 release-3.4.0-rc1.3 release-3.4.0-rc1.2 release-3.4.0-rc1.1 release-3.4.0-rc1 release-3.3.0-sr1.2 release-3.3.0-sr1.1 release-3.3.0-sr1 release-3.3.0-rc0 release-3.2.0 release-3.2.0-sr1 release-3.1.0-sr3 release-3.1.0-sr2 release-3.1.0-sr1.1 release-3.1.0-sr1 release-3.1.0-rc1 release-3.0.0-sr4.1 release-3.0.0-sr4 release-3.0.0-sr3 release-3.0.0-sr2 release-3.0.0-sr1 release-3.0.0-rc2 release-3.0.0-rc1 release-2.5.1 release-2.5.1-sr4 release-2.5.1-sr3 release-2.5.1-sr2 release-2.5.1-sr1 release-2.5.0 release-2.5.0-sr5 release-2.5.0-sr4 release-2.5.0-sr3 release-2.5.0-sr2 release-2.5.0-sr1 release-2.4.99-rc1 release-2.4.0 release-2.4.0-sr6 release-2.4.0-sr5 release-2.4.0-sr4 release-2.4.0-sr3 release-2.4.0-sr2 release-2.4.0-sr1 release-2.4.0-rc2 release-2.3.5 release-2.3.4 release-2.3.4-sr6 release-2.3.4-sr5 release-2.3.4-sr4 release-2.3.4-sr3 release-2.3.4-sr2 release-2.3.4-sr1 release-2.3.3 release-2.3.3-sr2 release-2.3.3-sr1.1 release-2.3.3-sr1 release-2.3.3-hf1 release-2.3.2 release-2.3.2-hf1 release-2.3.1 release-2.3.0 release-2.3.0-hf1 release-2.2.0 release-2.2.0-hf1 beta-cycle6buildtest beta-9.99.99-rui beta-9.9.999-rui beta-9.9.99-rui beta-9.9.15.5-rui beta-9.9.9.9-rui beta-9.9.9-rui beta-9.9.8-rui beta-3.5.0-pre1.1 beta-3.5.0-pre1 beta-3.4.0-rui beta-3.4.0-pre2.2 beta-3.4.0-pre2.1 beta-3.4.0-pre2 beta-3.4.0-pre1 beta-3.3.0-pre3 beta-3.3.0-pre2 beta-3.3.0-pre1 beta-3.2.0-pre3 beta-3.2.0-pre2 beta-3.2.0-pre1.1 beta-3.2.0-pre1 beta-3.1.0-pre4.1 beta-3.1.0-pre4 beta-3.1.0-pre3 beta-3.1.0-pre2.3 beta-3.1.0-pre2.2 beta-3.1.0-pre2 beta-3.1.0-pre1.2 beta-3.1.0-pre1 beta-3.0.0-rui beta-3.0.0-pre4.4 beta-3.0.0-pre4.3 beta-3.0.0-pre4.2
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
224 lines (208 sloc) 7.37 KB
using System;
using System.Globalization;
namespace Xamarin.Forms
{
[TypeConverter(typeof(FlexJustifyTypeConverter))]
public enum FlexJustify
{
Start = Flex.Justify.Start,
Center = Flex.Justify.Center,
End = Flex.Justify.End,
SpaceBetween = Flex.Justify.SpaceBetween,
SpaceAround = Flex.Justify.SpaceAround,
SpaceEvenly = Flex.Justify.SpaceEvenly,
}
[Xaml.TypeConversion(typeof(FlexJustify))]
public class FlexJustifyTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexJustify justify))
return justify;
if (value.Equals("flex-start", StringComparison.OrdinalIgnoreCase))
return FlexJustify.Start;
if (value.Equals("flex-end", StringComparison.OrdinalIgnoreCase))
return FlexJustify.End;
if (value.Equals("space-between", StringComparison.OrdinalIgnoreCase))
return FlexJustify.SpaceBetween;
if (value.Equals("space-around", StringComparison.OrdinalIgnoreCase))
return FlexJustify.SpaceAround;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexJustify)));
}
}
public enum FlexPosition
{
Relative = Flex.Position.Relative,
Absolute = Flex.Position.Absolute,
}
[TypeConverter(typeof(FlexDirectionTypeConverter))]
public enum FlexDirection
{
Column = Flex.Direction.Column,
ColumnReverse = Flex.Direction.ColumnReverse,
Row = Flex.Direction.Row,
RowReverse = Flex.Direction.RowReverse,
}
[Xaml.TypeConversion(typeof(FlexDirection))]
public class FlexDirectionTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexDirection aligncontent))
return aligncontent;
if (value.Equals("row-reverse", StringComparison.OrdinalIgnoreCase))
return FlexDirection.RowReverse;
if (value.Equals("column-reverse", StringComparison.OrdinalIgnoreCase))
return FlexDirection.ColumnReverse;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexDirection)));
}
}
[TypeConverter(typeof(FlexAlignContentTypeConverter))]
public enum FlexAlignContent
{
Stretch = Flex.AlignContent.Stretch,
Center = Flex.AlignContent.Center,
Start = Flex.AlignContent.Start,
End = Flex.AlignContent.End,
SpaceBetween = Flex.AlignContent.SpaceBetween,
SpaceAround = Flex.AlignContent.SpaceAround,
SpaceEvenly = Flex.AlignContent.SpaceEvenly,
}
[Xaml.TypeConversion(typeof(FlexAlignContent))]
public class FlexAlignContentTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexAlignContent aligncontent))
return aligncontent;
if (value.Equals("flex-start", StringComparison.OrdinalIgnoreCase))
return FlexAlignContent.Start;
if (value.Equals("flex-end", StringComparison.OrdinalIgnoreCase))
return FlexAlignContent.End;
if (value.Equals("space-between", StringComparison.OrdinalIgnoreCase))
return FlexAlignContent.SpaceBetween;
if (value.Equals("space-around", StringComparison.OrdinalIgnoreCase))
return FlexAlignContent.SpaceAround;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexAlignContent)));
}
}
[TypeConverter(typeof(FlexAlignItemsTypeConverter))]
public enum FlexAlignItems
{
Stretch = Flex.AlignItems.Stretch,
Center = Flex.AlignItems.Center,
Start = Flex.AlignItems.Start,
End = Flex.AlignItems.End,
//Baseline = Flex.AlignItems.Baseline,
}
[Xaml.TypeConversion(typeof(FlexAlignItems))]
public class FlexAlignItemsTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexAlignItems alignitems))
return alignitems;
if (value.Equals("flex-start", StringComparison.OrdinalIgnoreCase))
return FlexAlignItems.Start;
if (value.Equals("flex-end", StringComparison.OrdinalIgnoreCase))
return FlexAlignItems.End;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexAlignItems)));
}
}
[TypeConverter(typeof(FlexAlignSelfTypeConverter))]
public enum FlexAlignSelf
{
Auto = Flex.AlignSelf.Auto,
Stretch = Flex.AlignSelf.Stretch,
Center = Flex.AlignSelf.Center,
Start = Flex.AlignSelf.Start,
End = Flex.AlignSelf.End,
//Baseline = Flex.AlignSelf.Baseline,
}
[Xaml.TypeConversion(typeof(FlexAlignSelf))]
public class FlexAlignSelfTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexAlignSelf alignself))
return alignself;
if (value.Equals("flex-start", StringComparison.OrdinalIgnoreCase))
return FlexAlignSelf.Start;
if (value.Equals("flex-end", StringComparison.OrdinalIgnoreCase))
return FlexAlignSelf.End;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexAlignSelf)));
}
}
[TypeConverter(typeof(FlexWrapTypeConverter))]
public enum FlexWrap
{
NoWrap = Flex.Wrap.NoWrap,
Wrap = Flex.Wrap.Wrap,
Reverse = Flex.Wrap.WrapReverse,
}
[Xaml.TypeConversion(typeof(FlexWrap))]
public class FlexWrapTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (Enum.TryParse(value, true, out FlexWrap wrap))
return wrap;
if (value.Equals("wrap-reverse", StringComparison.OrdinalIgnoreCase))
return FlexWrap.Reverse;
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexWrap)));
}
}
[TypeConverter(typeof(FlexBasisTypeConverter))]
public struct FlexBasis
{
bool _isLength;
bool _isRelative;
public static FlexBasis Auto = new FlexBasis();
public float Length { get; }
internal bool IsAuto => !_isLength && !_isRelative;
internal bool IsRelative => _isRelative;
public FlexBasis(float length, bool isRelative = false)
{
if (length < 0)
throw new ArgumentException("should be a positive value", nameof(length));
if (isRelative && length > 1)
throw new ArgumentException("relative length should be in [0, 1]", nameof(length));
_isLength = !isRelative;
_isRelative = isRelative;
Length = length;
}
public static implicit operator FlexBasis(float length)
{
return new FlexBasis(length);
}
[Xaml.TypeConversion(typeof(FlexBasis))]
public class FlexBasisTypeConverter : TypeConverter
{
public override object ConvertFromInvariantString(string value)
{
if (value != null) {
if (value.Equals("auto", StringComparison.OrdinalIgnoreCase))
return Auto;
value = value.Trim();
if (value.EndsWith("%", StringComparison.OrdinalIgnoreCase) && float.TryParse(value.Substring(0, value.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture, out float relflex))
return new FlexBasis(relflex/100, isRelative: true);
if (float.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out float flex))
return new FlexBasis(flex);
}
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(FlexBasis)));
}
}
}
}