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.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +839 -0
  3. data/lib/motion-kit-cocoa/cocoa_util.rb +59 -0
  4. data/lib/motion-kit-cocoa/constraints/constraint.rb +765 -0
  5. data/lib/motion-kit-cocoa/constraints/constraint_placeholder.rb +22 -0
  6. data/lib/motion-kit-cocoa/constraints/constraints_layout.rb +536 -0
  7. data/lib/motion-kit-cocoa/constraints/constraints_target.rb +52 -0
  8. data/lib/motion-kit-cocoa/layouts/cagradientlayer_layout.rb +13 -0
  9. data/lib/motion-kit-cocoa/layouts/calayer_layout.rb +27 -0
  10. data/lib/motion-kit-cocoa/layouts/sugarcube_compat.rb +38 -0
  11. data/lib/motion-kit-ios/dummy.rb +93 -0
  12. data/lib/motion-kit-ios/ios_util.rb +20 -0
  13. data/lib/motion-kit-ios/layouts/constraints_layout.rb +22 -0
  14. data/lib/motion-kit-ios/layouts/layout_device.rb +32 -0
  15. data/lib/motion-kit-ios/layouts/layout_orientation.rb +47 -0
  16. data/lib/motion-kit-ios/layouts/uibutton_layout.rb +52 -0
  17. data/lib/motion-kit-ios/layouts/uiview_layout.rb +45 -0
  18. data/lib/motion-kit-ios/layouts/uiview_layout_autoresizing.rb +75 -0
  19. data/lib/motion-kit-ios/layouts/uiview_layout_constraints.rb +36 -0
  20. data/lib/motion-kit-ios/layouts/uiview_layout_frame.rb +307 -0
  21. data/lib/motion-kit-ios/layouts/uiview_layout_gradient.rb +20 -0
  22. data/lib/motion-kit-osx/dummy.rb +89 -0
  23. data/lib/motion-kit-osx/layouts/constraints_layout.rb +42 -0
  24. data/lib/motion-kit-osx/layouts/nsmenu_extensions.rb +186 -0
  25. data/lib/motion-kit-osx/layouts/nsmenu_layout.rb +109 -0
  26. data/lib/motion-kit-osx/layouts/nsmenuitem_extensions.rb +45 -0
  27. data/lib/motion-kit-osx/layouts/nstablecolumn_layout.rb +12 -0
  28. data/lib/motion-kit-osx/layouts/nstableview_layout.rb +20 -0
  29. data/lib/motion-kit-osx/layouts/nsview_layout.rb +47 -0
  30. data/lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb +75 -0
  31. data/lib/motion-kit-osx/layouts/nsview_layout_constraints.rb +34 -0
  32. data/lib/motion-kit-osx/layouts/nsview_layout_frame.rb +375 -0
  33. data/lib/motion-kit-osx/layouts/nswindow_frame.rb +14 -0
  34. data/lib/motion-kit-osx/layouts/nswindow_layout.rb +77 -0
  35. data/lib/motion-kit-osx/osx_util.rb +16 -0
  36. data/lib/motion-kit.rb +33 -0
  37. data/lib/motion-kit/calculate.rb +263 -0
  38. data/lib/motion-kit/layouts/base_layout.rb +299 -0
  39. data/lib/motion-kit/layouts/base_layout_class_methods.rb +43 -0
  40. data/lib/motion-kit/layouts/parent.rb +68 -0
  41. data/lib/motion-kit/layouts/view_layout.rb +327 -0
  42. data/lib/motion-kit/motion-kit.rb +18 -0
  43. data/lib/motion-kit/object.rb +16 -0
  44. data/lib/motion-kit/util.rb +20 -0
  45. data/lib/motion-kit/version.rb +1 -1
  46. data/spec/ios/apply_styles_spec.rb +21 -0
  47. data/spec/ios/autoresizing_helper_spec.rb +224 -0
  48. data/spec/ios/calculate_spec.rb +322 -0
  49. data/spec/ios/calculator_spec.rb +31 -0
  50. data/spec/ios/constraints_helpers/attribute_lookup_spec.rb +27 -0
  51. data/spec/ios/constraints_helpers/axis_lookup_spec.rb +13 -0
  52. data/spec/ios/constraints_helpers/center_constraints_spec.rb +419 -0
  53. data/spec/ios/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  54. data/spec/ios/constraints_helpers/priority_lookup_spec.rb +19 -0
  55. data/spec/ios/constraints_helpers/relationship_lookup_spec.rb +27 -0
  56. data/spec/ios/constraints_helpers/relative_corners_spec.rb +274 -0
  57. data/spec/ios/constraints_helpers/relative_location_spec.rb +111 -0
  58. data/spec/ios/constraints_helpers/simple_constraints_spec.rb +2763 -0
  59. data/spec/ios/constraints_helpers/size_constraints_spec.rb +422 -0
  60. data/spec/ios/constraints_helpers/view_lookup_constraints_spec.rb +93 -0
  61. data/spec/ios/create_layout_spec.rb +40 -0
  62. data/spec/ios/custom_layout_spec.rb +13 -0
  63. data/spec/ios/deferred_spec.rb +89 -0
  64. data/spec/ios/device_helpers_spec.rb +51 -0
  65. data/spec/ios/frame_helper_spec.rb +1150 -0
  66. data/spec/ios/layer_layout_spec.rb +36 -0
  67. data/spec/ios/layout_extensions_spec.rb +70 -0
  68. data/spec/ios/layout_spec.rb +74 -0
  69. data/spec/ios/layout_state_spec.rb +27 -0
  70. data/spec/ios/motionkit_util_spec.rb +102 -0
  71. data/spec/ios/objc_selectors_spec.rb +10 -0
  72. data/spec/ios/orientation_helper_specs.rb +67 -0
  73. data/spec/ios/parent_layout_spec.rb +19 -0
  74. data/spec/ios/parent_spec.rb +45 -0
  75. data/spec/ios/remove_layout_spec.rb +25 -0
  76. data/spec/ios/root_layout_spec.rb +53 -0
  77. data/spec/ios/setters_spec.rb +63 -0
  78. data/spec/ios/uibutton_layout_spec.rb +24 -0
  79. data/spec/ios/uitextfield_spec.rb +14 -0
  80. data/spec/ios/view_attr_spec.rb +25 -0
  81. data/spec/osx/autoresizing_helper_spec.rb +224 -0
  82. data/spec/osx/constraints_helper_spec.rb +0 -0
  83. data/spec/osx/constraints_helpers/orientation_lookup_spec.rb +13 -0
  84. data/spec/osx/constraints_helpers/simple_constraints_spec.rb +2095 -0
  85. data/spec/osx/constraints_helpers/size_constraints_spec.rb +362 -0
  86. data/spec/osx/create_menu_spec.rb +14 -0
  87. data/spec/osx/create_via_extensions_spec.rb +63 -0
  88. data/spec/osx/deferred_spec.rb +85 -0
  89. data/spec/osx/frame_helper_spec.rb +1881 -0
  90. data/spec/osx/menu_extensions_spec.rb +376 -0
  91. data/spec/osx/menu_layout_spec.rb +157 -0
  92. data/spec/osx/menu_spec.rb +70 -0
  93. data/spec/osx/root_menu_spec.rb +15 -0
  94. metadata +166 -14
@@ -0,0 +1,40 @@
1
+ describe MotionKit::Layout do
2
+ before do
3
+ @subject = TestCreateLayout.new
4
+ end
5
+
6
+ it 'should create a view' do
7
+ @subject.create_view.should.not == nil
8
+ end
9
+
10
+ it 'should create a UIView' do
11
+ @subject.create_view.should.be.kind_of(UIView)
12
+ end
13
+
14
+ it 'should create a new view every time' do
15
+ create_view1 = @subject.create_view
16
+ create_view2 = @subject.create_view
17
+ create_view1.should.not == create_view2
18
+ end
19
+
20
+ it 'should create a view without a superview' do
21
+ @subject.create_view.superview.should == nil
22
+ end
23
+
24
+ it 'should add a label to the view' do
25
+ @subject.create_view.subviews.first.should.be.kind_of(UILabel)
26
+ end
27
+
28
+ it 'should not add an image view' do
29
+ @subject.create_view.subviews.find { |view| view.is_a?(UIImageView) }.should == nil
30
+ end
31
+
32
+ it 'should allow a view to be returned ' do
33
+ @subject.create_and_context.should.not == nil
34
+ end
35
+
36
+ it 'should create a UIView via context' do
37
+ @subject.create_and_context.should.be.kind_of(UIView)
38
+ end
39
+
40
+ end
@@ -0,0 +1,13 @@
1
+ describe "Custom Layout" do
2
+
3
+ before do
4
+ @subject = TestCustomLayout.new
5
+ end
6
+
7
+ it 'should always use the correct Layout' do
8
+ @subject.view.should.be.kind_of?(CustomLabel)
9
+ @subject.view.text.should == 'custom text'
10
+ @subject.view.attributedText.should.not == nil
11
+ end
12
+
13
+ end
@@ -0,0 +1,89 @@
1
+ describe TestDeferredLayout do
2
+
3
+ before do
4
+ @layout = TestDeferredLayout.new
5
+ @layout.view
6
+ end
7
+
8
+ describe 'from layout' do
9
+ it 'should run the deferred block' do
10
+ @layout.layout_test_ran.should == true
11
+ end
12
+
13
+ it 'should have assigned the value 0' do
14
+ @layout.layout_test_is_0.should == true
15
+ end
16
+
17
+ it 'should end up with the value 1' do
18
+ @layout.layout_test.should == 1
19
+ end
20
+ end
21
+
22
+ describe 'from create_view' do
23
+ before do
24
+ @layout.create_view
25
+ end
26
+
27
+ it 'should run the deferred block' do
28
+ @layout.create_view_test_ran.should == true
29
+ end
30
+
31
+ it 'should have assigned the value 0' do
32
+ @layout.create_view_test_is_0.should == true
33
+ end
34
+
35
+ it 'should end up with the value 1' do
36
+ @layout.create_view_test.should == 1
37
+ end
38
+ end
39
+
40
+ describe 'from error_no_context' do
41
+ it 'should raise InvalidDeferredError' do
42
+ -> do
43
+ @layout.error_no_context
44
+ end.should.raise(MK::InvalidDeferredError)
45
+ end
46
+ end
47
+
48
+ describe 'from nested_blocks' do
49
+ before do
50
+ @layout.nested_blocks
51
+ end
52
+
53
+ it 'should run the deferred block' do
54
+ @layout.nested_blocks_test_ran.should == true
55
+ end
56
+ it 'should have assigned the value 0' do
57
+ @layout.nested_blocks_test_is_0.should == true
58
+ end
59
+ it 'should have assigned the value 1' do
60
+ @layout.nested_blocks_test_is_1.should == true
61
+ end
62
+ it 'should end up with the value 1' do
63
+ @layout.nested_blocks_test.should == 2
64
+ end
65
+ end
66
+
67
+ describe 'from apply_layouts' do
68
+ before do
69
+ @layout.apply_layouts
70
+ end
71
+
72
+ it 'should run the deferred block' do
73
+ @layout.apply_layouts_test_ran.should == 3
74
+ end
75
+
76
+ it 'should have assigned text to the label' do
77
+ @layout.apply_layouts_label.text.should == 'after'
78
+ end
79
+
80
+ it 'should have assigned title to the button' do
81
+ @layout.apply_layouts_button.currentTitle.should == 'after'
82
+ end
83
+
84
+ it 'should have assigned opacity to the layer' do
85
+ @layout.apply_layouts_layer.opacity.should == 0.5
86
+ end
87
+ end
88
+
89
+ end
@@ -0,0 +1,51 @@
1
+ describe 'Device helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ end
6
+
7
+ it 'should have device helpers' do
8
+ @layout.context({}) do
9
+ @layout.iphone?.should == true
10
+ @layout.iphone4?.should == true
11
+ @layout.iphone35?.should == false
12
+ @layout.ipad?.should == false
13
+ @layout.retina?.should == true
14
+ end
15
+ end
16
+
17
+ it 'should have device (iphone do end) helpers' do
18
+ @layout.context({}) do
19
+ @check = false
20
+ @layout.iphone do
21
+ @check = true
22
+ end
23
+ @check.should == true
24
+
25
+ @check = false
26
+ @layout.iphone4 do
27
+ @check = true
28
+ end
29
+ @check.should == true
30
+
31
+ @check = false
32
+ @layout.iphone35 do
33
+ @check = true
34
+ end
35
+ @check.should == false
36
+
37
+ @check = false
38
+ @layout.ipad do
39
+ @check = true
40
+ end
41
+ @check.should == false
42
+
43
+ @check = false
44
+ @layout.retina do
45
+ @check = true
46
+ end
47
+ @check.should == true
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,1150 @@
1
+ describe 'Frame helpers' do
2
+ tests UIViewController
3
+
4
+ before do
5
+ @layout = TestEmptyLayout.new
6
+ top_view = @controller.view
7
+ @layout.root = top_view
8
+
9
+ @view_size = CGSize.new(8, 10)
10
+ @view = UIView.alloc.initWithFrame([[0, 0], @view_size])
11
+ @view.backgroundColor = UIColor.whiteColor
12
+ @view.motion_kit_id = :view
13
+
14
+ @superview_size = CGSize.new(60, 40)
15
+ @superview = UIView.alloc.initWithFrame([[0, 0], @superview_size])
16
+ @superview.addSubview(@view)
17
+ @superview.backgroundColor = UIColor.blueColor
18
+
19
+ @another_view = UIView.alloc.initWithFrame([[10, 100], [120, 48]])
20
+ @another_view.backgroundColor = UIColor.redColor
21
+ @another_view.motion_kit_id = :another_view
22
+
23
+ top_view.addSubview(@another_view)
24
+ top_view.addSubview(@superview)
25
+
26
+ @label = UILabel.alloc.init
27
+ @label.text = 'M'
28
+ @label_auto_size = @label.intrinsicContentSize
29
+ end
30
+
31
+ it 'should support `x` method' do
32
+ @layout.context(@view) do
33
+ retval = @layout.x 1
34
+ @view.frame.origin.x.should == 1
35
+ retval.should == CGRectGetMinX(@view.frame)
36
+
37
+ retval = @layout.x '100% - 1'
38
+ @view.frame.origin.x.should == @superview_size.width - 1
39
+ retval.should == CGRectGetMinX(@view.frame)
40
+ end
41
+ end
42
+
43
+ it 'should support `left` method' do
44
+ @layout.context(@view) do
45
+ retval = @layout.left 1
46
+ @view.frame.origin.x.should == 1
47
+ retval.should == CGRectGetMinX(@view.frame)
48
+
49
+ retval = @layout.left '100% - 1'
50
+ @view.frame.origin.x.should == @superview_size.width - 1
51
+ retval.should == CGRectGetMinX(@view.frame)
52
+ end
53
+ end
54
+
55
+ it 'should support `right` method' do
56
+ @layout.context(@view) do
57
+ retval = @layout.right 1
58
+ @view.frame.origin.x.should == 1 - @view_size.width
59
+ retval.should == CGRectGetMaxX(@view.frame)
60
+
61
+ retval = @layout.right '100% - 1'
62
+ @view.frame.origin.x.should == @superview_size.width - 1 - @view_size.width
63
+ retval.should == CGRectGetMaxX(@view.frame)
64
+ end
65
+ end
66
+
67
+ it 'should support `center_x` method' do
68
+ @view.frame = [[0, 0], [2, 2]]
69
+ @layout.context(@view) do
70
+ retval = @layout.center_x 1
71
+ @view.center.x.should == 1
72
+ retval.should == CGRectGetMidX(@view.frame)
73
+
74
+ retval = @layout.center_x '100% - 1'
75
+ @view.center.x.should == @superview_size.width - 1
76
+ retval.should == CGRectGetMidX(@view.frame)
77
+ end
78
+ end
79
+
80
+ it 'should support `middle_x` method' do
81
+ @view.frame = [[0, 0], [2, 2]]
82
+ @layout.context(@view) do
83
+ retval = @layout.middle_x 1
84
+ @view.center.x.should == 1
85
+ retval.should == CGRectGetMidX(@view.frame)
86
+
87
+ retval = @layout.middle_x '100% - 1'
88
+ @view.center.x.should == @superview_size.width - 1
89
+ retval.should == CGRectGetMidX(@view.frame)
90
+ end
91
+ end
92
+
93
+ it 'should support `y` method' do
94
+ @layout.context(@view) do
95
+ retval = @layout.y 1
96
+ @view.frame.origin.y.should == 1
97
+ retval.should == CGRectGetMinY(@view.frame)
98
+
99
+ retval = @layout.y '100% - 1'
100
+ @view.frame.origin.y.should == @superview_size.height - 1
101
+ retval.should == CGRectGetMinY(@view.frame)
102
+ end
103
+ end
104
+
105
+ it 'should support `top` method' do
106
+ @layout.context(@view) do
107
+ retval = @layout.top 1
108
+ @view.frame.origin.y.should == 1
109
+ retval.should == CGRectGetMinY(@view.frame)
110
+
111
+ retval = @layout.top '100% - 1'
112
+ @view.frame.origin.y.should == @superview_size.height - 1
113
+ retval.should == CGRectGetMinY(@view.frame)
114
+ end
115
+ end
116
+
117
+ it 'should support `bottom` method' do
118
+ @layout.context(@view) do
119
+ retval = @layout.bottom 1
120
+ @view.frame.origin.y.should == 1 - @view_size.height
121
+ retval.should == CGRectGetMaxY(@view.frame)
122
+
123
+ retval = @layout.bottom '100% - 1'
124
+ @view.frame.origin.y.should == @superview_size.height - 1 - @view_size.height
125
+ retval.should == CGRectGetMaxY(@view.frame)
126
+ end
127
+ end
128
+
129
+ it 'should support `center_y` method' do
130
+ @view.frame = [[0, 0], [2, 2]]
131
+ @layout.context(@view) do
132
+ retval = @layout.center_y 1
133
+ @view.center.y.should == 1
134
+ retval.should == CGRectGetMidY(@view.frame)
135
+
136
+ retval = @layout.center_y '100% - 1'
137
+ @view.center.y.should == @superview_size.height - 1
138
+ retval.should == CGRectGetMidY(@view.frame)
139
+ end
140
+ end
141
+
142
+ it 'should support `middle_y` method' do
143
+ @view.frame = [[0, 0], [2, 2]]
144
+ @layout.context(@view) do
145
+ retval = @layout.middle_y 1
146
+ @view.center.y.should == 1
147
+ retval.should == CGRectGetMidY(@view.frame)
148
+
149
+ retval = @layout.middle_y '100% - 1'
150
+ @view.center.y.should == @superview_size.height - 1
151
+ retval.should == CGRectGetMidY(@view.frame)
152
+ end
153
+ end
154
+
155
+ it 'should support `width` method' do
156
+ @layout.context(@view) do
157
+ retval = @layout.width 1
158
+ @view.frame.size.width.should == 1
159
+ retval.should == CGRectGetWidth(@view.frame)
160
+
161
+ retval = @layout.width '100% - 1'
162
+ @view.frame.size.width.should == @superview_size.width - 1
163
+ retval.should == CGRectGetWidth(@view.frame)
164
+ end
165
+ end
166
+
167
+ it 'should support `w` method' do
168
+ @layout.context(@view) do
169
+ retval = @layout.w 1
170
+ @view.frame.size.width.should == 1
171
+ retval.should == CGRectGetWidth(@view.frame)
172
+
173
+ retval = @layout.w '100% - 1'
174
+ @view.frame.size.width.should == @superview_size.width - 1
175
+ retval.should == CGRectGetWidth(@view.frame)
176
+ end
177
+ end
178
+
179
+ it 'should support `height` method' do
180
+ @layout.context(@view) do
181
+ retval = @layout.height 1
182
+ @view.frame.size.height.should == 1
183
+ retval.should == CGRectGetHeight(@view.frame)
184
+
185
+ retval = @layout.height '100% - 1'
186
+ @view.frame.size.height.should == @superview_size.height - 1
187
+ retval.should == CGRectGetHeight(@view.frame)
188
+ end
189
+ end
190
+
191
+ it 'should support `h` method' do
192
+ @layout.context(@view) do
193
+ retval = @layout.h 1
194
+ @view.frame.size.height.should == 1
195
+ retval.should == CGRectGetHeight(@view.frame)
196
+
197
+ retval = @layout.h '100% - 1'
198
+ @view.frame.size.height.should == @superview_size.height - 1
199
+ retval.should == CGRectGetHeight(@view.frame)
200
+ end
201
+ end
202
+
203
+ it 'should support `origin([])` method' do
204
+ @layout.context(@view) do
205
+ retval = @layout.origin [1, 2]
206
+ @view.frame.origin.x.should == 1
207
+ @view.frame.origin.y.should == 2
208
+ retval.should == @view.frame.origin
209
+
210
+ retval = @layout.origin ['100% - 1', '100% - 2']
211
+ @view.frame.origin.x.should == @superview_size.width - 1
212
+ @view.frame.origin.y.should == @superview_size.height - 2
213
+ retval.should == @view.frame.origin
214
+ end
215
+ end
216
+
217
+ it 'should support `origin({})` method' do
218
+ @layout.context(@view) do
219
+ retval = @layout.origin x: 1, y: 2
220
+ @view.frame.origin.x.should == 1
221
+ @view.frame.origin.y.should == 2
222
+ retval.should == @view.frame.origin
223
+
224
+ retval = @layout.origin x: '100% - 1', y: '100% - 2'
225
+ @view.frame.origin.x.should == @superview_size.width - 1
226
+ @view.frame.origin.y.should == @superview_size.height - 2
227
+ retval.should == @view.frame.origin
228
+ end
229
+ end
230
+
231
+ it 'should support `origin({relative: true})` method' do
232
+ @layout.context(@view) do
233
+ retval = @layout.origin right: 1, down: 2, relative: true
234
+ @view.frame.origin.x.should == 1
235
+ @view.frame.origin.y.should == 2
236
+ retval.should == @view.frame.origin
237
+
238
+ retval = @layout.origin x: '100%', y: '100%', left: 1, up: 2, relative: true
239
+ @view.frame.origin.x.should == @superview_size.width - 1
240
+ @view.frame.origin.y.should == @superview_size.height - 2
241
+ retval.should == @view.frame.origin
242
+ end
243
+ end
244
+
245
+ it 'should support `center([])` method' do
246
+ @view.frame = [[0, 0], [2, 2]]
247
+ @layout.context(@view) do
248
+ retval = @layout.center [1, 2]
249
+ @view.center.x.should == 1
250
+ @view.center.y.should == 2
251
+ retval.should == @view.center
252
+
253
+ retval = @layout.center ['100% - 1', '100% - 2']
254
+ @view.center.x.should == @superview_size.width - 1
255
+ @view.center.y.should == @superview_size.height - 2
256
+ retval.should == @view.center
257
+ end
258
+ end
259
+
260
+ it 'should support `center({})` method' do
261
+ @view.frame = [[0, 0], [2, 2]]
262
+ @layout.context(@view) do
263
+ retval = @layout.center x: 1, y: 2
264
+ @view.center.x.should == 1
265
+ @view.center.y.should == 2
266
+ retval.should == @view.center
267
+
268
+ retval = @layout.center x: '100% - 1', y: '100% - 2'
269
+ @view.center.x.should == @superview_size.width - 1
270
+ @view.center.y.should == @superview_size.height - 2
271
+ retval.should == @view.center
272
+ end
273
+ end
274
+
275
+ it 'should support `center({relative: true})` method' do
276
+ @view.frame = [[0, 0], [2, 2]]
277
+ @layout.context(@view) do
278
+ retval = @layout.center x: 1, y: 1, right: 1, down: 2, relative: true
279
+ @view.center.x.should == 2
280
+ @view.center.y.should == 3
281
+ retval.should == @view.center
282
+
283
+ retval = @layout.center x: '100%', y: '100%', left: 1, up: 2, relative: true
284
+ @view.center.x.should == @superview_size.width - 1
285
+ @view.center.y.should == @superview_size.height - 2
286
+ retval.should == @view.center
287
+ end
288
+ end
289
+
290
+ it 'should support `size` method' do
291
+ @layout.context(@view) do
292
+ retval = @layout.size [1, 2]
293
+ @view.frame.size.width.should == 1
294
+ @view.frame.size.height.should == 2
295
+ retval.should == @view.frame.size
296
+
297
+ retval = @layout.size ['100% - 1', '100% - 2']
298
+ @view.frame.size.width.should == @superview_size.width - 1
299
+ @view.frame.size.height.should == @superview_size.height - 2
300
+ retval.should == @view.frame.size
301
+ end
302
+ end
303
+
304
+ it 'should support `size :full`' do
305
+ @layout.context(@view) do
306
+ retval = @layout.size :full
307
+ retval.should == @view.frame.size
308
+ end
309
+ @view.frame.size.width.should == @superview_size.width
310
+ @view.frame.size.height.should == @superview_size.height
311
+ end
312
+
313
+ it 'should support `size :auto`' do
314
+ @layout.context(@label) do
315
+ retval = @layout.size :auto
316
+ retval.should == @label.frame.size
317
+ end
318
+ @label.frame.size.width.should == @label_auto_size.width
319
+ @label.frame.size.height.should == @label_auto_size.height
320
+ end
321
+
322
+ it 'should support `size :auto, height`' do
323
+ @layout.context(@label) do
324
+ retval = @layout.size [:auto, @label_auto_size.height]
325
+ retval.should == @label.frame.size
326
+ end
327
+ @label.frame.size.width.should == @label_auto_size.width
328
+ @label.frame.size.height.should == @label_auto_size.height
329
+ end
330
+
331
+ it 'should support `size width, :auto`' do
332
+ @layout.context(@label) do
333
+ retval = @layout.size [@label_auto_size.width, :auto]
334
+ retval.should == @label.frame.size
335
+ end
336
+ @label.frame.size.width.should == @label_auto_size.width
337
+ @label.frame.size.height.should == @label_auto_size.height
338
+ end
339
+
340
+ it 'should support `size :scale, height`' do
341
+ @layout.context(@label) do
342
+ retval = @layout.size [100 * @label_auto_size.width, :scale]
343
+ retval.should == @label.frame.size
344
+ end
345
+ @label.frame.size.width.should == 100 * @label_auto_size.width
346
+ @label.frame.size.height.should == 100 * @label_auto_size.height
347
+ end
348
+
349
+ it 'should support `size width, :scale`' do
350
+ @layout.context(@label) do
351
+ retval = @layout.size [:scale, 100 * @label_auto_size.height]
352
+ retval.should == @label.frame.size
353
+ end
354
+ @label.frame.size.width.should == 100 * @label_auto_size.width
355
+ @label.frame.size.height.should == 100 * @label_auto_size.height
356
+ end
357
+
358
+ it 'should support `frame` arrays [[x, y], [w, h]]' do
359
+ @layout.context(@view) do
360
+ retval = @layout.frame [[1, 2], [3, 4]]
361
+ retval.should == @view.frame
362
+ end
363
+ @view.frame.origin.x.should == 1
364
+ @view.frame.origin.y.should == 2
365
+ @view.frame.size.width.should == 3
366
+ @view.frame.size.height.should == 4
367
+ end
368
+
369
+ it 'should support `frame` arrays [x, y, w, h]' do
370
+ @layout.context(@view) do
371
+ retval = @layout.frame [1, 2, 3, 4]
372
+ retval.should == @view.frame
373
+ end
374
+ @view.frame.origin.x.should == 1
375
+ @view.frame.origin.y.should == 2
376
+ @view.frame.size.width.should == 3
377
+ @view.frame.size.height.should == 4
378
+ end
379
+
380
+ it 'should support `frame :full`' do
381
+ @layout.context(@view) do
382
+ retval = @layout.frame :full
383
+ retval.should == @view.frame
384
+ end
385
+ @view.frame.origin.x.should == 0
386
+ @view.frame.origin.y.should == 0
387
+ @view.frame.size.width.should == @superview_size.width
388
+ @view.frame.size.height.should == @superview_size.height
389
+ end
390
+
391
+ it 'should support `frame :auto`' do
392
+ def @view.intrinsicContentSize
393
+ CGSize.new(1, 2)
394
+ end
395
+
396
+ @layout.context(@view) do
397
+ retval = @layout.frame :auto
398
+ retval.should == @view.frame
399
+ end
400
+ @view.frame.origin.x.should == 0
401
+ @view.frame.origin.y.should == 0
402
+ @view.frame.size.width.should == 1
403
+ @view.frame.size.height.should == 2
404
+ end
405
+
406
+ it 'should support `frame :center`' do
407
+ @layout.context(@view) do
408
+ retval = @layout.frame :center
409
+ retval.should == @view.frame
410
+ end
411
+ @view.frame.origin.x.should == 26
412
+ @view.frame.origin.y.should == 15
413
+ @view.frame.size.width.should == @view_size.width
414
+ @view.frame.size.height.should == @view_size.height
415
+ end
416
+
417
+ it 'should support setting the frame via `from_top_left`' do
418
+ @layout.context(@view) do
419
+ retval = @layout.frame @layout.from_top_left()
420
+ retval.should == @view.frame
421
+ end
422
+ @view.frame.origin.x.should == 0
423
+ @view.frame.origin.y.should == 0
424
+ @view.frame.size.width.should == @view_size.width
425
+ @view.frame.size.height.should == @view_size.height
426
+ end
427
+
428
+ it 'should support setting the frame via `from_top_left(width:height:)`' do
429
+ @layout.context(@view) do
430
+ retval = @layout.frame @layout.from_top_left(width: 10, height: 20)
431
+ retval.should == @view.frame
432
+ end
433
+ @view.frame.origin.x.should == 0
434
+ @view.frame.origin.y.should == 0
435
+ @view.frame.size.width.should == 10
436
+ @view.frame.size.height.should == 20
437
+ end
438
+
439
+ it 'should support setting the frame via `from_top_left(x:y:width:height:)`' do
440
+ @layout.context(@view) do
441
+ retval = @layout.frame @layout.from_top_left(x: 10, y: 20, width: 22, height: 12)
442
+ retval.should == @view.frame
443
+ end
444
+ @view.frame.origin.x.should == 10
445
+ @view.frame.origin.y.should == 20
446
+ @view.frame.size.width.should == 22
447
+ @view.frame.size.height.should == 12
448
+ end
449
+
450
+ it 'should support setting the frame via `from_top_left(right:down:width:height:)`' do
451
+ @layout.context(@view) do
452
+ retval = @layout.frame @layout.from_top_left(right: 10, down: 20, width: 22, height: 12)
453
+ retval.should == @view.frame
454
+ end
455
+ @view.frame.origin.x.should == 10
456
+ @view.frame.origin.y.should == 20
457
+ @view.frame.size.width.should == 22
458
+ @view.frame.size.height.should == 12
459
+ end
460
+
461
+ it 'should support setting the frame via `from_top_left(view)`' do
462
+ @layout.context(@view) do
463
+ retval = @layout.frame @layout.from_top_left(@another_view, x: 1, y: 1)
464
+ retval.should == @view.frame
465
+ end
466
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
467
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
468
+ @view.frame.size.width.should == @view_size.width
469
+ @view.frame.size.height.should == @view_size.height
470
+ end
471
+
472
+ it 'should support setting the frame via `from_top_left(:view)`' do
473
+ @layout.context(@view) do
474
+ retval = @layout.frame @layout.from_top_left(:another_view, x: 1, y: 1)
475
+ retval.should == @view.frame
476
+ end
477
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
478
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
479
+ @view.frame.size.width.should == @view_size.width
480
+ @view.frame.size.height.should == @view_size.height
481
+ end
482
+
483
+ it 'should support setting the frame via `from_top`' do
484
+ @layout.context(@view) do
485
+ retval = @layout.frame @layout.from_top()
486
+ retval.should == @view.frame
487
+ end
488
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
489
+ @view.frame.origin.y.should == 0
490
+ @view.frame.size.width.should == @view_size.width
491
+ @view.frame.size.height.should == @view_size.height
492
+ end
493
+
494
+ it 'should support setting the frame via `from_top(width:height:)`' do
495
+ @layout.context(@view) do
496
+ retval = @layout.frame @layout.from_top(width: 10, height: 20)
497
+ retval.should == @view.frame
498
+ end
499
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
500
+ @view.frame.origin.y.should == 0
501
+ @view.frame.size.width.should == 10
502
+ @view.frame.size.height.should == 20
503
+ end
504
+
505
+ it 'should support setting the frame via `from_top(x:y:width:height:)`' do
506
+ @layout.context(@view) do
507
+ retval = @layout.frame @layout.from_top(x: 10, y: 20, width: 22, height: 12)
508
+ retval.should == @view.frame
509
+ end
510
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
511
+ @view.frame.origin.y.should == 20
512
+ @view.frame.size.width.should == 22
513
+ @view.frame.size.height.should == 12
514
+ end
515
+
516
+ it 'should support setting the frame via `from_top(view)`' do
517
+ @layout.context(@view) do
518
+ retval = @layout.frame @layout.from_top(@another_view, x: 1, y: 1)
519
+ retval.should == @view.frame
520
+ end
521
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
522
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
523
+ @view.frame.size.width.should == @view_size.width
524
+ @view.frame.size.height.should == @view_size.height
525
+ end
526
+
527
+ it 'should support setting the frame via `from_top_right`' do
528
+ @layout.context(@view) do
529
+ retval = @layout.frame @layout.from_top_right()
530
+ retval.should == @view.frame
531
+ end
532
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
533
+ @view.frame.origin.y.should == 0
534
+ @view.frame.size.width.should == @view_size.width
535
+ @view.frame.size.height.should == @view_size.height
536
+ end
537
+
538
+ it 'should support setting the frame via `from_top_right(width:height:)`' do
539
+ @layout.context(@view) do
540
+ retval = @layout.frame @layout.from_top_right(width: 10, height: 20)
541
+ retval.should == @view.frame
542
+ end
543
+ @view.frame.origin.x.should == @superview_size.width - 10
544
+ @view.frame.origin.y.should == 0
545
+ @view.frame.size.width.should == 10
546
+ @view.frame.size.height.should == 20
547
+ end
548
+
549
+ it 'should support setting the frame via `from_top_right(x:y:width:height:)`' do
550
+ @layout.context(@view) do
551
+ retval = @layout.frame @layout.from_top_right(x: 10, y: 20, width: 22, height: 12)
552
+ retval.should == @view.frame
553
+ end
554
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
555
+ @view.frame.origin.y.should == 20
556
+ @view.frame.size.width.should == 22
557
+ @view.frame.size.height.should == 12
558
+ end
559
+
560
+ it 'should support setting the frame via `from_top_right(view)`' do
561
+ @layout.context(@view) do
562
+ retval = @layout.frame @layout.from_top_right(@another_view, x: 1, y: 1)
563
+ retval.should == @view.frame
564
+ end
565
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
566
+ @view.frame.origin.y.should == @another_view.frame.origin.y + 1
567
+ @view.frame.size.width.should == @view_size.width
568
+ @view.frame.size.height.should == @view_size.height
569
+ end
570
+
571
+ it 'should support setting the frame via `from_left`' do
572
+ @layout.context(@view) do
573
+ retval = @layout.frame @layout.from_left()
574
+ retval.should == @view.frame
575
+ end
576
+ @view.frame.origin.x.should == 0
577
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
578
+ @view.frame.size.width.should == @view_size.width
579
+ @view.frame.size.height.should == @view_size.height
580
+ end
581
+
582
+ it 'should support setting the frame via `from_left(width:height:)`' do
583
+ @layout.context(@view) do
584
+ retval = @layout.frame @layout.from_left(width: 10, height: 20)
585
+ retval.should == @view.frame
586
+ end
587
+ @view.frame.origin.x.should == 0
588
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
589
+ @view.frame.size.width.should == 10
590
+ @view.frame.size.height.should == 20
591
+ end
592
+
593
+ it 'should support setting the frame via `from_left(x:y:width:height:)`' do
594
+ @layout.context(@view) do
595
+ retval = @layout.frame @layout.from_left(x: 10, y: 20, width: 22, height: 12)
596
+ retval.should == @view.frame
597
+ end
598
+ @view.frame.origin.x.should == 10
599
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
600
+ @view.frame.size.width.should == 22
601
+ @view.frame.size.height.should == 12
602
+ end
603
+
604
+ it 'should support setting the frame via `from_left(view)`' do
605
+ @layout.context(@view) do
606
+ retval = @layout.frame @layout.from_left(@another_view, x: 1, y: 1)
607
+ retval.should == @view.frame
608
+ end
609
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
610
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
611
+ @view.frame.size.width.should == @view_size.width
612
+ @view.frame.size.height.should == @view_size.height
613
+ end
614
+
615
+ it 'should support setting the frame via `from_center`' do
616
+ @layout.context(@view) do
617
+ retval = @layout.frame @layout.from_center()
618
+ retval.should == @view.frame
619
+ end
620
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
621
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
622
+ @view.frame.size.width.should == @view_size.width
623
+ @view.frame.size.height.should == @view_size.height
624
+ end
625
+
626
+ it 'should support setting the frame via `from_center(width:height:)`' do
627
+ @layout.context(@view) do
628
+ retval = @layout.frame @layout.from_center(width: 10, height: 20)
629
+ retval.should == @view.frame
630
+ end
631
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
632
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
633
+ @view.frame.size.width.should == 10
634
+ @view.frame.size.height.should == 20
635
+ end
636
+
637
+ it 'should support setting the frame via `from_center(x:y:width:height:)`' do
638
+ @layout.context(@view) do
639
+ retval = @layout.frame @layout.from_center(x: 10, y: 20, width: 22, height: 12)
640
+ retval.should == @view.frame
641
+ end
642
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
643
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
644
+ @view.frame.size.width.should == 22
645
+ @view.frame.size.height.should == 12
646
+ end
647
+
648
+ it 'should support setting the frame via `from_center(view)`' do
649
+ @layout.context(@view) do
650
+ retval = @layout.frame @layout.from_center(@another_view, x: 1, y: 1)
651
+ retval.should == @view.frame
652
+ end
653
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
654
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
655
+ @view.frame.size.width.should == @view_size.width
656
+ @view.frame.size.height.should == @view_size.height
657
+ end
658
+
659
+ it 'should support setting the frame via `from_right`' do
660
+ @layout.context(@view) do
661
+ retval = @layout.frame @layout.from_right()
662
+ retval.should == @view.frame
663
+ end
664
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
665
+ @view.frame.origin.y.should == (@superview_size.height - @view_size.height) / 2
666
+ @view.frame.size.width.should == @view_size.width
667
+ @view.frame.size.height.should == @view_size.height
668
+ end
669
+
670
+ it 'should support setting the frame via `from_right(width:height:)`' do
671
+ @layout.context(@view) do
672
+ retval = @layout.frame @layout.from_right(width: 10, height: 20)
673
+ retval.should == @view.frame
674
+ end
675
+ @view.frame.origin.x.should == @superview_size.width - 10
676
+ @view.frame.origin.y.should == (@superview_size.height - 20) / 2
677
+ @view.frame.size.width.should == 10
678
+ @view.frame.size.height.should == 20
679
+ end
680
+
681
+ it 'should support setting the frame via `from_right(x:y:width:height:)`' do
682
+ @layout.context(@view) do
683
+ retval = @layout.frame @layout.from_right(x: 10, y: 20, width: 22, height: 12)
684
+ retval.should == @view.frame
685
+ end
686
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
687
+ @view.frame.origin.y.should == (@superview_size.height - 12) / 2 + 20
688
+ @view.frame.size.width.should == 22
689
+ @view.frame.size.height.should == 12
690
+ end
691
+
692
+ it 'should support setting the frame via `from_right(view)`' do
693
+ @layout.context(@view) do
694
+ retval = @layout.frame @layout.from_right(@another_view, x: 1, y: 1)
695
+ retval.should == @view.frame
696
+ end
697
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
698
+ @view.frame.origin.y.should == @another_view.frame.origin.y + (@another_view.frame.size.height - @view_size.height) / 2 + 1
699
+ @view.frame.size.width.should == @view_size.width
700
+ @view.frame.size.height.should == @view_size.height
701
+ end
702
+
703
+ it 'should support setting the frame via `from_bottom_left`' do
704
+ @layout.context(@view) do
705
+ retval = @layout.frame @layout.from_bottom_left()
706
+ retval.should == @view.frame
707
+ end
708
+ @view.frame.origin.x.should == 0
709
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
710
+ @view.frame.size.width.should == @view_size.width
711
+ @view.frame.size.height.should == @view_size.height
712
+ end
713
+
714
+ it 'should support setting the frame via `from_bottom_left(width:height:)`' do
715
+ @layout.context(@view) do
716
+ retval = @layout.frame @layout.from_bottom_left(width: 10, height: 20)
717
+ retval.should == @view.frame
718
+ end
719
+ @view.frame.origin.x.should == 0
720
+ @view.frame.origin.y.should == @superview_size.height - 20
721
+ @view.frame.size.width.should == 10
722
+ @view.frame.size.height.should == 20
723
+ end
724
+
725
+ it 'should support setting the frame via `from_bottom_left(x:y:width:height:)`' do
726
+ @layout.context(@view) do
727
+ retval = @layout.frame @layout.from_bottom_left(x: 10, y: 20, width: 22, height: 12)
728
+ retval.should == @view.frame
729
+ end
730
+ @view.frame.origin.x.should == 10
731
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
732
+ @view.frame.size.width.should == 22
733
+ @view.frame.size.height.should == 12
734
+ end
735
+
736
+ it 'should support setting the frame via `from_bottom_left(view)`' do
737
+ @layout.context(@view) do
738
+ retval = @layout.frame @layout.from_bottom_left(@another_view, x: 1, y: 1)
739
+ retval.should == @view.frame
740
+ end
741
+ @view.frame.origin.x.should == @another_view.frame.origin.x + 1
742
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
743
+ @view.frame.size.width.should == @view_size.width
744
+ @view.frame.size.height.should == @view_size.height
745
+ end
746
+
747
+ it 'should support setting the frame via `from_bottom`' do
748
+ @layout.context(@view) do
749
+ retval = @layout.frame @layout.from_bottom()
750
+ retval.should == @view.frame
751
+ end
752
+ @view.frame.origin.x.should == (@superview_size.width - @view_size.width) / 2
753
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
754
+ @view.frame.size.width.should == @view_size.width
755
+ @view.frame.size.height.should == @view_size.height
756
+ end
757
+
758
+ it 'should support setting the frame via `from_bottom(width:height:)`' do
759
+ @layout.context(@view) do
760
+ retval = @layout.frame @layout.from_bottom(width: 10, height: 20)
761
+ retval.should == @view.frame
762
+ end
763
+ @view.frame.origin.x.should == (@superview_size.width - 10) / 2
764
+ @view.frame.origin.y.should == @superview_size.height - 20
765
+ @view.frame.size.width.should == 10
766
+ @view.frame.size.height.should == 20
767
+ end
768
+
769
+ it 'should support setting the frame via `from_bottom(x:y:width:height:)`' do
770
+ @layout.context(@view) do
771
+ retval = @layout.frame @layout.from_bottom(x: 10, y: 20, width: 22, height: 12)
772
+ retval.should == @view.frame
773
+ end
774
+ @view.frame.origin.x.should == (@superview_size.width - 22) / 2 + 10
775
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
776
+ @view.frame.size.width.should == 22
777
+ @view.frame.size.height.should == 12
778
+ end
779
+
780
+ it 'should support setting the frame via `from_bottom(view)`' do
781
+ @layout.context(@view) do
782
+ retval = @layout.frame @layout.from_bottom(@another_view, x: 1, y: 1)
783
+ retval.should == @view.frame
784
+ end
785
+ @view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view_size.width) / 2 + 1
786
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
787
+ @view.frame.size.width.should == @view_size.width
788
+ @view.frame.size.height.should == @view_size.height
789
+ end
790
+
791
+ it 'should support setting the frame via `from_bottom_right`' do
792
+ @layout.context(@view) do
793
+ retval = @layout.frame @layout.from_bottom_right()
794
+ retval.should == @view.frame
795
+ end
796
+ @view.frame.origin.x.should == @superview_size.width - @view_size.width
797
+ @view.frame.origin.y.should == @superview_size.height - @view_size.height
798
+ @view.frame.size.width.should == @view_size.width
799
+ @view.frame.size.height.should == @view_size.height
800
+ end
801
+
802
+ it 'should support setting the frame via `from_bottom_right(width:height:)`' do
803
+ @layout.context(@view) do
804
+ retval = @layout.frame @layout.from_bottom_right(width: 10, height: 20)
805
+ retval.should == @view.frame
806
+ end
807
+ @view.frame.origin.x.should == @superview_size.width - 10
808
+ @view.frame.origin.y.should == @superview_size.height - 20
809
+ @view.frame.size.width.should == 10
810
+ @view.frame.size.height.should == 20
811
+ end
812
+
813
+ it 'should support setting the frame via `from_bottom_right(x:y:width:height:)`' do
814
+ @layout.context(@view) do
815
+ retval = @layout.frame @layout.from_bottom_right(x: 10, y: 20, width: 22, height: 12)
816
+ retval.should == @view.frame
817
+ end
818
+ @view.frame.origin.x.should == @superview_size.width - 22 + 10
819
+ @view.frame.origin.y.should == @superview_size.height - 12 + 20
820
+ @view.frame.size.width.should == 22
821
+ @view.frame.size.height.should == 12
822
+ end
823
+
824
+ it 'should support setting the frame via `from_bottom_right(view)`' do
825
+ @layout.context(@view) do
826
+ retval = @layout.frame @layout.from_bottom_right(@another_view, x: 1, y: 1)
827
+ retval.should == @view.frame
828
+ end
829
+ @view.frame.origin.x.should == @another_view.frame.origin.x + @another_view.frame.size.width - @view_size.width + 1
830
+ @view.frame.origin.y.should == @another_view.frame.origin.y + @another_view.frame.size.height - @view_size.height + 1
831
+ @view.frame.size.width.should == @view_size.width
832
+ @view.frame.size.height.should == @view_size.height
833
+ end
834
+
835
+ it 'should support setting the frame via `above(view)`' do
836
+ @layout.context(@view) do
837
+ retval = @layout.frame @layout.above(@another_view)
838
+ retval.should == @view.frame
839
+ end
840
+ @view.frame.origin.x.should == 10
841
+ @view.frame.origin.y.should == 90
842
+ @view.frame.size.width.should == @view_size.width
843
+ @view.frame.size.height.should == @view_size.height
844
+ end
845
+
846
+ it 'should support setting the frame via `above(view)` and ignore view origin' do
847
+ f = @view.frame
848
+ f.origin.x = 10
849
+ f.origin.y = 10
850
+ @view.frame = f
851
+
852
+ @layout.context(@view) do
853
+ retval = @layout.frame @layout.above(@another_view)
854
+ retval.should == @view.frame
855
+ end
856
+ @view.frame.origin.x.should == 10
857
+ @view.frame.origin.y.should == 90
858
+ @view.frame.size.width.should == @view_size.width
859
+ @view.frame.size.height.should == @view_size.height
860
+ end
861
+
862
+ it 'should support setting the frame via `above(view, up:)`' do
863
+ @layout.context(@view) do
864
+ retval = @layout.frame @layout.above(@another_view, up: 8)
865
+ retval.should == @view.frame
866
+ end
867
+ @view.frame.origin.x.should == 10
868
+ @view.frame.origin.y.should == 82
869
+ @view.frame.size.width.should == @view_size.width
870
+ @view.frame.size.height.should == @view_size.height
871
+ end
872
+
873
+ it 'should support setting the frame via `above(view, width:height:)`' do
874
+ @layout.context(@view) do
875
+ retval = @layout.frame @layout.above(@another_view, width: 10, height: 20)
876
+ retval.should == @view.frame
877
+ end
878
+ @view.frame.origin.x.should == 10
879
+ @view.frame.origin.y.should == 80
880
+ @view.frame.size.width.should == 10
881
+ @view.frame.size.height.should == 20
882
+ end
883
+
884
+ it 'should support setting the frame via `above(view, x:y:width:height:)`' do
885
+ @layout.context(@view) do
886
+ retval = @layout.frame @layout.above(@another_view, x: 10, y: 20, width: 22, height: 12)
887
+ retval.should == @view.frame
888
+ end
889
+ @view.frame.origin.x.should == 20
890
+ @view.frame.origin.y.should == 108
891
+ @view.frame.size.width.should == 22
892
+ @view.frame.size.height.should == 12
893
+ end
894
+
895
+ it 'should support setting the frame via `below(view)`' do
896
+ @layout.context(@view) do
897
+ retval = @layout.frame @layout.below(@another_view)
898
+ retval.should == @view.frame
899
+ end
900
+ @view.frame.origin.x.should == 10
901
+ @view.frame.origin.y.should == 148
902
+ @view.frame.size.width.should == @view_size.width
903
+ @view.frame.size.height.should == @view_size.height
904
+ end
905
+
906
+ it 'should support setting the frame via `below(view)` and ignore view origin' do
907
+ f = @view.frame
908
+ f.origin.x = 10
909
+ f.origin.y = 10
910
+ @view.frame = f
911
+
912
+ @layout.context(@view) do
913
+ retval = @layout.frame @layout.below(@another_view)
914
+ retval.should == @view.frame
915
+ end
916
+ @view.frame.origin.x.should == 10
917
+ @view.frame.origin.y.should == 148
918
+ @view.frame.size.width.should == @view_size.width
919
+ @view.frame.size.height.should == @view_size.height
920
+ end
921
+
922
+ it 'should support setting the frame via `below(view, down:)`' do
923
+ @layout.context(@view) do
924
+ retval = @layout.frame @layout.below(@another_view, down: 8)
925
+ retval.should == @view.frame
926
+ end
927
+ @view.frame.origin.x.should == 10
928
+ @view.frame.origin.y.should == 156
929
+ @view.frame.size.width.should == @view_size.width
930
+ @view.frame.size.height.should == @view_size.height
931
+ end
932
+
933
+ it 'should support setting the frame via `below(view, width:height:)`' do
934
+ @layout.context(@view) do
935
+ retval = @layout.frame @layout.below(@another_view, width: 10, height: 20)
936
+ retval.should == @view.frame
937
+ end
938
+ @view.frame.origin.x.should == 10
939
+ @view.frame.origin.y.should == 148
940
+ @view.frame.size.width.should == 10
941
+ @view.frame.size.height.should == 20
942
+ end
943
+
944
+ it 'should support setting the frame via `below(view, x:y:width:height:)`' do
945
+ @layout.context(@view) do
946
+ retval = @layout.frame @layout.below(@another_view, x: 10, y: 20, width: 22, height: 12)
947
+ retval.should == @view.frame
948
+ end
949
+ @view.frame.origin.x.should == 20
950
+ @view.frame.origin.y.should == 168
951
+ @view.frame.size.width.should == 22
952
+ @view.frame.size.height.should == 12
953
+ end
954
+
955
+ it 'should support setting the frame via `before(view)`' do
956
+ @layout.context(@view) do
957
+ retval = @layout.frame @layout.before(@another_view)
958
+ retval.should == @view.frame
959
+ end
960
+ @view.frame.origin.x.should == 2
961
+ @view.frame.origin.y.should == 100
962
+ @view.frame.size.width.should == @view_size.width
963
+ @view.frame.size.height.should == @view_size.height
964
+ end
965
+
966
+ it 'should support setting the frame via `before(view)` and ignore view origin' do
967
+ f = @view.frame
968
+ f.origin.x = 10
969
+ f.origin.y = 10
970
+ @view.frame = f
971
+
972
+ @layout.context(@view) do
973
+ retval = @layout.frame @layout.before(@another_view)
974
+ retval.should == @view.frame
975
+ end
976
+ @view.frame.origin.x.should == 2
977
+ @view.frame.origin.y.should == 100
978
+ @view.frame.size.width.should == @view_size.width
979
+ @view.frame.size.height.should == @view_size.height
980
+ end
981
+
982
+ it 'should support setting the frame via `before(view, left:)`' do
983
+ @layout.context(@view) do
984
+ retval = @layout.frame @layout.before(@another_view, left: 8)
985
+ retval.should == @view.frame
986
+ end
987
+ @view.frame.origin.x.should == -6
988
+ @view.frame.origin.y.should == 100
989
+ @view.frame.size.width.should == @view_size.width
990
+ @view.frame.size.height.should == @view_size.height
991
+ end
992
+
993
+ it 'should support setting the frame via `before(view, width:height:)`' do
994
+ @layout.context(@view) do
995
+ retval = @layout.frame @layout.before(@another_view, width: 10, height: 20)
996
+ retval.should == @view.frame
997
+ end
998
+ @view.frame.origin.x.should == 0
999
+ @view.frame.origin.y.should == 100
1000
+ @view.frame.size.width.should == 10
1001
+ @view.frame.size.height.should == 20
1002
+ end
1003
+
1004
+ it 'should support setting the frame via `before(view, x:y:width:height:)`' do
1005
+ @layout.context(@view) do
1006
+ retval = @layout.frame @layout.before(@another_view, x: 10, y: 20, width: 22, height: 12)
1007
+ retval.should == @view.frame
1008
+ end
1009
+ @view.frame.origin.x.should == -2
1010
+ @view.frame.origin.y.should == 120
1011
+ @view.frame.size.width.should == 22
1012
+ @view.frame.size.height.should == 12
1013
+ end
1014
+
1015
+ it 'should support setting the frame via `left_of(view)`' do
1016
+ before = nil
1017
+ left_of = nil
1018
+ @layout.context(@view) do
1019
+ before = @layout.before(@another_view)
1020
+ left_of = @layout.left_of(@another_view)
1021
+ end
1022
+ left_of.origin.x.should == before.origin.x
1023
+ left_of.origin.y.should == before.origin.y
1024
+ left_of.size.width.should == before.size.width
1025
+ left_of.size.height.should == before.size.height
1026
+ end
1027
+
1028
+ it 'should support setting the frame via `after(view)`' do
1029
+ @layout.context(@view) do
1030
+ retval = @layout.frame @layout.after(@another_view)
1031
+ retval.should == @view.frame
1032
+ end
1033
+ @view.frame.origin.x.should == 130
1034
+ @view.frame.origin.y.should == 100
1035
+ @view.frame.size.width.should == @view_size.width
1036
+ @view.frame.size.height.should == @view_size.height
1037
+ end
1038
+
1039
+ it 'should support setting the frame via `after(view)` and ignore view origin' do
1040
+ f = @view.frame
1041
+ f.origin.x = 10
1042
+ f.origin.y = 10
1043
+ @view.frame = f
1044
+
1045
+ @layout.context(@view) do
1046
+ retval = @layout.frame @layout.after(@another_view)
1047
+ retval.should == @view.frame
1048
+ end
1049
+ @view.frame.origin.x.should == 130
1050
+ @view.frame.origin.y.should == 100
1051
+ @view.frame.size.width.should == @view_size.width
1052
+ @view.frame.size.height.should == @view_size.height
1053
+ end
1054
+
1055
+ it 'should support setting the frame via `after(view, right:)`' do
1056
+ @layout.context(@view) do
1057
+ retval = @layout.frame @layout.after(@another_view, right: 8)
1058
+ retval.should == @view.frame
1059
+ end
1060
+ @view.frame.origin.x.should == 138
1061
+ @view.frame.origin.y.should == 100
1062
+ @view.frame.size.width.should == @view_size.width
1063
+ @view.frame.size.height.should == @view_size.height
1064
+ end
1065
+
1066
+ it 'should support setting the frame via `after(view, width:height:)`' do
1067
+ @layout.context(@view) do
1068
+ retval = @layout.frame @layout.after(@another_view, width: 10, height: 20)
1069
+ retval.should == @view.frame
1070
+ end
1071
+ @view.frame.origin.x.should == 130
1072
+ @view.frame.origin.y.should == 100
1073
+ @view.frame.size.width.should == 10
1074
+ @view.frame.size.height.should == 20
1075
+ end
1076
+
1077
+ it 'should support setting the frame via `after(view, x:y:width:height:)`' do
1078
+ @layout.context(@view) do
1079
+ retval = @layout.frame @layout.after(@another_view, x: 10, y: 20, width: 22, height: 12)
1080
+ retval.should == @view.frame
1081
+ end
1082
+ @view.frame.origin.x.should == 140
1083
+ @view.frame.origin.y.should == 120
1084
+ @view.frame.size.width.should == 22
1085
+ @view.frame.size.height.should == 12
1086
+ end
1087
+
1088
+ it 'should support setting the frame via `right_of(view)`' do
1089
+ after = nil
1090
+ right_of = nil
1091
+ @layout.context(@view) do
1092
+ after = @layout.after(@another_view)
1093
+ right_of = @layout.right_of(@another_view)
1094
+ end
1095
+ right_of.origin.x.should == after.origin.x
1096
+ right_of.origin.y.should == after.origin.y
1097
+ right_of.size.width.should == after.size.width
1098
+ right_of.size.height.should == after.size.height
1099
+ end
1100
+
1101
+ it 'should support setting the frame via `relative_to(view)`' do
1102
+ @layout.context(@view) do
1103
+ retval = @layout.frame @layout.relative_to(@another_view, {})
1104
+ retval.should == @view.frame
1105
+ end
1106
+ @view.frame.origin.x.should == 10
1107
+ @view.frame.origin.y.should == 100
1108
+ @view.frame.size.width.should == @view_size.width
1109
+ @view.frame.size.height.should == @view_size.height
1110
+ end
1111
+
1112
+ it 'should support setting the frame via `relative_to(view)` and ignore view origin' do
1113
+ f = @view.frame
1114
+ f.origin.x = 10
1115
+ f.origin.y = 10
1116
+ @view.frame = f
1117
+
1118
+ @layout.context(@view) do
1119
+ retval = @layout.frame @layout.relative_to(@another_view, {})
1120
+ retval.should == @view.frame
1121
+ end
1122
+ @view.frame.origin.x.should == 10
1123
+ @view.frame.origin.y.should == 100
1124
+ @view.frame.size.width.should == @view_size.width
1125
+ @view.frame.size.height.should == @view_size.height
1126
+ end
1127
+
1128
+ it 'should support setting the frame via `relative_to(view, width:height:)`' do
1129
+ @layout.context(@view) do
1130
+ retval = @layout.frame @layout.relative_to(@another_view, width: 10, height: 20)
1131
+ retval.should == @view.frame
1132
+ end
1133
+ @view.frame.origin.x.should == 10
1134
+ @view.frame.origin.y.should == 100
1135
+ @view.frame.size.width.should == 10
1136
+ @view.frame.size.height.should == 20
1137
+ end
1138
+
1139
+ it 'should support setting the frame via `relative_to(view, x:y:width:height:)`' do
1140
+ @layout.context(@view) do
1141
+ retval = @layout.frame @layout.relative_to(@another_view, x: 10, y: 20, width: 22, height: 12)
1142
+ retval.should == @view.frame
1143
+ end
1144
+ @view.frame.origin.x.should == 20
1145
+ @view.frame.origin.y.should == 120
1146
+ @view.frame.size.width.should == 22
1147
+ @view.frame.size.height.should == 12
1148
+ end
1149
+
1150
+ end