geomotion 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geomotion (0.13.0)
4
+ geomotion (0.13.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -191,20 +191,27 @@ frame.bottom_right(true) # => [20, 20]
191
191
 
192
192
  #### The great and powerful `apply` method
193
193
 
194
+ Most of the frame-manipulation methods delegate to the `apply` method. You can
195
+ use this method to perform batch changes.
196
+
197
+ ```ruby
198
+ frame = view.frame.apply(left: 10, y: 0, wider: 50, grow_height: 10)
199
+ ```
200
+
194
201
  All of the methods that return a new frame (`left, shrink, below` and friends)
195
202
  also accept a hash in which you can apply more changes. You can accomplish the
196
203
  same thing using method chaining; this is an implementation detail that might
197
- also clean your code up by grouping changes. And, of course, it can be used on
198
- its own as well.
204
+ also clean your code up by grouping changes.
199
205
 
200
206
  ```ruby
201
207
  frame = CGRect.make(x: 10, y: 10, width:10, height: 10)
202
208
  frame.beside.width(20).down(10).height(20)
203
209
  # => [[20, 20], [20, 20]]
204
- # or, using the options hash
210
+
211
+ # using the options hash / apply method
205
212
  frame.beside(width: 20, down: 10, height: 20)
213
+ # => [[20, 20], [20, 20]]
206
214
 
207
- # there are some changes that don't have a corresponding method:
208
215
  frame.below(grow_width: 10, grow_up: 5)
209
216
  # => [[0, 15], [40, 25]]
210
217
  ```
@@ -191,15 +191,15 @@ class CGRect
191
191
  rect.size.width -= value
192
192
  rect.origin.x += value
193
193
  when :grow_width
194
- rect = rect.grow([value, 0])
194
+ rect = rect.grow_width(value)
195
195
  when :grow_height
196
- rect = rect.grow([0, value])
196
+ rect = rect.grow_height(value)
197
197
  when :shrink
198
198
  rect = rect.shrink(value)
199
199
  when :shrink_width
200
- rect = rect.shrink([value, 0])
200
+ rect = rect.shrink_width(value)
201
201
  when :shrink_height
202
- rect = rect.shrink([0, value])
202
+ rect = rect.shrink_height(value)
203
203
  when :offset
204
204
  rect = rect.offset(value)
205
205
  else
@@ -210,65 +210,105 @@ class CGRect
210
210
  end
211
211
 
212
212
  # modified rects
213
- def left(dist = 0, options={})
213
+ def left(dist=nil, options={})
214
+ if dist.nil?
215
+ NSLog("Using the default value of `0` in `CGRect#left` is deprecated.")
216
+ dist = 0
217
+ end
218
+ raise "You must specify an amount in `CGRect#left`" unless dist.is_a?(Numeric)
219
+
214
220
  options[:left] = dist
215
221
  self.apply(options)
216
222
  end
217
223
 
218
- def right(dist = 0, options={})
224
+ def right(dist=nil, options={})
225
+ if dist.nil?
226
+ NSLog("Using the default value of `0` in `CGRect#right` is deprecated.")
227
+ dist = 0
228
+ end
229
+ raise "You must specify an amount in `CGRect#right`" unless dist.is_a?(Numeric)
230
+
219
231
  options[:right] = dist
220
232
  self.apply(options)
221
233
  end
222
234
 
223
- def up(dist = 0, options={})
235
+ def up(dist=nil, options={})
236
+ if dist.nil?
237
+ NSLog("Using the default value of `0` in `CGRect#up` is deprecated.")
238
+ dist = 0
239
+ end
240
+ raise "You must specify an amount in `CGRect#up`" unless dist.is_a?(Numeric)
241
+
224
242
  options[:up] = dist
225
243
  self.apply(options)
226
244
  end
227
245
 
228
- def down(dist = 0, options={})
246
+ def down(dist=nil, options={})
247
+ if dist.nil?
248
+ NSLog("Using the default value of `0` in `CGRect#down` is deprecated.")
249
+ dist = 0
250
+ end
251
+ raise "You must specify an amount in `CGRect#down`" unless dist.is_a?(Numeric)
252
+
229
253
  options[:down] = dist
230
254
  self.apply(options)
231
255
  end
232
256
 
233
257
  def wider(dist, options={})
258
+ raise "You must specify an amount in `CGRect#wider`" unless dist.is_a?(Numeric)
259
+
234
260
  options[:wider] = dist
235
261
  self.apply(options)
236
262
  end
237
263
 
238
264
  def thinner(dist, options={})
265
+ raise "You must specify an amount in `CGRect#thinner`" unless dist.is_a?(Numeric)
266
+
239
267
  options[:thinner] = dist
240
268
  self.apply(options)
241
269
  end
242
270
 
243
271
  def taller(dist, options={})
272
+ raise "You must specify an amount in `CGRect#taller`" unless dist.is_a?(Numeric)
273
+
244
274
  options[:taller] = dist
245
275
  self.apply(options)
246
276
  end
247
277
 
248
278
  def shorter(dist, options={})
279
+ raise "You must specify an amount in `CGRect#shorter`" unless dist.is_a?(Numeric)
280
+
249
281
  options[:shorter] = dist
250
282
  self.apply(options)
251
283
  end
252
284
 
253
285
  # adjacent rects
254
286
  def above(margin = 0, options={})
287
+ margin, options = 0, margin if margin.is_a?(NSDictionary)
288
+
255
289
  height = options[:height] || self.size.height
256
290
  options[:up] = height + margin
257
291
  self.apply(options)
258
292
  end
259
293
 
260
294
  def below(margin = 0, options={})
295
+ margin, options = 0, margin if margin.is_a?(NSDictionary)
296
+
261
297
  options[:down] = self.size.height + margin
262
298
  self.apply(options)
263
299
  end
264
300
 
265
301
  def before(margin = 0, options={})
302
+ margin, options = 0, margin if margin.is_a?(NSDictionary)
303
+
266
304
  width = options[:width] || self.size.width
267
305
  options[:left] = width + margin
268
306
  self.apply(options)
269
307
  end
270
308
 
271
309
  def beside(margin = 0, options={})
310
+ margin, options = 0, margin if margin.is_a?(NSDictionary)
311
+
272
312
  options[:right] = self.size.width + margin
273
313
  self.apply(options)
274
314
  end
@@ -395,6 +435,30 @@ public
395
435
  return rect
396
436
  end
397
437
 
438
+ alias grow_right wider
439
+ def grow_left(amount, options=nil)
440
+ raise "You must specify an amount in `CGRect#grow_left`" unless amount.is_a?(Numeric)
441
+
442
+ options[:grow_left] = amount
443
+ self.apply(options)
444
+ end
445
+
446
+ alias grow_down taller
447
+ def grow_up(amount, options=nil)
448
+ raise "You must specify an amount in `CGRect#grow_up`" unless amount.is_a?(Numeric)
449
+
450
+ options[:grow_up] = amount
451
+ self.apply(options)
452
+ end
453
+
454
+ def grow_width(amount, options=nil)
455
+ return self.grow([amount, 0], options)
456
+ end
457
+
458
+ def grow_height(amount, options=nil)
459
+ return self.grow([0, amount], options)
460
+ end
461
+
398
462
  def shrink(size, options=nil)
399
463
  if size.is_a? Numeric
400
464
  size = CGSize.new(size, size)
@@ -406,6 +470,30 @@ public
406
470
  return rect
407
471
  end
408
472
 
473
+ alias shrink_left thinner
474
+ def shrink_right(amount, options={})
475
+ raise "You must specify an amount in `CGRect#shrink_right`" unless amount.is_a?(Numeric)
476
+
477
+ options[:shrink_right] = amount
478
+ self.apply(options)
479
+ end
480
+
481
+ alias shrink_up shorter
482
+ def shrink_down(amount, options={})
483
+ raise "You must specify an amount in `CGRect#shrink_down`" unless amount.is_a?(Numeric)
484
+
485
+ options[:shrink_down] = amount
486
+ self.apply(options)
487
+ end
488
+
489
+ def shrink_width(amount, options={})
490
+ return self.shrink([amount, 0], options)
491
+ end
492
+
493
+ def shrink_height(amount, options={})
494
+ return self.shrink([0, amount], options)
495
+ end
496
+
409
497
  def empty?
410
498
  CGRectIsEmpty(self)
411
499
  end
@@ -1,3 +1,3 @@
1
1
  module Geomotion
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.1"
3
3
  end
@@ -288,10 +288,15 @@ describe "CGRect" do
288
288
 
289
289
  describe "#left" do
290
290
  it "works" do
291
- rect = CGRect.empty
292
- rect = rect.left(20)
291
+ rect = CGRect.empty.left(20)
293
292
  rect.origin.x.should == -20
294
293
  end
294
+
295
+ it "works with options" do
296
+ rect = CGRect.empty.left(20, width: 20)
297
+ rect.origin.x.should == -20
298
+ rect.size.width.should == 20
299
+ end
295
300
  end
296
301
 
297
302
  describe "#right" do
@@ -299,6 +304,12 @@ describe "CGRect" do
299
304
  rect = CGRect.empty.right(20)
300
305
  rect.origin.x.should == 20
301
306
  end
307
+
308
+ it "works with options" do
309
+ rect = CGRect.empty.right(20, width: 20)
310
+ rect.origin.x.should == 20
311
+ rect.size.width.should == 20
312
+ end
302
313
  end
303
314
 
304
315
  describe "#up" do
@@ -306,6 +317,12 @@ describe "CGRect" do
306
317
  rect = CGRect.empty.up(20)
307
318
  rect.origin.y.should == -20
308
319
  end
320
+
321
+ it "works with options" do
322
+ rect = CGRect.empty.up(20, height: 20)
323
+ rect.origin.y.should == -20
324
+ rect.size.height.should == 20
325
+ end
309
326
  end
310
327
 
311
328
  describe "#down" do
@@ -313,6 +330,12 @@ describe "CGRect" do
313
330
  rect = CGRect.empty.down(20)
314
331
  rect.origin.y.should == 20
315
332
  end
333
+
334
+ it "works with options" do
335
+ rect = CGRect.empty.down(20, height: 20)
336
+ rect.origin.y.should == 20
337
+ rect.size.height.should == 20
338
+ end
316
339
  end
317
340
 
318
341
  describe "#wider" do
@@ -320,106 +343,154 @@ describe "CGRect" do
320
343
  rect = CGRect.empty.wider(20)
321
344
  rect.size.width.should == 20
322
345
  end
346
+
347
+ it "works with options" do
348
+ rect = CGRect.empty.wider(20, height: 20)
349
+ rect.size.width.should == 20
350
+ rect.size.height.should == 20
351
+ end
323
352
  end
324
353
 
325
354
  describe "#thinner" do
326
355
  it "works" do
327
- rect = CGRect.empty.thinner(20)
328
- rect.size.width.should == -20
356
+ rect = CGRect.make(width: 20).thinner(10)
357
+ rect.size.width.should == 10
358
+ end
359
+
360
+ it "works with options" do
361
+ rect = CGRect.make(width: 20).thinner(10, height: 20)
362
+ rect.size.width.should == 10
363
+ rect.size.height.should == 20
329
364
  end
330
365
  end
331
366
 
332
367
  describe "#taller" do
333
368
  it "works" do
334
- rect = CGRect.empty.taller(20)
335
- rect.size.height.should == 20
369
+ rect = CGRect.make(height: 20).taller(20)
370
+ rect.size.height.should == 40
371
+ end
372
+
373
+ it "works with options" do
374
+ rect = CGRect.make(height: 20).taller(20, width: 20)
375
+ rect.size.width.should == 20
376
+ rect.size.height.should == 40
336
377
  end
337
378
  end
338
379
 
339
380
  describe "#shorter" do
340
381
  it "works" do
341
- rect = CGRect.empty.shorter(20)
342
- rect.size.height.should == -20
382
+ rect = CGRect.make(height: 20).shorter(10)
383
+ rect.size.height.should == 10
384
+ end
385
+
386
+ it "works with options" do
387
+ rect = CGRect.make(height: 20).shorter(10, width: 20)
388
+ rect.size.width.should == 20
389
+ rect.size.height.should == 10
343
390
  end
344
391
  end
345
392
 
346
393
  describe "#above" do
394
+ it "works without margins" do
395
+ rect = CGRect.make(height: 50).above
396
+ rect.origin.y.should == -50
397
+ rect.size.height.should == 50
398
+ end
399
+
347
400
  it "works with margins" do
348
401
  rect = CGRect.make(height: 50).above(20)
349
402
  rect.origin.y.should == -70
350
403
  rect.size.height.should == 50
351
404
  end
352
405
 
353
- it "works with height" do
406
+ it "works with options" do
354
407
  rect = CGRect.make(height: 50).above(20, height: 10)
355
408
  rect.origin.y.should == -30
356
409
  rect.size.height.should == 10
357
410
  end
358
411
 
359
- it "works without margins" do
360
- rect = CGRect.make(height: 50).above
361
- rect.origin.y.should == -50
362
- rect.size.height.should == 50
412
+ it "works with options and no margin" do
413
+ rect = CGRect.make(height: 50).above(height: 10)
414
+ rect.origin.y.should == -10
415
+ rect.size.height.should == 10
363
416
  end
364
417
  end
365
418
 
366
419
  describe "#below" do
420
+ it "works without margins" do
421
+ rect = CGRect.make(height: 50).below
422
+ rect.origin.y.should == 50
423
+ rect.size.height.should == 50
424
+ end
425
+
367
426
  it "works with margins" do
368
427
  rect = CGRect.make(height: 50).below(20)
369
428
  rect.origin.y.should == 70
370
429
  rect.size.height.should == 50
371
430
  end
372
431
 
373
- it "works with height" do
432
+ it "works with options" do
374
433
  rect = CGRect.make(height: 50).below(20, height: 10)
375
434
  rect.origin.y.should == 70
376
435
  rect.size.height.should == 10
377
436
  end
378
437
 
379
- it "works without margins" do
380
- rect = CGRect.make(height: 50).below
438
+ it "works with options and no margin" do
439
+ rect = CGRect.make(height: 50).below(height: 10)
381
440
  rect.origin.y.should == 50
382
- rect.size.height.should == 50
441
+ rect.size.height.should == 10
383
442
  end
384
443
  end
385
444
 
386
445
  describe "#before" do
446
+ it "works without margins" do
447
+ rect = CGRect.make(width: 50).before
448
+ rect.origin.x.should == -50
449
+ rect.size.width.should == 50
450
+ end
451
+
387
452
  it "works with margins" do
388
453
  rect = CGRect.make(width: 50).before(20)
389
454
  rect.origin.x.should == -70
390
455
  rect.size.width.should == 50
391
456
  end
392
457
 
393
- it "works with width" do
458
+ it "works with options" do
394
459
  rect = CGRect.make(width: 50).before(20, width: 10)
395
460
  rect.origin.x.should == -30
396
461
  rect.size.width.should == 10
397
462
  end
398
463
 
399
- it "works without margins" do
400
- rect = CGRect.make(width: 50).before
401
- rect.origin.x.should == -50
402
- rect.size.width.should == 50
464
+ it "works with options and no margin" do
465
+ rect = CGRect.make(width: 50).before(width: 10)
466
+ rect.origin.x.should == -10
467
+ rect.size.width.should == 10
403
468
  end
404
469
  end
405
470
 
406
471
  describe "#beside" do
472
+ it "works without margins" do
473
+ rect = CGRect.make(width: 50).beside
474
+ rect.origin.x.should == 50
475
+ rect.size.width.should == 50
476
+ end
477
+
407
478
  it "works with margins" do
408
479
  rect = CGRect.make(width: 50).beside(20)
409
480
  rect.origin.x.should == 70
410
481
  rect.size.width.should == 50
411
482
  end
412
483
 
413
- it "works with width" do
484
+ it "works with options" do
414
485
  rect = CGRect.make(width: 50).beside(20, width: 10)
415
486
  rect.origin.x.should == 70
416
487
  rect.size.width.should == 10
417
488
  end
418
489
 
419
- it "works without margins" do
420
- rect = CGRect.make(width: 50).beside
490
+ it "works with options and no margin" do
491
+ rect = CGRect.make(width: 50).beside(width: 10)
421
492
  rect.origin.x.should == 50
422
- rect.size.width.should == 50
493
+ rect.size.width.should == 10
423
494
  end
424
495
  end
425
496
 
@@ -711,6 +782,50 @@ describe "CGRect" do
711
782
  end
712
783
  end
713
784
 
785
+ describe "#grow_left" do
786
+ # @rect = CGRect.make(x: 10, y: 100, width: 50, height: 20)
787
+ it "should work" do
788
+ rect = @rect.grow_left(10)
789
+ rect.should == CGRectMake(0, 100, 60, 20)
790
+ end
791
+ end
792
+
793
+ describe "#grow_right" do
794
+ it "should work" do
795
+ rect = @rect.grow_right(10)
796
+ rect.should == CGRectMake(10, 100, 60, 20)
797
+ end
798
+ end
799
+
800
+ describe "#grow_up" do
801
+ it "should work" do
802
+ rect = @rect.grow_up(10)
803
+ rect.should == CGRectMake(10, 90, 50, 30)
804
+ end
805
+ end
806
+
807
+ describe "#grow_down" do
808
+ it "should work" do
809
+ rect = @rect.grow_down(10)
810
+ rect.should == CGRectMake(10, 100, 50, 30)
811
+ end
812
+ end
813
+
814
+ describe "#grow_width" do
815
+ # @rect = CGRect.make(x: 10, y: 100, width: 50, height: 20)
816
+ it "should work" do
817
+ rect = @rect.grow_width(10)
818
+ rect.should == CGRectMake(0, 100, 70, 20)
819
+ end
820
+ end
821
+
822
+ describe "#grow_height" do
823
+ it "should work" do
824
+ rect = @rect.grow_height(10)
825
+ rect.should == CGRectMake(10, 90, 50, 40)
826
+ end
827
+ end
828
+
714
829
  describe "#shrink" do
715
830
  it "should work with Numeric" do
716
831
  rect = @rect.shrink(10)
@@ -728,6 +843,49 @@ describe "CGRect" do
728
843
  end
729
844
  end
730
845
 
846
+ describe "#shrink_left" do
847
+ it "should work" do
848
+ rect = @rect.shrink_left(10)
849
+ rect.should == CGRectMake(10, 100, 40, 20)
850
+ end
851
+ end
852
+
853
+ describe "#shrink_right" do
854
+ it "should work" do
855
+ rect = @rect.shrink_right(10)
856
+ rect.should == CGRectMake(20, 100, 40, 20)
857
+ end
858
+ end
859
+
860
+ describe "#shrink_up" do
861
+ it "should work" do
862
+ rect = @rect.shrink_up(10)
863
+ rect.should == CGRectMake(10, 100, 50, 10)
864
+ end
865
+ end
866
+
867
+ describe "#shrink_down" do
868
+ it "should work" do
869
+ rect = @rect.shrink_down(10)
870
+ rect.should == CGRectMake(10, 110, 50, 10)
871
+ end
872
+ end
873
+
874
+ describe "#shrink_width" do
875
+ # @rect = CGRect.make(x: 10, y: 100, width: 50, height: 20)
876
+ it "should work" do
877
+ rect = @rect.shrink_width(10)
878
+ rect.should == CGRectMake(20, 100, 30, 20)
879
+ end
880
+ end
881
+
882
+ describe "#shrink_height" do
883
+ it "should work" do
884
+ rect = @rect.shrink_height(10)
885
+ rect.should == CGRectMake(10, 110, 50, 0)
886
+ end
887
+ end
888
+
731
889
  describe "#apply" do
732
890
 
733
891
  it "should support :left" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geomotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: