motion-kit 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/motion-kit-tvos/deprecated.rb +31 -0
  4. data/lib/motion-kit-tvos/dummy.rb +93 -0
  5. data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
  6. data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
  7. data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
  8. data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
  9. data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
  10. data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
  11. data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
  12. data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
  13. data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
  14. data/lib/motion-kit-tvos/ios_util.rb +24 -0
  15. data/lib/motion-kit.rb +2 -0
  16. data/lib/motion-kit/version.rb +1 -1
  17. data/spec/tvos/apply_styles_spec.rb +37 -0
  18. data/spec/tvos/autoresizing_helper_spec.rb +240 -0
  19. data/spec/tvos/calayer_spec.rb +23 -0
  20. data/spec/tvos/calculate_spec.rb +322 -0
  21. data/spec/tvos/calculator_spec.rb +31 -0
  22. data/spec/tvos/child_layouts_spec.rb +65 -0
  23. data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
  24. data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
  25. data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
  26. data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
  27. data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  28. data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
  29. data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
  30. data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
  31. data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
  32. data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
  33. data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
  34. data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
  35. data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
  36. data/spec/tvos/create_layout_spec.rb +40 -0
  37. data/spec/tvos/custom_layout_spec.rb +13 -0
  38. data/spec/tvos/custom_root_layout_spec.rb +57 -0
  39. data/spec/tvos/deferred_spec.rb +89 -0
  40. data/spec/tvos/device_helpers_spec.rb +58 -0
  41. data/spec/tvos/frame_helper_spec.rb +1160 -0
  42. data/spec/tvos/layer_layout_spec.rb +36 -0
  43. data/spec/tvos/layout_extensions_spec.rb +70 -0
  44. data/spec/tvos/layout_spec.rb +57 -0
  45. data/spec/tvos/layout_state_spec.rb +27 -0
  46. data/spec/tvos/memory_leak_spec.rb +74 -0
  47. data/spec/tvos/motion_kit_id_spec.rb +15 -0
  48. data/spec/tvos/motionkit_util_spec.rb +15 -0
  49. data/spec/tvos/nearest_spec.rb +80 -0
  50. data/spec/tvos/objc_selectors_spec.rb +10 -0
  51. data/spec/tvos/orientation_helper_specs.rb +67 -0
  52. data/spec/tvos/parent_layout_spec.rb +19 -0
  53. data/spec/tvos/parent_spec.rb +45 -0
  54. data/spec/tvos/prev_next_spec.rb +153 -0
  55. data/spec/tvos/reapply_frame.rb +64 -0
  56. data/spec/tvos/relative_layout.spec.rb +31 -0
  57. data/spec/tvos/remove_layout_spec.rb +28 -0
  58. data/spec/tvos/root_layout_spec.rb +53 -0
  59. data/spec/tvos/setters_spec.rb +63 -0
  60. data/spec/tvos/uibutton_layout_spec.rb +37 -0
  61. data/spec/tvos/uitextfield_spec.rb +14 -0
  62. data/spec/tvos/view_attr_spec.rb +32 -0
  63. metadata +118 -8
@@ -0,0 +1,37 @@
1
+ describe "Layouts automatically apply styles" do
2
+
3
+ before do
4
+ @subject = TestApplyStyles.new.build
5
+ end
6
+
7
+ describe "should call all style methods" do
8
+ {
9
+ logo: -> { @subject.did_call_logo },
10
+ h1_label: -> { @subject.did_call_h1_label },
11
+ label: -> { @subject.did_call_label },
12
+ }.each do |name, condition|
13
+ it "should call #{name} style method" do
14
+ condition.call.should == true
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "should apply all styles" do
20
+ it 'should style :logo' do
21
+ @subject.get(:logo).text.should == 'MK'
22
+ end
23
+ it 'should style :label' do
24
+ @subject.get(:label).text.should == ':label'
25
+ end
26
+ it 'should style :label' do
27
+ @subject.get(:label).numberOfLines.should == 2
28
+ end
29
+ it 'should style :label' do
30
+ @subject.get(:label).font.pointSize.should == 16
31
+ end
32
+ it 'should style :label' do
33
+ @subject.get(:label).textColor.should == UIColor.blackColor
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,240 @@
1
+ describe 'Autoresize helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @view = UIView.alloc.initWithFrame([[0, 0], [10, 10]])
6
+ end
7
+
8
+ it 'should support :flexible_left' do
9
+ mask = nil
10
+ @layout.context(@view) do
11
+ mask = @layout.autoresizing_mask :flexible_left
12
+ end
13
+ mask.should == UIViewAutoresizingFlexibleLeftMargin
14
+ end
15
+
16
+ it 'should support :flexible_width' do
17
+ mask = nil
18
+ @layout.context(@view) do
19
+ mask = @layout.autoresizing_mask :flexible_width
20
+ end
21
+ mask.should == UIViewAutoresizingFlexibleWidth
22
+ end
23
+
24
+ it 'should support :flexible_right' do
25
+ mask = nil
26
+ @layout.context(@view) do
27
+ mask = @layout.autoresizing_mask :flexible_right
28
+ end
29
+ mask.should == UIViewAutoresizingFlexibleRightMargin
30
+ end
31
+
32
+ it 'should support :flexible_top' do
33
+ mask = nil
34
+ @layout.context(@view) do
35
+ mask = @layout.autoresizing_mask :flexible_top
36
+ end
37
+ mask.should == UIViewAutoresizingFlexibleTopMargin
38
+ end
39
+
40
+ it 'should support :flexible_height' do
41
+ mask = nil
42
+ @layout.context(@view) do
43
+ mask = @layout.autoresizing_mask :flexible_height
44
+ end
45
+ mask.should == UIViewAutoresizingFlexibleHeight
46
+ end
47
+
48
+ it 'should support :flexible_bottom' do
49
+ mask = nil
50
+ @layout.context(@view) do
51
+ mask = @layout.autoresizing_mask :flexible_bottom
52
+ end
53
+ mask.should == UIViewAutoresizingFlexibleBottomMargin
54
+ end
55
+
56
+ it 'should support :rigid_left' do
57
+ mask = nil
58
+ @layout.context(@view) do
59
+ mask = @layout.autoresizing_mask :flexible_right, :flexible_left, :rigid_left
60
+ end
61
+ mask.should == UIViewAutoresizingFlexibleRightMargin
62
+ end
63
+
64
+ it 'should support :rigid_width' do
65
+ mask = nil
66
+ @layout.context(@view) do
67
+ mask = @layout.autoresizing_mask :flexible_height, :flexible_width, :rigid_width
68
+ end
69
+ mask.should == UIViewAutoresizingFlexibleHeight
70
+ end
71
+
72
+ it 'should support :rigid_right' do
73
+ mask = nil
74
+ @layout.context(@view) do
75
+ mask = @layout.autoresizing_mask :flexible_left, :flexible_right, :rigid_right
76
+ end
77
+ mask.should == UIViewAutoresizingFlexibleLeftMargin
78
+ end
79
+
80
+ it 'should support :rigid_top' do
81
+ mask = nil
82
+ @layout.context(@view) do
83
+ mask = @layout.autoresizing_mask :flexible_bottom, :flexible_top, :rigid_top
84
+ end
85
+ mask.should == UIViewAutoresizingFlexibleBottomMargin
86
+ end
87
+
88
+ it 'should support :rigid_height' do
89
+ mask = nil
90
+ @layout.context(@view) do
91
+ mask = @layout.autoresizing_mask :flexible_width, :flexible_height, :rigid_height
92
+ end
93
+ mask.should == UIViewAutoresizingFlexibleWidth
94
+ end
95
+
96
+ it 'should support :rigid_bottom' do
97
+ mask = nil
98
+ @layout.context(@view) do
99
+ mask = @layout.autoresizing_mask :flexible_top, :flexible_bottom, :rigid_bottom
100
+ end
101
+ mask.should == UIViewAutoresizingFlexibleTopMargin
102
+ end
103
+
104
+ it 'should support :fill' do
105
+ mask = nil
106
+ @layout.context(@view) do
107
+ mask = @layout.autoresizing_mask :fill
108
+ end
109
+ mask.should == UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
110
+ end
111
+
112
+ it 'should support :fill_top' do
113
+ mask = nil
114
+ @layout.context(@view) do
115
+ mask = @layout.autoresizing_mask :fill_top
116
+ end
117
+ mask.should == UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
118
+ end
119
+
120
+ it 'should support :fill_bottom' do
121
+ mask = nil
122
+ @layout.context(@view) do
123
+ mask = @layout.autoresizing_mask :fill_bottom
124
+ end
125
+ mask.should == UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin
126
+ end
127
+
128
+ it 'should support :fill_width' do
129
+ mask = nil
130
+ @layout.context(@view) do
131
+ mask = @layout.autoresizing_mask :fill_width
132
+ end
133
+ mask.should == UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
134
+ end
135
+
136
+ it 'should support :fill_left' do
137
+ mask = nil
138
+ @layout.context(@view) do
139
+ mask = @layout.autoresizing_mask :fill_left
140
+ end
141
+ mask.should == UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin
142
+ end
143
+
144
+ it 'should support :fill_right' do
145
+ mask = nil
146
+ @layout.context(@view) do
147
+ mask = @layout.autoresizing_mask :fill_right
148
+ end
149
+ mask.should == UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin
150
+ end
151
+
152
+ it 'should support :fill_height' do
153
+ mask = nil
154
+ @layout.context(@view) do
155
+ mask = @layout.autoresizing_mask :fill_height
156
+ end
157
+ mask.should == UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
158
+ end
159
+
160
+ it 'should support :pin_to_top_left' do
161
+ mask = nil
162
+ @layout.context(@view) do
163
+ mask = @layout.autoresizing_mask :pin_to_top_left
164
+ end
165
+ mask.should == UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
166
+ end
167
+
168
+ it 'should support :pin_to_top' do
169
+ mask = nil
170
+ @layout.context(@view) do
171
+ mask = @layout.autoresizing_mask :pin_to_top
172
+ end
173
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
174
+ end
175
+
176
+ it 'should support :pin_to_top_right' do
177
+ mask = nil
178
+ @layout.context(@view) do
179
+ mask = @layout.autoresizing_mask :pin_to_top_right
180
+ end
181
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin
182
+ end
183
+
184
+ it 'should support :pin_to_left' do
185
+ mask = nil
186
+ @layout.context(@view) do
187
+ mask = @layout.autoresizing_mask :pin_to_left
188
+ end
189
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
190
+ end
191
+
192
+ it 'should support :pin_to_center' do
193
+ mask = nil
194
+ @layout.context(@view) do
195
+ mask = @layout.autoresizing_mask :pin_to_center
196
+ end
197
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
198
+ end
199
+
200
+ it 'should support :pin_to_middle' do
201
+ mask = nil
202
+ @layout.context(@view) do
203
+ mask = @layout.autoresizing_mask :pin_to_middle
204
+ end
205
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
206
+ end
207
+
208
+ it 'should support :pin_to_right' do
209
+ mask = nil
210
+ @layout.context(@view) do
211
+ mask = @layout.autoresizing_mask :pin_to_right
212
+ end
213
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin
214
+ end
215
+
216
+ it 'should support :pin_to_bottom_left' do
217
+ mask = nil
218
+ @layout.context(@view) do
219
+ mask = @layout.autoresizing_mask :pin_to_bottom_left
220
+ end
221
+ mask.should == UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
222
+ end
223
+
224
+ it 'should support :pin_to_bottom' do
225
+ mask = nil
226
+ @layout.context(@view) do
227
+ mask = @layout.autoresizing_mask :pin_to_bottom
228
+ end
229
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
230
+ end
231
+
232
+ it 'should support :pin_to_bottom_right' do
233
+ mask = nil
234
+ @layout.context(@view) do
235
+ mask = @layout.autoresizing_mask :pin_to_bottom_right
236
+ end
237
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin
238
+ end
239
+
240
+ end
@@ -0,0 +1,23 @@
1
+ describe 'CALayerHelpers' do
2
+
3
+ before do
4
+ @subject = TestCALayerLayout.new.build
5
+ end
6
+
7
+ describe 'should style a CALayer' do
8
+ describe 'should style :gradient layer' do
9
+ it 'should set the frame' do
10
+ @subject.get(:gradient).frame.should == CGRectMake(0, 0, 20, 20)
11
+ end
12
+ it 'should set the colors' do
13
+ @subject.get(:gradient).colors.length.should == 2
14
+ end
15
+ end
16
+ describe 'should style :bottom layer' do
17
+ it 'should set the frame' do
18
+ @subject.get(:bottom).frame.should == CGRectMake(0, 20, 20, 10)
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,322 @@
1
+ class Viewish
2
+ def superview
3
+ @superview ||= Viewish.new
4
+ end
5
+
6
+ def frame
7
+ @frame
8
+ end
9
+
10
+ def initialize(size=nil)
11
+ size ||= [100, 44]
12
+ @frame = CGRect.new([10, 10], size)
13
+ end
14
+
15
+ def intrinsicContentSize
16
+ CGSize.new(80, 20)
17
+ end
18
+ end
19
+
20
+
21
+ describe 'MotionKit.calculate' do
22
+
23
+ it 'should return static numbers' do
24
+ MotionKit.calculate(nil, nil, 1).should == 1
25
+ end
26
+
27
+ it 'should call blocks' do
28
+ a = 'hi!'
29
+ MotionKit.calculate(a, nil, ->{
30
+ self.should == a
31
+ 2
32
+ }).should == 2
33
+ end
34
+
35
+ it 'should return percents with :width' do
36
+ MotionKit.calculate(Viewish.new, :width, '50%').should == 50
37
+ end
38
+
39
+ it 'should return percents with :height' do
40
+ MotionKit.calculate(Viewish.new, :height, '50%').should == 22
41
+ end
42
+
43
+ it 'should return :auto with :width' do
44
+ MotionKit.calculate(Viewish.new, :width, :auto).should == 80
45
+ end
46
+
47
+ it 'should return :auto with :height' do
48
+ MotionKit.calculate(Viewish.new, :height, :auto).should == 20
49
+ end
50
+
51
+ describe 'should return percents with offset' do
52
+ it ':width, 50% + 10' do
53
+ MotionKit.calculate(Viewish.new, :width, '50% + 10').should == 60
54
+ end
55
+ it ':width, 50% - 10' do
56
+ MotionKit.calculate(Viewish.new, :width, '50% - 10').should == 40
57
+ end
58
+ it ':width, 25% + 5' do
59
+ MotionKit.calculate(Viewish.new, :width, '25% + 5').should == 30
60
+ end
61
+ it ':height, 50% + 10' do
62
+ MotionKit.calculate(Viewish.new, :height, '50% + 10').should == 32
63
+ end
64
+ it ':height, 50% - 10' do
65
+ MotionKit.calculate(Viewish.new, :height, '50% - 10').should == 12
66
+ end
67
+ it ':height, 25% + 5' do
68
+ MotionKit.calculate(Viewish.new, :height, '25% + 5').should == 16
69
+ end
70
+ end
71
+
72
+ describe 'should return point with :origin' do
73
+ it 'should support two numbers' do
74
+ pt = MotionKit.calculate(Viewish.new, :origin, [10, 20])
75
+ pt.x.should == 10
76
+ pt.y.should == 20
77
+ end
78
+
79
+ it 'should support a point' do
80
+ pt = MotionKit.calculate(Viewish.new, :origin, CGPoint.new(10, 20))
81
+ pt.x.should == 10
82
+ pt.y.should == 20
83
+ end
84
+
85
+ it 'should support {:x, :y}' do
86
+ pt = MotionKit.calculate(Viewish.new, :origin, {x: 10, y: 20})
87
+ pt.x.should == 10
88
+ pt.y.should == 20
89
+ end
90
+
91
+ it 'should support {:left, :top}' do
92
+ pt = MotionKit.calculate(Viewish.new, :origin, {left: 10, top: 20})
93
+ pt.x.should == 10
94
+ pt.y.should == 20
95
+ end
96
+
97
+ it 'should support x as percent' do
98
+ pt = MotionKit.calculate(Viewish.new, :origin, ['10%', 20])
99
+ pt.x.should == 10
100
+ pt.y.should == 20
101
+ end
102
+
103
+ it 'should support y as percent' do
104
+ pt = MotionKit.calculate(Viewish.new, :origin, [10, '50%'])
105
+ pt.x.should == 10
106
+ pt.y.should == 22
107
+ end
108
+
109
+ it 'should support two percents' do
110
+ pt = MotionKit.calculate(Viewish.new, :origin, ['50%', '50%'])
111
+ pt.x.should == 50
112
+ pt.y.should == 22
113
+ end
114
+
115
+ it 'should support {:right, :bottom}' do
116
+ pt = MotionKit.calculate(Viewish.new([10, 10]), :origin, {right: '100%', bottom: '100%'})
117
+ pt.x.should == 90
118
+ pt.y.should == 34
119
+ end
120
+
121
+ it 'should support {:right, :bottom} with offsets' do
122
+ pt = MotionKit.calculate(Viewish.new([10, 10]), :origin, {right: '100%-8', bottom: '100%-8'})
123
+ pt.x.should == 82
124
+ pt.y.should == 26
125
+ end
126
+
127
+ it 'should support two percents with offsets' do
128
+ pt = MotionKit.calculate(Viewish.new, :origin, ['50%-10', '50%-10'])
129
+ pt.x.should == 40
130
+ pt.y.should == 12
131
+ end
132
+ end
133
+
134
+ describe 'should return size with :size' do
135
+
136
+ it 'should support two numbers' do
137
+ size = MotionKit.calculate(Viewish.new, :size, [10, 20])
138
+ size.width.should == 10
139
+ size.height.should == 20
140
+ end
141
+
142
+ it 'should support a point' do
143
+ size = MotionKit.calculate(Viewish.new, :size, CGSize.new(10, 20))
144
+ size.width.should == 10
145
+ size.height.should == 20
146
+ end
147
+
148
+ it 'should support {:w, :h}' do
149
+ size = MotionKit.calculate(Viewish.new, :size, {w: 10, h: 20})
150
+ size.width.should == 10
151
+ size.height.should == 20
152
+ end
153
+
154
+ it 'should support {:width, :height}' do
155
+ size = MotionKit.calculate(Viewish.new, :size, {width: 10, height: 20})
156
+ size.width.should == 10
157
+ size.height.should == 20
158
+ end
159
+
160
+ it 'should support width as percent' do
161
+ size = MotionKit.calculate(Viewish.new, :size, ['10%', 20])
162
+ size.width.should == 10
163
+ size.height.should == 20
164
+ end
165
+
166
+ it 'should support height as percent' do
167
+ size = MotionKit.calculate(Viewish.new, :size, [10, '50%'])
168
+ size.width.should == 10
169
+ size.height.should == 22
170
+ end
171
+
172
+ it 'should support two percents' do
173
+ size = MotionKit.calculate(Viewish.new, :size, ['50%', '50%'])
174
+ size.width.should == 50
175
+ size.height.should == 22
176
+ end
177
+
178
+ it 'should support two percents with offsets' do
179
+ size = MotionKit.calculate(Viewish.new, :size, ['50%-10', '50%-10'])
180
+ size.width.should == 40
181
+ size.height.should == 12
182
+ end
183
+
184
+ it 'should support :auto' do
185
+ size = MotionKit.calculate(Viewish.new, :size, :auto)
186
+ size.width.should == 80
187
+ size.height.should == 20
188
+ end
189
+
190
+ it 'should support :full' do
191
+ size = MotionKit.calculate(Viewish.new, :size, :full)
192
+ size.width.should == 100
193
+ size.height.should == 44
194
+ end
195
+
196
+ it 'should support :scale width' do
197
+ size = MotionKit.calculate(Viewish.new, :size, [:scale, 40])
198
+ size.width.should == 160
199
+ size.height.should == 40
200
+ end
201
+
202
+ it 'should support :scale width, :auto height' do
203
+ size = MotionKit.calculate(Viewish.new, :size, [:scale, :auto])
204
+ size.width.should == 80
205
+ size.height.should == 20
206
+ end
207
+
208
+ it 'should support :scale height' do
209
+ size = MotionKit.calculate(Viewish.new, :size, [40, :scale])
210
+ size.width.should == 40
211
+ size.height.should == 10
212
+ end
213
+
214
+ it 'should support :scale height, :auto width' do
215
+ size = MotionKit.calculate(Viewish.new, :size, [:auto, :scale])
216
+ size.width.should == 80
217
+ size.height.should == 20
218
+ end
219
+
220
+ end
221
+
222
+ describe 'should return frame with :frame' do
223
+
224
+ it 'should support four numbers [[a, b], [c, d]]' do
225
+ frame = MotionKit.calculate(Viewish.new, :frame, [[10, 20], [30, 40]])
226
+ frame.origin.x.should == 10
227
+ frame.origin.y.should == 20
228
+ frame.size.width.should == 30
229
+ frame.size.height.should == 40
230
+ end
231
+
232
+ it 'should support four numbers [a, b, c, d]' do
233
+ frame = MotionKit.calculate(Viewish.new, :frame, [10, 20, 30, 40])
234
+ frame.origin.x.should == 10
235
+ frame.origin.y.should == 20
236
+ frame.size.width.should == 30
237
+ frame.size.height.should == 40
238
+ end
239
+
240
+ it 'should support a point and a size' do
241
+ frame = MotionKit.calculate(Viewish.new, :frame, [CGPoint.new(10, 20), CGSize.new(30, 40)])
242
+ frame.origin.x.should == 10
243
+ frame.origin.y.should == 20
244
+ frame.size.width.should == 30
245
+ frame.size.height.should == 40
246
+ end
247
+
248
+ it 'should support {:x, :y, :w, :h}' do
249
+ frame = MotionKit.calculate(Viewish.new, :frame, {x: 10, y: 20, w: 30, h: 40})
250
+ frame.origin.x.should == 10
251
+ frame.origin.y.should == 20
252
+ frame.size.width.should == 30
253
+ frame.size.height.should == 40
254
+ end
255
+
256
+ it 'should support {:left, :top, :width, :height}' do
257
+ frame = MotionKit.calculate(Viewish.new, :frame, {left: 10, top: 20, width: 30, height: 40})
258
+ frame.origin.x.should == 10
259
+ frame.origin.y.should == 20
260
+ frame.size.width.should == 30
261
+ frame.size.height.should == 40
262
+ end
263
+
264
+ it 'should support four percents' do
265
+ frame = MotionKit.calculate(Viewish.new, :frame, [['25%', '25%'], ['50%', '50%']])
266
+ frame.origin.x.should == 25
267
+ frame.origin.y.should == 11
268
+ frame.size.width.should == 50
269
+ frame.size.height.should == 22
270
+ end
271
+
272
+ it 'should support four percents with offsets' do
273
+ frame = MotionKit.calculate(Viewish.new, :frame, [['25%-10', '25%-10'], ['50%+20', '50%+20']])
274
+ frame.origin.x.should == 15
275
+ frame.origin.y.should == 1
276
+ frame.size.width.should == 70
277
+ frame.size.height.should == 42
278
+ end
279
+
280
+ it 'should support :auto' do
281
+ frame = MotionKit.calculate(Viewish.new, :frame, :auto)
282
+ frame.origin.x.should == 0
283
+ frame.origin.y.should == 0
284
+ frame.size.width.should == 80
285
+ frame.size.height.should == 20
286
+ end
287
+
288
+ it 'should support :full' do
289
+ frame = MotionKit.calculate(Viewish.new, :frame, :full)
290
+ frame.origin.x.should == 0
291
+ frame.origin.y.should == 0
292
+ frame.size.width.should == 100
293
+ frame.size.height.should == 44
294
+ end
295
+
296
+ it 'should support :center' do
297
+ frame = MotionKit.calculate(Viewish.new([50, 22]), :frame, :center)
298
+ frame.origin.x.should == 25
299
+ frame.origin.y.should == 11
300
+ frame.size.width.should == 50
301
+ frame.size.height.should == 22
302
+ end
303
+
304
+ it 'should support [:center, :auto]' do
305
+ frame = MotionKit.calculate(Viewish.new, :frame, [:center, :auto])
306
+ frame.origin.x.should == 10
307
+ frame.origin.y.should == 12
308
+ frame.size.width.should == 80
309
+ frame.size.height.should == 20
310
+ end
311
+
312
+ it 'should support :scale' do
313
+ frame = MotionKit.calculate(Viewish.new, :frame, [:center, [:scale, 40]])
314
+ frame.origin.x.should == -30
315
+ frame.origin.y.should == 2
316
+ frame.size.width.should == 160
317
+ frame.size.height.should == 40
318
+ end
319
+
320
+ end
321
+
322
+ end