|
5 | 5 | // |
6 | 6 | // Project Lead - Stuart Lodge, @slodge, [email protected] |
7 | 7 |
|
| 8 | +using System; |
8 | 9 | using System.Collections.Generic; |
9 | 10 | using UIKit; |
10 | 11 |
|
11 | 12 | namespace Cirrious.FluentLayouts.Touch |
12 | 13 | { |
13 | 14 | public static class AdvancedFluentLayoutExtensions |
14 | 15 | { |
15 | | - public static FluentLayout AtTopOf(this UIView view, UIView parentView, float margin = 0f) |
| 16 | + const float DefaultMargin = 0; |
| 17 | + const float DefaultScale = 1; |
| 18 | + |
| 19 | + public static FluentLayout AtTopOf(this UIView view, UIView parentView, nfloat? margin = null) |
16 | 20 | { |
17 | | - return view.Top().EqualTo().TopOf(parentView).Plus(margin); |
| 21 | + return view.Top().EqualTo().TopOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin)); |
18 | 22 | } |
19 | 23 |
|
20 | | - public static FluentLayout AtLeftOf(this UIView view, UIView parentView, float margin = 0f) |
| 24 | + public static FluentLayout AtLeftOf(this UIView view, UIView parentView, nfloat? margin = null) |
21 | 25 | { |
22 | | - return view.Left().EqualTo().LeftOf(parentView).Plus(margin); |
| 26 | + return view.Left().EqualTo().LeftOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin)); |
23 | 27 | } |
24 | 28 |
|
25 | | - public static FluentLayout AtRightOf(this UIView view, UIView parentView, float margin = 0f) |
| 29 | + public static FluentLayout AtRightOf(this UIView view, UIView parentView, nfloat? margin = null) |
26 | 30 | { |
27 | | - return view.Right().EqualTo().RightOf(parentView).Minus(margin); |
| 31 | + return view.Right().EqualTo().RightOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin)); |
28 | 32 | } |
29 | 33 |
|
30 | | - public static FluentLayout AtBottomOf(this UIView view, UIView parentView, float margin = 0f) |
| 34 | + public static FluentLayout AtBottomOf(this UIView view, UIView parentView, nfloat? margin = null) |
31 | 35 | { |
32 | | - return view.Bottom().EqualTo().BottomOf(parentView).Minus(margin); |
| 36 | + return view.Bottom().EqualTo().BottomOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin)); |
33 | 37 | } |
34 | 38 |
|
35 | | - public static FluentLayout Below(this UIView view, UIView previous, float margin = 0f) |
| 39 | + public static FluentLayout Below(this UIView view, UIView previous, nfloat? margin = null) |
36 | 40 | { |
37 | | - return view.Top().EqualTo().BottomOf(previous).Plus(margin); |
| 41 | + return view.Top().EqualTo().BottomOf(previous).Plus(margin.GetValueOrDefault(DefaultMargin)); |
38 | 42 | } |
39 | 43 |
|
40 | | - public static FluentLayout Above(this UIView view, UIView previous, float margin = 0f) |
| 44 | + public static FluentLayout Above(this UIView view, UIView previous, nfloat? margin = null) |
41 | 45 | { |
42 | | - return view.Bottom().EqualTo().TopOf(previous).Minus(margin); |
| 46 | + return view.Bottom().EqualTo().TopOf(previous).Minus(margin.GetValueOrDefault(DefaultMargin)); |
43 | 47 | } |
44 | 48 |
|
45 | 49 | public static FluentLayout WithSameLeft(this UIView view, UIView previous) |
@@ -77,41 +81,43 @@ public static FluentLayout WithSameBottom(this UIView view, UIView previous) |
77 | 81 | return view.Bottom().EqualTo().BottomOf(previous); |
78 | 82 | } |
79 | 83 |
|
80 | | - public static FluentLayout WithRelativeWidth(this UIView view, UIView previous, float scale = 1.0f) |
| 84 | + public static FluentLayout WithRelativeWidth(this UIView view, UIView previous, nfloat? scale = null) |
81 | 85 | { |
82 | | - return view.Width().EqualTo().WidthOf(previous).WithMultiplier(scale); |
| 86 | + return view.Width().EqualTo().WidthOf(previous).WithMultiplier(scale.GetValueOrDefault(DefaultScale)); |
83 | 87 | } |
84 | 88 |
|
85 | 89 | public static FluentLayout WithSameHeight(this UIView view, UIView previous) |
86 | 90 | { |
87 | 91 | return view.Height().EqualTo().HeightOf(previous); |
88 | 92 | } |
89 | 93 |
|
90 | | - public static FluentLayout WithRelativeHeight(this UIView view, UIView previous, float scale = 1.0f) |
| 94 | + public static FluentLayout WithRelativeHeight(this UIView view, UIView previous, nfloat? scale = null) |
91 | 95 | { |
92 | | - return view.Height().EqualTo().HeightOf(previous).WithMultiplier(scale); |
| 96 | + return view.Height().EqualTo().HeightOf(previous).WithMultiplier(scale.GetValueOrDefault(DefaultScale)); |
93 | 97 | } |
94 | 98 |
|
95 | | - public static FluentLayout ToRightOf(this UIView view, UIView previous, float margin = 0f) |
| 99 | + public static FluentLayout ToRightOf(this UIView view, UIView previous, nfloat? margin = null) |
96 | 100 | { |
97 | | - return view.Left().EqualTo().RightOf(previous).Plus(margin); |
| 101 | + return view.Left().EqualTo().RightOf(previous).Plus(margin.GetValueOrDefault(DefaultMargin)); |
98 | 102 | } |
99 | 103 |
|
100 | | - public static FluentLayout ToLeftOf(this UIView view, UIView previous, float margin = 0f) |
| 104 | + public static FluentLayout ToLeftOf(this UIView view, UIView previous, nfloat? margin = null) |
101 | 105 | { |
102 | | - return view.Right().EqualTo().LeftOf(previous).Minus(margin); |
| 106 | + return view.Right().EqualTo().LeftOf(previous).Minus(margin.GetValueOrDefault(DefaultMargin)); |
103 | 107 | } |
104 | 108 |
|
105 | | - public static IEnumerable<FluentLayout> FullWidthOf(this UIView view, UIView parent, float margin = 0f) |
| 109 | + public static IEnumerable<FluentLayout> FullWidthOf(this UIView view, UIView parent, nfloat? margin = null) |
106 | 110 | { |
107 | | - yield return view.Left().EqualTo().LeftOf(parent).Plus(margin); |
108 | | - yield return view.Right().EqualTo().RightOf(parent).Minus(margin); |
| 111 | + var marginValue = margin.GetValueOrDefault(DefaultMargin); |
| 112 | + yield return view.Left().EqualTo().LeftOf(parent).Plus(marginValue); |
| 113 | + yield return view.Right().EqualTo().RightOf(parent).Minus(marginValue); |
109 | 114 | } |
110 | 115 |
|
111 | | - public static IEnumerable<FluentLayout> FullHeightOf(this UIView view, UIView parent, float margin = 0f) |
| 116 | + public static IEnumerable<FluentLayout> FullHeightOf(this UIView view, UIView parent, nfloat? margin = null) |
112 | 117 | { |
113 | | - yield return view.Top().EqualTo().TopOf(parent).Plus(margin); |
114 | | - yield return view.Bottom().EqualTo().BottomOf(parent).Minus(margin); |
| 118 | + var marginValue = margin.GetValueOrDefault(DefaultMargin); |
| 119 | + yield return view.Top().EqualTo().TopOf(parent).Plus(marginValue); |
| 120 | + yield return view.Bottom().EqualTo().BottomOf(parent).Minus(marginValue); |
115 | 121 | } |
116 | 122 |
|
117 | 123 | public static IEnumerable<FluentLayout> VerticalStackPanelConstraints(this UIView parentView, Margins margins, |
|
0 commit comments