motion-kit 0.0.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +839 -0
- data/lib/motion-kit-cocoa/cocoa_util.rb +59 -0
- data/lib/motion-kit-cocoa/constraints/constraint.rb +765 -0
- data/lib/motion-kit-cocoa/constraints/constraint_placeholder.rb +22 -0
- data/lib/motion-kit-cocoa/constraints/constraints_layout.rb +536 -0
- data/lib/motion-kit-cocoa/constraints/constraints_target.rb +52 -0
- data/lib/motion-kit-cocoa/layouts/cagradientlayer_layout.rb +13 -0
- data/lib/motion-kit-cocoa/layouts/calayer_layout.rb +27 -0
- data/lib/motion-kit-cocoa/layouts/sugarcube_compat.rb +38 -0
- data/lib/motion-kit-ios/dummy.rb +93 -0
- data/lib/motion-kit-ios/ios_util.rb +20 -0
- data/lib/motion-kit-ios/layouts/constraints_layout.rb +22 -0
- data/lib/motion-kit-ios/layouts/layout_device.rb +32 -0
- data/lib/motion-kit-ios/layouts/layout_orientation.rb +47 -0
- data/lib/motion-kit-ios/layouts/uibutton_layout.rb +52 -0
- data/lib/motion-kit-ios/layouts/uiview_layout.rb +45 -0
- data/lib/motion-kit-ios/layouts/uiview_layout_autoresizing.rb +75 -0
- data/lib/motion-kit-ios/layouts/uiview_layout_constraints.rb +36 -0
- data/lib/motion-kit-ios/layouts/uiview_layout_frame.rb +307 -0
- data/lib/motion-kit-ios/layouts/uiview_layout_gradient.rb +20 -0
- data/lib/motion-kit-osx/dummy.rb +89 -0
- data/lib/motion-kit-osx/layouts/constraints_layout.rb +42 -0
- data/lib/motion-kit-osx/layouts/nsmenu_extensions.rb +186 -0
- data/lib/motion-kit-osx/layouts/nsmenu_layout.rb +109 -0
- data/lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb +45 -0
- data/lib/motion-kit-osx/layouts/nstablecolumn_layout.rb +12 -0
- data/lib/motion-kit-osx/layouts/nstableview_layout.rb +20 -0
- data/lib/motion-kit-osx/layouts/nsview_layout.rb +47 -0
- data/lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb +75 -0
- data/lib/motion-kit-osx/layouts/nsview_layout_constraints.rb +34 -0
- data/lib/motion-kit-osx/layouts/nsview_layout_frame.rb +375 -0
- data/lib/motion-kit-osx/layouts/nswindow_frame.rb +14 -0
- data/lib/motion-kit-osx/layouts/nswindow_layout.rb +77 -0
- data/lib/motion-kit-osx/osx_util.rb +16 -0
- data/lib/motion-kit.rb +33 -0
- data/lib/motion-kit/calculate.rb +263 -0
- data/lib/motion-kit/layouts/base_layout.rb +299 -0
- data/lib/motion-kit/layouts/base_layout_class_methods.rb +43 -0
- data/lib/motion-kit/layouts/parent.rb +68 -0
- data/lib/motion-kit/layouts/view_layout.rb +327 -0
- data/lib/motion-kit/motion-kit.rb +18 -0
- data/lib/motion-kit/object.rb +16 -0
- data/lib/motion-kit/util.rb +20 -0
- data/lib/motion-kit/version.rb +1 -1
- data/spec/ios/apply_styles_spec.rb +21 -0
- data/spec/ios/autoresizing_helper_spec.rb +224 -0
- data/spec/ios/calculate_spec.rb +322 -0
- data/spec/ios/calculator_spec.rb +31 -0
- data/spec/ios/constraints_helpers/attribute_lookup_spec.rb +27 -0
- data/spec/ios/constraints_helpers/axis_lookup_spec.rb +13 -0
- data/spec/ios/constraints_helpers/center_constraints_spec.rb +419 -0
- data/spec/ios/constraints_helpers/constraint_placeholder_spec.rb +72 -0
- data/spec/ios/constraints_helpers/priority_lookup_spec.rb +19 -0
- data/spec/ios/constraints_helpers/relationship_lookup_spec.rb +27 -0
- data/spec/ios/constraints_helpers/relative_corners_spec.rb +274 -0
- data/spec/ios/constraints_helpers/relative_location_spec.rb +111 -0
- data/spec/ios/constraints_helpers/simple_constraints_spec.rb +2763 -0
- data/spec/ios/constraints_helpers/size_constraints_spec.rb +422 -0
- data/spec/ios/constraints_helpers/view_lookup_constraints_spec.rb +93 -0
- data/spec/ios/create_layout_spec.rb +40 -0
- data/spec/ios/custom_layout_spec.rb +13 -0
- data/spec/ios/deferred_spec.rb +89 -0
- data/spec/ios/device_helpers_spec.rb +51 -0
- data/spec/ios/frame_helper_spec.rb +1150 -0
- data/spec/ios/layer_layout_spec.rb +36 -0
- data/spec/ios/layout_extensions_spec.rb +70 -0
- data/spec/ios/layout_spec.rb +74 -0
- data/spec/ios/layout_state_spec.rb +27 -0
- data/spec/ios/motionkit_util_spec.rb +102 -0
- data/spec/ios/objc_selectors_spec.rb +10 -0
- data/spec/ios/orientation_helper_specs.rb +67 -0
- data/spec/ios/parent_layout_spec.rb +19 -0
- data/spec/ios/parent_spec.rb +45 -0
- data/spec/ios/remove_layout_spec.rb +25 -0
- data/spec/ios/root_layout_spec.rb +53 -0
- data/spec/ios/setters_spec.rb +63 -0
- data/spec/ios/uibutton_layout_spec.rb +24 -0
- data/spec/ios/uitextfield_spec.rb +14 -0
- data/spec/ios/view_attr_spec.rb +25 -0
- data/spec/osx/autoresizing_helper_spec.rb +224 -0
- data/spec/osx/constraints_helper_spec.rb +0 -0
- data/spec/osx/constraints_helpers/orientation_lookup_spec.rb +13 -0
- data/spec/osx/constraints_helpers/simple_constraints_spec.rb +2095 -0
- data/spec/osx/constraints_helpers/size_constraints_spec.rb +362 -0
- data/spec/osx/create_menu_spec.rb +14 -0
- data/spec/osx/create_via_extensions_spec.rb +63 -0
- data/spec/osx/deferred_spec.rb +85 -0
- data/spec/osx/frame_helper_spec.rb +1881 -0
- data/spec/osx/menu_extensions_spec.rb +376 -0
- data/spec/osx/menu_layout_spec.rb +157 -0
- data/spec/osx/menu_spec.rb +70 -0
- data/spec/osx/root_menu_spec.rb +15 -0
- metadata +166 -14
@@ -0,0 +1,72 @@
|
|
1
|
+
describe 'Constraints - placeholder helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MK::Layout.new
|
5
|
+
@view = @layout.context(UIView.new) do
|
6
|
+
@first = @layout.add UILabel.new, :label do
|
7
|
+
@layout.text 'first'
|
8
|
+
end
|
9
|
+
@nth = @layout.add UILabel.new, :label do
|
10
|
+
@layout.text 'nth'
|
11
|
+
end
|
12
|
+
@last = @layout.add UILabel.new, :label do
|
13
|
+
@layout.text 'last'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return :first' do
|
19
|
+
@layout.context(@view) do
|
20
|
+
@layout.constraints do
|
21
|
+
@constraint = @layout.x.equals(@layout.first(:label))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
26
|
+
resolved.length.should == 1
|
27
|
+
resolved[0].firstItem.should == @view
|
28
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
29
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
30
|
+
resolved[0].secondItem.should == @first
|
31
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
32
|
+
resolved[0].multiplier.should == 1
|
33
|
+
resolved[0].constant.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return :nth' do
|
37
|
+
@layout.context(@view) do
|
38
|
+
@layout.constraints do
|
39
|
+
@constraint = @layout.x.equals(@layout.nth(:label, 1))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
44
|
+
resolved.length.should == 1
|
45
|
+
resolved[0].firstItem.should == @view
|
46
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
47
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
48
|
+
resolved[0].secondItem.should == @nth
|
49
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
50
|
+
resolved[0].multiplier.should == 1
|
51
|
+
resolved[0].constant.should == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return :last' do
|
55
|
+
@layout.context(@view) do
|
56
|
+
@layout.constraints do
|
57
|
+
@constraint = @layout.x.equals(@layout.last(:label))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
62
|
+
resolved.length.should == 1
|
63
|
+
resolved[0].firstItem.should == @view
|
64
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
65
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
66
|
+
resolved[0].secondItem.should == @last
|
67
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
68
|
+
resolved[0].multiplier.should == 1
|
69
|
+
resolved[0].constant.should == 0
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe 'Constraints - priority lookup' do
|
2
|
+
|
3
|
+
it 'should return 1000' do
|
4
|
+
MotionKit::Constraint.priority_lookup(:required).should == 1000
|
5
|
+
MotionKit::Constraint.priority_lookup(1000).should == 1000
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return 250' do
|
9
|
+
MotionKit::Constraint.priority_lookup(:low).should == 250
|
10
|
+
MotionKit::Constraint.priority_lookup(250).should == 250
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should raise InvalidPriorityError' do
|
14
|
+
-> do
|
15
|
+
MotionKit::Constraint.priority_lookup(:foo)
|
16
|
+
end.should.raise(MotionKit::InvalidPriorityError)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe 'Constraints - relationship lookup' do
|
2
|
+
|
3
|
+
it 'should return NSLayoutRelationEqual' do
|
4
|
+
MotionKit::Constraint.relationship_lookup(:equal).should == NSLayoutRelationEqual
|
5
|
+
MotionKit::Constraint.relationship_lookup(NSLayoutRelationEqual).should == NSLayoutRelationEqual
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should return NSLayoutRelationGreaterThanOrEqual' do
|
9
|
+
MotionKit::Constraint.relationship_lookup(:gte).should == NSLayoutRelationGreaterThanOrEqual
|
10
|
+
MotionKit::Constraint.relationship_lookup(NSLayoutRelationGreaterThanOrEqual).should == NSLayoutRelationGreaterThanOrEqual
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should raise InvalidRelationshipError' do
|
14
|
+
-> do
|
15
|
+
MotionKit::Constraint.relationship_lookup(:foo)
|
16
|
+
end.should.raise(MotionKit::InvalidRelationshipError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should reverse NSLayoutRelationEqual' do
|
20
|
+
MotionKit::Constraint.relationship_reverse(NSLayoutRelationEqual).should == :equal
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should reverse NSLayoutRelationGreaterThanOrEqual' do
|
24
|
+
MotionKit::Constraint.relationship_reverse(NSLayoutRelationGreaterThanOrEqual).should == :gte
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
describe 'Constraints - Relative corners helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MK::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = nil
|
7
|
+
@another_view = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should support `top_left [10, 10]`' do
|
11
|
+
@view = @layout.context(UIView.new) do
|
12
|
+
@layout.constraints do
|
13
|
+
@constraint = @layout.top_left([10, 10])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@constraint.constant.should == [10, 10]
|
18
|
+
@constraint.relationship.should == :equal
|
19
|
+
@constraint.multiplier.should == [1, 1]
|
20
|
+
@constraint.relative_to.should == :superview
|
21
|
+
@constraint.attribute.should == [:left, :top]
|
22
|
+
@constraint.attribute2.should == [:left, :top]
|
23
|
+
|
24
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
25
|
+
resolved.length.should == 2
|
26
|
+
resolved[0].firstItem.should == @view
|
27
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
28
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
29
|
+
resolved[0].secondItem.should == nil
|
30
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
31
|
+
resolved[0].multiplier.should == 1
|
32
|
+
resolved[0].constant.should == 10
|
33
|
+
|
34
|
+
resolved[1].firstItem.should == @view
|
35
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeTop
|
36
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
37
|
+
resolved[1].secondItem.should == nil
|
38
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
39
|
+
resolved[1].multiplier.should == 1
|
40
|
+
resolved[1].constant.should == 10
|
41
|
+
end
|
42
|
+
it 'should support `top_left.equals(:another_view).plus(10).plus([5, 10])`' do
|
43
|
+
@view = @layout.context(UIView.new) do
|
44
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
45
|
+
@layout.constraints do
|
46
|
+
@constraint = @layout.top_left.equals(:another_view).plus(10).plus([5, 10])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
@constraint.constant.should == [15, 20]
|
51
|
+
@constraint.relationship.should == :equal
|
52
|
+
@constraint.multiplier.should == [1, 1]
|
53
|
+
@constraint.relative_to.should == :another_view
|
54
|
+
@constraint.attribute.should == [:left, :top]
|
55
|
+
@constraint.attribute2.should == [:left, :top]
|
56
|
+
|
57
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
58
|
+
resolved.length.should == 2
|
59
|
+
resolved[0].firstItem.should == @view
|
60
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
61
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
62
|
+
resolved[0].secondItem.should == @another_view
|
63
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
64
|
+
resolved[0].multiplier.should == 1
|
65
|
+
resolved[0].constant.should == 15
|
66
|
+
|
67
|
+
resolved[1].firstItem.should == @view
|
68
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeTop
|
69
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
70
|
+
resolved[1].secondItem.should == @another_view
|
71
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeTop
|
72
|
+
resolved[1].multiplier.should == 1
|
73
|
+
resolved[1].constant.should == 20
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should support `top_right [10, 10]`' do
|
77
|
+
@view = @layout.context(UIView.new) do
|
78
|
+
@layout.constraints do
|
79
|
+
@constraint = @layout.top_right([10, 10])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
@constraint.constant.should == [10, 10]
|
84
|
+
@constraint.relationship.should == :equal
|
85
|
+
@constraint.multiplier.should == [1, 1]
|
86
|
+
@constraint.relative_to.should == :superview
|
87
|
+
@constraint.attribute.should == [:right, :top]
|
88
|
+
@constraint.attribute2.should == [:right, :top]
|
89
|
+
|
90
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
91
|
+
resolved.length.should == 2
|
92
|
+
resolved[0].firstItem.should == @view
|
93
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeRight
|
94
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
95
|
+
resolved[0].secondItem.should == nil
|
96
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
97
|
+
resolved[0].multiplier.should == 1
|
98
|
+
resolved[0].constant.should == 10
|
99
|
+
|
100
|
+
resolved[1].firstItem.should == @view
|
101
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeTop
|
102
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
103
|
+
resolved[1].secondItem.should == nil
|
104
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
105
|
+
resolved[1].multiplier.should == 1
|
106
|
+
resolved[1].constant.should == 10
|
107
|
+
end
|
108
|
+
it 'should support `top_right.equals(:another_view).plus(10).plus([5, 10])`' do
|
109
|
+
@view = @layout.context(UIView.new) do
|
110
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
111
|
+
@layout.constraints do
|
112
|
+
@constraint = @layout.top_right.equals(:another_view).plus(10).plus([5, 10])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
@constraint.constant.should == [15, 20]
|
117
|
+
@constraint.relationship.should == :equal
|
118
|
+
@constraint.multiplier.should == [1, 1]
|
119
|
+
@constraint.relative_to.should == :another_view
|
120
|
+
@constraint.attribute.should == [:right, :top]
|
121
|
+
@constraint.attribute2.should == [:right, :top]
|
122
|
+
|
123
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
124
|
+
resolved.length.should == 2
|
125
|
+
resolved[0].firstItem.should == @view
|
126
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeRight
|
127
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
128
|
+
resolved[0].secondItem.should == @another_view
|
129
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeRight
|
130
|
+
resolved[0].multiplier.should == 1
|
131
|
+
resolved[0].constant.should == 15
|
132
|
+
|
133
|
+
resolved[1].firstItem.should == @view
|
134
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeTop
|
135
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
136
|
+
resolved[1].secondItem.should == @another_view
|
137
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeTop
|
138
|
+
resolved[1].multiplier.should == 1
|
139
|
+
resolved[1].constant.should == 20
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should support `bottom_left [10, 10]`' do
|
143
|
+
@view = @layout.context(UIView.new) do
|
144
|
+
@layout.constraints do
|
145
|
+
@constraint = @layout.bottom_left([10, 10])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
@constraint.constant.should == [10, 10]
|
150
|
+
@constraint.relationship.should == :equal
|
151
|
+
@constraint.multiplier.should == [1, 1]
|
152
|
+
@constraint.relative_to.should == :superview
|
153
|
+
@constraint.attribute.should == [:left, :bottom]
|
154
|
+
@constraint.attribute2.should == [:left, :bottom]
|
155
|
+
|
156
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
157
|
+
resolved.length.should == 2
|
158
|
+
resolved[0].firstItem.should == @view
|
159
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
160
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
161
|
+
resolved[0].secondItem.should == nil
|
162
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
163
|
+
resolved[0].multiplier.should == 1
|
164
|
+
resolved[0].constant.should == 10
|
165
|
+
|
166
|
+
resolved[1].firstItem.should == @view
|
167
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeBottom
|
168
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
169
|
+
resolved[1].secondItem.should == nil
|
170
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
171
|
+
resolved[1].multiplier.should == 1
|
172
|
+
resolved[1].constant.should == 10
|
173
|
+
end
|
174
|
+
it 'should support `bottom_left.equals(:another_view).plus(10).plus([5, 10])`' do
|
175
|
+
@view = @layout.context(UIView.new) do
|
176
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
177
|
+
@layout.constraints do
|
178
|
+
@constraint = @layout.bottom_left.equals(:another_view).plus(10).plus([5, 10])
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
@constraint.constant.should == [15, 20]
|
183
|
+
@constraint.relationship.should == :equal
|
184
|
+
@constraint.multiplier.should == [1, 1]
|
185
|
+
@constraint.relative_to.should == :another_view
|
186
|
+
@constraint.attribute.should == [:left, :bottom]
|
187
|
+
@constraint.attribute2.should == [:left, :bottom]
|
188
|
+
|
189
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
190
|
+
resolved.length.should == 2
|
191
|
+
resolved[0].firstItem.should == @view
|
192
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
193
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
194
|
+
resolved[0].secondItem.should == @another_view
|
195
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
196
|
+
resolved[0].multiplier.should == 1
|
197
|
+
resolved[0].constant.should == 15
|
198
|
+
|
199
|
+
resolved[1].firstItem.should == @view
|
200
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeBottom
|
201
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
202
|
+
resolved[1].secondItem.should == @another_view
|
203
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeBottom
|
204
|
+
resolved[1].multiplier.should == 1
|
205
|
+
resolved[1].constant.should == 20
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should support `bottom_right [10, 10]`' do
|
209
|
+
@view = @layout.context(UIView.new) do
|
210
|
+
@layout.constraints do
|
211
|
+
@constraint = @layout.bottom_right([10, 10])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
@constraint.constant.should == [10, 10]
|
216
|
+
@constraint.relationship.should == :equal
|
217
|
+
@constraint.multiplier.should == [1, 1]
|
218
|
+
@constraint.relative_to.should == :superview
|
219
|
+
@constraint.attribute.should == [:right, :bottom]
|
220
|
+
@constraint.attribute2.should == [:right, :bottom]
|
221
|
+
|
222
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
223
|
+
resolved.length.should == 2
|
224
|
+
resolved[0].firstItem.should == @view
|
225
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeRight
|
226
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
227
|
+
resolved[0].secondItem.should == nil
|
228
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
229
|
+
resolved[0].multiplier.should == 1
|
230
|
+
resolved[0].constant.should == 10
|
231
|
+
|
232
|
+
resolved[1].firstItem.should == @view
|
233
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeBottom
|
234
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
235
|
+
resolved[1].secondItem.should == nil
|
236
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeNotAnAttribute
|
237
|
+
resolved[1].multiplier.should == 1
|
238
|
+
resolved[1].constant.should == 10
|
239
|
+
end
|
240
|
+
it 'should support `bottom_right.equals(:another_view).plus(10).plus([5, 10])`' do
|
241
|
+
@view = @layout.context(UIView.new) do
|
242
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
243
|
+
@layout.constraints do
|
244
|
+
@constraint = @layout.bottom_right.equals(:another_view).plus(10).plus([5, 10])
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
@constraint.constant.should == [15, 20]
|
249
|
+
@constraint.relationship.should == :equal
|
250
|
+
@constraint.multiplier.should == [1, 1]
|
251
|
+
@constraint.relative_to.should == :another_view
|
252
|
+
@constraint.attribute.should == [:right, :bottom]
|
253
|
+
@constraint.attribute2.should == [:right, :bottom]
|
254
|
+
|
255
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
256
|
+
resolved.length.should == 2
|
257
|
+
resolved[0].firstItem.should == @view
|
258
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeRight
|
259
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
260
|
+
resolved[0].secondItem.should == @another_view
|
261
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeRight
|
262
|
+
resolved[0].multiplier.should == 1
|
263
|
+
resolved[0].constant.should == 15
|
264
|
+
|
265
|
+
resolved[1].firstItem.should == @view
|
266
|
+
resolved[1].firstAttribute.should == NSLayoutAttributeBottom
|
267
|
+
resolved[1].relation.should == NSLayoutRelationEqual
|
268
|
+
resolved[1].secondItem.should == @another_view
|
269
|
+
resolved[1].secondAttribute.should == NSLayoutAttributeBottom
|
270
|
+
resolved[1].multiplier.should == 1
|
271
|
+
resolved[1].constant.should == 20
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
describe 'Constraints - Relative location helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MK::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = nil
|
7
|
+
@another_view = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should support `above(:another_view)`' do
|
11
|
+
@view = @layout.context(UIView.new) do
|
12
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
13
|
+
@layout.constraints do
|
14
|
+
@constraint = @layout.above(:another_view)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
@constraint.constant.should == 0
|
19
|
+
@constraint.relationship.should == :equal
|
20
|
+
@constraint.multiplier.should == 1
|
21
|
+
@constraint.relative_to.should == :another_view
|
22
|
+
@constraint.attribute.should == :bottom
|
23
|
+
@constraint.attribute2.should == :top
|
24
|
+
|
25
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
26
|
+
resolved.length.should == 1
|
27
|
+
resolved[0].firstItem.should == @view
|
28
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeBottom
|
29
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
30
|
+
resolved[0].secondItem.should == @another_view
|
31
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeTop
|
32
|
+
resolved[0].multiplier.should == 1
|
33
|
+
resolved[0].constant.should == 0
|
34
|
+
end
|
35
|
+
it 'should support `below(:another_view)`' do
|
36
|
+
@view = @layout.context(UIView.new) do
|
37
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
38
|
+
@layout.constraints do
|
39
|
+
@constraint = @layout.below(:another_view)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@constraint.constant.should == 0
|
44
|
+
@constraint.relationship.should == :equal
|
45
|
+
@constraint.multiplier.should == 1
|
46
|
+
@constraint.relative_to.should == :another_view
|
47
|
+
@constraint.attribute.should == :top
|
48
|
+
@constraint.attribute2.should == :bottom
|
49
|
+
|
50
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
51
|
+
resolved.length.should == 1
|
52
|
+
resolved[0].firstItem.should == @view
|
53
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeTop
|
54
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
55
|
+
resolved[0].secondItem.should == @another_view
|
56
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeBottom
|
57
|
+
resolved[0].multiplier.should == 1
|
58
|
+
resolved[0].constant.should == 0
|
59
|
+
end
|
60
|
+
it 'should support `before(:another_view)`' do
|
61
|
+
@view = @layout.context(UIView.new) do
|
62
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
63
|
+
@layout.constraints do
|
64
|
+
@constraint = @layout.before(:another_view)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
@constraint.constant.should == 0
|
69
|
+
@constraint.relationship.should == :equal
|
70
|
+
@constraint.multiplier.should == 1
|
71
|
+
@constraint.relative_to.should == :another_view
|
72
|
+
@constraint.attribute.should == :right
|
73
|
+
@constraint.attribute2.should == :left
|
74
|
+
|
75
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
76
|
+
resolved.length.should == 1
|
77
|
+
resolved[0].firstItem.should == @view
|
78
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeRight
|
79
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
80
|
+
resolved[0].secondItem.should == @another_view
|
81
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
82
|
+
resolved[0].multiplier.should == 1
|
83
|
+
resolved[0].constant.should == 0
|
84
|
+
end
|
85
|
+
it 'should support `after(:another_view)`' do
|
86
|
+
@view = @layout.context(UIView.new) do
|
87
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
88
|
+
@layout.constraints do
|
89
|
+
@constraint = @layout.after(:another_view)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@constraint.constant.should == 0
|
94
|
+
@constraint.relationship.should == :equal
|
95
|
+
@constraint.multiplier.should == 1
|
96
|
+
@constraint.relative_to.should == :another_view
|
97
|
+
@constraint.attribute.should == :left
|
98
|
+
@constraint.attribute2.should == :right
|
99
|
+
|
100
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
101
|
+
resolved.length.should == 1
|
102
|
+
resolved[0].firstItem.should == @view
|
103
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
104
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
105
|
+
resolved[0].secondItem.should == @another_view
|
106
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeRight
|
107
|
+
resolved[0].multiplier.should == 1
|
108
|
+
resolved[0].constant.should == 0
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|