-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
FlexEnums.cs
108 lines (92 loc) · 3.08 KB
/
FlexEnums.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.ComponentModel;
namespace Microsoft.Maui.Layouts
{
[TypeConverter(typeof(Converters.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,
}
public enum FlexPosition
{
Relative = Flex.Position.Relative,
Absolute = Flex.Position.Absolute,
}
[TypeConverter(typeof(Converters.FlexDirectionTypeConverter))]
public enum FlexDirection
{
Column = Flex.Direction.Column,
ColumnReverse = Flex.Direction.ColumnReverse,
Row = Flex.Direction.Row,
RowReverse = Flex.Direction.RowReverse,
}
[TypeConverter(typeof(Converters.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,
}
[TypeConverter(typeof(Converters.FlexAlignItemsTypeConverter))]
public enum FlexAlignItems
{
Stretch = Flex.AlignItems.Stretch,
Center = Flex.AlignItems.Center,
Start = Flex.AlignItems.Start,
End = Flex.AlignItems.End,
//Baseline = Flex.AlignItems.Baseline,
}
[TypeConverter(typeof(Converters.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,
}
[TypeConverter(typeof(Converters.FlexWrapTypeConverter))]
public enum FlexWrap
{
NoWrap = Flex.Wrap.NoWrap,
Wrap = Flex.Wrap.Wrap,
Reverse = Flex.Wrap.WrapReverse,
}
[TypeConverter(typeof(Converters.FlexBasisTypeConverter))]
public struct FlexBasis : IEquatable<FlexBasis>
{
bool _isLength;
bool _isRelative;
public float Length { get; }
internal bool IsAuto => !_isLength && !_isRelative;
internal bool IsRelative => _isRelative;
public static readonly FlexBasis Auto;
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)
=> new FlexBasis(length);
public bool Equals(FlexBasis other) => _isLength == other._isLength && _isRelative == other._isRelative && Length == other.Length;
public override bool Equals(object? obj) => obj is FlexBasis other && Equals(other);
public override int GetHashCode() => _isRelative.GetHashCode() ^ Length.GetHashCode();
public static bool operator ==(FlexBasis left, FlexBasis right) => left.Equals(right);
public static bool operator !=(FlexBasis left, FlexBasis right) => !(left == right);
}
}