forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGRectExtensions.iOSmacOS.cs
More file actions
182 lines (158 loc) · 4.6 KB
/
Copy pathCGRectExtensions.iOSmacOS.cs
File metadata and controls
182 lines (158 loc) · 4.6 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using CoreGraphics;
using System;
using System.Drawing;
namespace Uno.UI.Extensions
{
public static class CGRectExtensions
{
public static CGRect IncrementX(this CGRect thisCGRect, nfloat delta)
{
thisCGRect.X += delta;
return thisCGRect;
}
public static CGRect IncrementY(this CGRect thisCGRect, nfloat delta)
{
thisCGRect.Y += delta;
return thisCGRect;
}
public static CGRect SetX(this CGRect thisCGRect, nfloat value)
{
thisCGRect.X = value;
return thisCGRect;
}
public static CGRect SetY(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Y = value;
return thisCGRect;
}
public static CGRect SetBottom(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Height = value - thisCGRect.Y;
return thisCGRect;
}
public static CGRect SetRight(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Width = value - thisCGRect.X;
return thisCGRect;
}
public static CGRect SetRightRespectWidth(this CGRect thisCGRect, nfloat value)
{
thisCGRect.X = value - thisCGRect.Width;
return thisCGRect;
}
public static CGRect SetHorizontalCenter(this CGRect thisCGRect, nfloat value)
{
thisCGRect.X = value - (thisCGRect.Width / 2);
return thisCGRect;
}
public static CGRect SetVerticalCenter(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Y = value - (thisCGRect.Height / 2);
return thisCGRect;
}
public static CGRect Shrink(this CGRect thisCGRect, nfloat numberOfPixels)
{
return Shrink(thisCGRect, numberOfPixels, numberOfPixels, numberOfPixels, numberOfPixels);
}
public static CGRect Shrink(this CGRect thisCGRect, nfloat left, nfloat top, nfloat right, nfloat bottom)
{
thisCGRect.X += left;
thisCGRect.Y += top;
thisCGRect.Width -= (left + right);
thisCGRect.Height -= (top + bottom);
return thisCGRect;
}
public static CGRect IncrementHeight(this CGRect thisCGRect, nfloat delta)
{
thisCGRect.Height += delta;
return thisCGRect;
}
public static CGRect IncrementWidth(this CGRect thisCGRect, nfloat delta)
{
thisCGRect.Width += delta;
return thisCGRect;
}
public static CGRect SetWidth(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Width = value;
return thisCGRect;
}
public static CGRect SetHeight(this CGRect thisCGRect, nfloat value)
{
thisCGRect.Height = value;
return thisCGRect;
}
public static CGRect Copy(this CGRect thisCGRect)
{
return new CGRect(thisCGRect.X, thisCGRect.Y, thisCGRect.Width, thisCGRect.Height);
}
public static CGRect ResetPosition(this CGRect thisCGRect)
{
return new CGRect(0, 0, thisCGRect.Width, thisCGRect.Height);
}
public static bool AreSizesDifferent(this CGRect cgRectOne, CGRect cgRectTwo)
{
return NMath.Abs(cgRectOne.Width - cgRectTwo.Width) > nfloat.Epsilon
|| NMath.Abs(cgRectOne.Height - cgRectTwo.Height) > nfloat.Epsilon;
}
/// <summary>
/// Index-based access to X or Y value.
/// </summary>
/// <param name="rect">A CGRect</param>
/// <param name="axisIndex">A coordinate axis index</param>
/// <returns>CGRect.X if <paramref name="axisIndex"/> =0, CGRect.Y if <paramref name="axisIndex"/> =1</returns>
public static nfloat GetXOrY(this CGRect rect, int axisIndex)
{
if (axisIndex == 0)
{
return rect.X;
}
if (axisIndex == 1)
{
return rect.Y;
}
throw new ArgumentOutOfRangeException(nameof(axisIndex));
}
/// <summary>
/// Index-based access to Width and Height.
/// </summary>
/// <param name="rect">A CGRect</param>
/// <param name="axisIndex">A coordinate axis index</param>
/// <returns>CGRect.Width if <paramref name="axisIndex"/> =0, CGRect.Height if <paramref name="axisIndex"/> =1</returns>
public static nfloat GetWidthOrHeight(this CGRect rect, int axisIndex)
{
if (axisIndex == 0)
{
return rect.Width;
}
if (axisIndex == 1)
{
return rect.Height;
}
throw new ArgumentOutOfRangeException(nameof(axisIndex));
}
/// <summary>
/// Index-based creation of a CGRect with modified X or Y
/// </summary>
/// <param name="rect">A CGRect</param>
/// <param name="axisIndex">A coordinate axis index</param>
/// <param name="newXYValue">The new value for X or Y</param>
/// <returns>A CGRect with modified X if <paramref name="axisIndex"/> =0, or modified Y if <paramref name="axisIndex"/> =1</returns>
public static CGRect SetXOrY(this CGRect rect, int axisIndex, nfloat newXYValue)
{
if (axisIndex == 0)
{
rect.X = newXYValue;
}
else if (axisIndex == 1)
{
rect.Y = newXYValue;
}
else
{
throw new ArgumentOutOfRangeException(nameof(axisIndex));
}
return rect;
}
}
}