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,16 @@
1
+ class Object
2
+ attr_accessor :motion_kit_meta
3
+
4
+ def motion_kit_id=(element_id)
5
+ motion_kit_meta[:id] = element_id
6
+ end
7
+
8
+ def motion_kit_id
9
+ motion_kit_meta[:id]
10
+ end
11
+
12
+ def motion_kit_meta
13
+ @motion_kit_meta ||= {}
14
+ end
15
+
16
+ end
@@ -0,0 +1,20 @@
1
+ module MotionKit
2
+ module_function
3
+
4
+ def objective_c_method_name(str)
5
+ str.split('_').inject([]) { |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
6
+ end
7
+
8
+ def camel_case(str)
9
+ str.split('_').map(&:capitalize).join
10
+ end
11
+
12
+ def setter(method_name)
13
+ "set#{method_name[0].capitalize}#{method_name[1..-1]}:"
14
+ end
15
+
16
+ def appearance_class
17
+ @appearance_class ||= Class.new
18
+ end
19
+
20
+ end
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- Version = '0.0.1'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ describe "Layouts automatically apply styles" do
2
+
3
+ before do
4
+ @subject = TestApplyStyles.new
5
+ end
6
+
7
+ it "should call all style methods" do
8
+ @subject.view
9
+ @subject.did_call_logo.should == true
10
+ @subject.did_call_h1_label.should == true
11
+ @subject.did_call_label.should == true
12
+ end
13
+
14
+ it "should apply all styles" do
15
+ @subject.get(:logo).text.should == 'MK'
16
+ @subject.get(:label).text.should == ':label'
17
+ @subject.get(:label).font.pointSize.should == 16
18
+ @subject.get(:label).textColor.should == UIColor.blackColor
19
+ end
20
+
21
+ end
@@ -0,0 +1,224 @@
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_left' do
129
+ mask = nil
130
+ @layout.context(@view) do
131
+ mask = @layout.autoresizing_mask :fill_left
132
+ end
133
+ mask.should == UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin
134
+ end
135
+
136
+ it 'should support :fill_right' do
137
+ mask = nil
138
+ @layout.context(@view) do
139
+ mask = @layout.autoresizing_mask :fill_right
140
+ end
141
+ mask.should == UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin
142
+ end
143
+
144
+ it 'should support :pin_to_top_left' do
145
+ mask = nil
146
+ @layout.context(@view) do
147
+ mask = @layout.autoresizing_mask :pin_to_top_left
148
+ end
149
+ mask.should == UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
150
+ end
151
+
152
+ it 'should support :pin_to_top' do
153
+ mask = nil
154
+ @layout.context(@view) do
155
+ mask = @layout.autoresizing_mask :pin_to_top
156
+ end
157
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
158
+ end
159
+
160
+ it 'should support :pin_to_top_right' do
161
+ mask = nil
162
+ @layout.context(@view) do
163
+ mask = @layout.autoresizing_mask :pin_to_top_right
164
+ end
165
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin
166
+ end
167
+
168
+ it 'should support :pin_to_left' do
169
+ mask = nil
170
+ @layout.context(@view) do
171
+ mask = @layout.autoresizing_mask :pin_to_left
172
+ end
173
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
174
+ end
175
+
176
+ it 'should support :pin_to_center' do
177
+ mask = nil
178
+ @layout.context(@view) do
179
+ mask = @layout.autoresizing_mask :pin_to_center
180
+ end
181
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
182
+ end
183
+
184
+ it 'should support :pin_to_middle' do
185
+ mask = nil
186
+ @layout.context(@view) do
187
+ mask = @layout.autoresizing_mask :pin_to_middle
188
+ end
189
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
190
+ end
191
+
192
+ it 'should support :pin_to_right' do
193
+ mask = nil
194
+ @layout.context(@view) do
195
+ mask = @layout.autoresizing_mask :pin_to_right
196
+ end
197
+ mask.should == UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin
198
+ end
199
+
200
+ it 'should support :pin_to_bottom_left' do
201
+ mask = nil
202
+ @layout.context(@view) do
203
+ mask = @layout.autoresizing_mask :pin_to_bottom_left
204
+ end
205
+ mask.should == UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
206
+ end
207
+
208
+ it 'should support :pin_to_bottom' do
209
+ mask = nil
210
+ @layout.context(@view) do
211
+ mask = @layout.autoresizing_mask :pin_to_bottom
212
+ end
213
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
214
+ end
215
+
216
+ it 'should support :pin_to_bottom_right' do
217
+ mask = nil
218
+ @layout.context(@view) do
219
+ mask = @layout.autoresizing_mask :pin_to_bottom_right
220
+ end
221
+ mask.should == UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin
222
+ end
223
+
224
+ 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