motion-kit 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eedf449e832f4fd4ba85cd38676396f3cba7bc85
4
- data.tar.gz: 5214242fb4dd14ace924f3090a6dd453a8b3b821
3
+ metadata.gz: aa78cfdb4f32651a26841b55115ba60a7cd76654
4
+ data.tar.gz: a79b1b9a0ea64591911bd41c66201c69107f92b6
5
5
  SHA512:
6
- metadata.gz: 42a2537b79984c792ce5bb117f2b739406418326a8e41e6539071524ae44fb14ea7ad4fd5608c3437f20ae15680fca1c192b68d2bcacb296bae3716469ec219c
7
- data.tar.gz: d8fab44502565556b68c92dc1b0640fce0415b04a6e7281472d71cb211a57818d046a604a50d22bd2187ec8521cc05cc26fad946ef9135105c1c0c3dadcd4fd2
6
+ metadata.gz: b984dc391e595694145c6f0774dbd88e1db7e4aea682b42615ec3cf110fadd1f5f0a690e684ed5076b7abd845fbd0c0df76f8ca7e15a3b459ca2404a9495ab67
7
+ data.tar.gz: 3e074c594ff27236219d715845882b0f1469dd1458593ed6db6bda52241142a51e86ce518c489cc42a079b2478162e9bb382e0d6b9822d8e7cd02a72f2551414
data/README.md CHANGED
@@ -339,9 +339,16 @@ def my_root_view_style
339
339
  end
340
340
  ```
341
341
 
342
- This is especially useful with collection views, table views, and table cells.
343
- Keep in mind that MotionKit will **not** retain a strong reference to your provided
344
- root view, so retain one yourself to prevent it from being deallocated.
342
+ This is especially useful with collection views, table views, and table cells,
343
+ where you can assign a root view explicitly:
344
+
345
+ ```ruby
346
+ return MyCellLayout.new(root: cell).build
347
+ ```
348
+
349
+ Keep in mind that MotionKit will **not** retain a strong reference when you
350
+ provide a root view, so retain it yourself to prevent it from being
351
+ deallocated.
345
352
 
346
353
  ### How do styles get applied?
347
354
 
@@ -1,3 +1,5 @@
1
+ # @provides MotionKit::Constraint
2
+ # @provides MotionKit::CompoundConstraint
1
3
  module MotionKit
2
4
  class InvalidRelationshipError < Exception
3
5
  end
@@ -379,387 +381,4 @@ module MotionKit
379
381
 
380
382
  end
381
383
 
382
- class SizeConstraint < CompoundConstraint
383
-
384
- def initialize(target, attribute=nil, relationship=:equal)
385
- super
386
- @attribute = [:width, :height]
387
- @attribute2 = [:width, :height]
388
- end
389
-
390
- def attribute=(value)
391
- raise NoMethodError.new("undefined method `#{:attribute=}' for #{self}:#{self.class}", :attribute=)
392
- end
393
-
394
- def attribute2=(value)
395
- raise NoMethodError.new("undefined method `#{:attribute2=}' for #{self}:#{self.class}", :attribute2=)
396
- end
397
-
398
- def constant=(constant)
399
- if constant.is_a?(Array)
400
- @constant = constant[0..1]
401
- elsif constant.is_a?(Hash)
402
- @constant = [0, 0]
403
-
404
- if constant.key?(:w)
405
- @constant[0] = constant[:w]
406
- elsif constant.key?(:width)
407
- @constant[0] = constant[:width]
408
- end
409
-
410
- if constant.key?(:h)
411
- @constant[1] = constant[:h]
412
- elsif constant.key?(:height)
413
- @constant[1] = constant[:height]
414
- end
415
- else
416
- @constant = [constant, constant]
417
- end
418
-
419
- self.update_constraint
420
- end
421
-
422
- def multiplier=(multiplier)
423
- if multiplier.is_a?(Array)
424
- @multiplier = multiplier[0..1]
425
- elsif multiplier.is_a?(Hash)
426
- @multiplier = [0, 0]
427
-
428
- if multiplier.key?(:w)
429
- @multiplier[0] = multiplier[:w]
430
- elsif multiplier.key?(:width)
431
- @multiplier[0] = multiplier[:width]
432
- end
433
-
434
- if multiplier.key?(:h)
435
- @multiplier[1] = multiplier[:h]
436
- elsif multiplier.key?(:height)
437
- @multiplier[1] = multiplier[:height]
438
- end
439
- else
440
- @multiplier = [multiplier, multiplier]
441
- end
442
-
443
- self.update_constraint
444
- end
445
-
446
- def plus(constant)
447
- if constant.is_a?(Array)
448
- self.constant[0] += constant[0]
449
- self.constant[1] += constant[1]
450
- elsif constant.is_a?(Hash)
451
- if constant.key?(:w)
452
- self.constant[0] += constant[:w]
453
- elsif constant.key?(:width)
454
- self.constant[0] += constant[:width]
455
- end
456
-
457
- if constant.key?(:h)
458
- self.constant[1] += constant[:h]
459
- elsif constant.key?(:height)
460
- self.constant[1] += constant[:height]
461
- end
462
- else
463
- self.constant[0] += constant
464
- self.constant[1] += constant
465
- end
466
-
467
- self.update_constraint
468
- self
469
- end
470
-
471
- def minus(constant)
472
- if constant.is_a?(Array)
473
- self.constant[0] -= constant[0]
474
- self.constant[1] -= constant[1]
475
- elsif constant.is_a?(Hash)
476
- if constant.key?(:w)
477
- self.constant[0] -= constant[:w]
478
- elsif constant.key?(:width)
479
- self.constant[0] -= constant[:width]
480
- end
481
-
482
- if constant.key?(:h)
483
- self.constant[1] -= constant[:h]
484
- elsif constant.key?(:height)
485
- self.constant[1] -= constant[:height]
486
- end
487
- else
488
- self.constant[0] -= constant
489
- self.constant[1] -= constant
490
- end
491
-
492
- self.update_constraint
493
- self
494
- end
495
-
496
- def times(multiplier)
497
- if multiplier.is_a?(Array)
498
- self.multiplier[0] *= multiplier[0]
499
- self.multiplier[1] *= multiplier[1]
500
- elsif multiplier.is_a?(Hash)
501
- if multiplier.key?(:w)
502
- self.multiplier[0] *= multiplier[:w]
503
- elsif multiplier.key?(:width)
504
- self.multiplier[0] *= multiplier[:width]
505
- end
506
-
507
- if multiplier.key?(:h)
508
- self.multiplier[1] *= multiplier[:h]
509
- elsif multiplier.key?(:height)
510
- self.multiplier[1] *= multiplier[:height]
511
- end
512
- else
513
- self.multiplier[0] *= multiplier
514
- self.multiplier[1] *= multiplier
515
- end
516
-
517
- self.update_constraint
518
- self
519
- end
520
-
521
- def divided_by(multiplier)
522
- if multiplier.is_a?(Array)
523
- self.multiplier[0] /= multiplier[0].to_f
524
- self.multiplier[1] /= multiplier[1].to_f
525
- elsif multiplier.is_a?(Hash)
526
- if multiplier.key?(:w)
527
- self.multiplier[0] /= multiplier[:w].to_f
528
- elsif multiplier.key?(:width)
529
- self.multiplier[0] /= multiplier[:width].to_f
530
- end
531
-
532
- if multiplier.key?(:h)
533
- self.multiplier[1] /= multiplier[:h].to_f
534
- elsif multiplier.key?(:height)
535
- self.multiplier[1] /= multiplier[:height].to_f
536
- end
537
- else
538
- self.multiplier[0] /= multiplier.to_f
539
- self.multiplier[1] /= multiplier.to_f
540
- end
541
-
542
- self.update_constraint
543
- self
544
- end
545
-
546
- def resolve_all(layout, view)
547
- @resolved ||= begin
548
- item = Constraint.view_lookup(layout, view, self.target)
549
- rel_item = Constraint.view_lookup(layout, view, self.relative_to)
550
- relationship = Constraint.relationship_lookup(self.relationship)
551
-
552
- [[:width, 0], [:height, 1]].map do |attr_name, index|
553
- attribute = Constraint.attribute_lookup(attr_name)
554
- nsconstraint = NSLayoutConstraint.constraintWithItem(item,
555
- attribute: attribute,
556
- relatedBy: relationship,
557
- toItem: rel_item,
558
- attribute: attribute,
559
- multiplier: self.multiplier[index],
560
- constant: self.constant[index]
561
- )
562
-
563
- if self.priority
564
- nsconstraint.priority = Constraint.priority_lookup(self.priority)
565
- end
566
-
567
- if self.identifier
568
- nsconstraint.setIdentifier(self.identifier)
569
- end
570
-
571
- nsconstraint
572
- end
573
- end
574
- end
575
-
576
- end
577
-
578
- class PointConstraint < CompoundConstraint
579
-
580
- def constant=(constant)
581
- if constant.is_a?(Array)
582
- @constant = constant[0..1]
583
- elsif constant.is_a?(Hash)
584
- @constant = [0, 0]
585
-
586
- if constant.key?(:x)
587
- @constant[0] = constant[:x]
588
- end
589
-
590
- if constant.key?(:y)
591
- @constant[1] = constant[:y]
592
- end
593
- else
594
- @constant = [constant, constant]
595
- end
596
-
597
- self.relative_to ||= :superview
598
- self.update_constraint
599
- end
600
-
601
- def multiplier=(multiplier)
602
- if multiplier.is_a?(Array)
603
- @multiplier = multiplier[0..1]
604
- elsif multiplier.is_a?(Hash)
605
- @multiplier = [0, 0]
606
-
607
- if multiplier.key?(:x)
608
- @multiplier[0] = multiplier[:x]
609
- end
610
-
611
- if multiplier.key?(:y)
612
- @multiplier[1] = multiplier[:y]
613
- end
614
- else
615
- @multiplier = [multiplier, multiplier]
616
- end
617
-
618
- self.update_constraint
619
- end
620
-
621
- def plus(constant)
622
- if constant.is_a?(Array)
623
- self.constant[0] += constant[0]
624
- self.constant[1] += constant[1]
625
- elsif constant.is_a?(Hash)
626
- if constant.key?(:x)
627
- self.constant[0] += constant[:x]
628
- elsif constant.key?(:right)
629
- self.constant[0] += constant[:right]
630
- elsif constant.key?(:left)
631
- self.constant[0] -= constant[:left]
632
- end
633
-
634
- if constant.key?(:y)
635
- self.constant[1] += constant[:y]
636
- elsif constant.key?(:up)
637
- self.constant[1] += constant[:up]
638
- elsif constant.key?(:down)
639
- self.constant[1] -= constant[:down]
640
- end
641
- else
642
- self.constant[0] += constant
643
- self.constant[1] += constant
644
- end
645
-
646
- self.update_constraint
647
- self
648
- end
649
-
650
- def minus(constant)
651
- if constant.is_a?(Array)
652
- self.constant[0] -= constant[0]
653
- self.constant[1] -= constant[1]
654
- elsif constant.is_a?(Hash)
655
- if constant.key?(:x)
656
- self.constant[0] -= constant[:x]
657
- elsif constant.key?(:right)
658
- self.constant[0] -= constant[:right]
659
- elsif constant.key?(:left)
660
- self.constant[0] += constant[:left]
661
- end
662
-
663
- if constant.key?(:y)
664
- self.constant[1] -= constant[:y]
665
- elsif constant.key?(:up)
666
- self.constant[1] -= constant[:up]
667
- elsif constant.key?(:down)
668
- self.constant[1] += constant[:down]
669
- end
670
- else
671
- self.constant[0] -= constant
672
- self.constant[1] -= constant
673
- end
674
-
675
- self.update_constraint
676
- self
677
- end
678
-
679
- def times(multiplier)
680
- if multiplier.is_a?(Array)
681
- self.multiplier[0] *= multiplier[0]
682
- self.multiplier[1] *= multiplier[1]
683
- elsif multiplier.is_a?(Hash)
684
- if multiplier.key?(:x)
685
- self.multiplier[0] *= multiplier[:x]
686
- end
687
-
688
- if multiplier.key?(:y)
689
- self.multiplier[1] *= multiplier[:y]
690
- end
691
- else
692
- self.multiplier[0] *= multiplier
693
- self.multiplier[1] *= multiplier
694
- end
695
-
696
- self.update_constraint
697
- self
698
- end
699
-
700
- def divided_by(multiplier)
701
- if multiplier.is_a?(Array)
702
- self.multiplier[0] /= multiplier[0].to_f
703
- self.multiplier[1] /= multiplier[1].to_f
704
- elsif multiplier.is_a?(Hash)
705
- if multiplier.key?(:x)
706
- self.multiplier[0] /= multiplier[:x].to_f
707
- end
708
-
709
- if multiplier.key?(:y)
710
- self.multiplier[1] /= multiplier[:y].to_f
711
- end
712
- else
713
- self.multiplier[0] /= multiplier.to_f
714
- self.multiplier[1] /= multiplier.to_f
715
- end
716
-
717
- self.update_constraint
718
- self
719
- end
720
-
721
- def update_constraint
722
- if @resolved
723
- [0, 1].each do |index|
724
- constraint = @resolved[index]
725
- constraint.constant = self.constant[index]
726
- end
727
- end
728
- end
729
-
730
- def resolve_all(layout, view)
731
- @resolved ||= begin
732
- item = Constraint.view_lookup(layout, view, self.target)
733
- rel_item = Constraint.view_lookup(layout, view, self.relative_to)
734
- relationship = Constraint.relationship_lookup(self.relationship)
735
-
736
- [0, 1].map do |index|
737
- attribute = Constraint.attribute_lookup(self.attribute[index])
738
- mul = self.multiplier[index]
739
- const = self.constant[index]
740
-
741
- nsconstraint = NSLayoutConstraint.constraintWithItem(item,
742
- attribute: attribute,
743
- relatedBy: relationship,
744
- toItem: rel_item,
745
- attribute: attribute,
746
- multiplier: mul,
747
- constant: const
748
- )
749
-
750
- if self.priority
751
- nsconstraint.priority = Constraint.priority_lookup(self.priority)
752
- end
753
-
754
- if self.identifier
755
- nsconstraint.setIdentifier(self.identifier)
756
- end
757
-
758
- nsconstraint
759
- end
760
- end
761
- end
762
-
763
- end
764
-
765
384
  end
@@ -0,0 +1,191 @@
1
+ # @requires MotionKit::CompoundConstraint
2
+ module MotionKit
3
+
4
+ class PointConstraint < CompoundConstraint
5
+
6
+ def constant=(constant)
7
+ if constant.is_a?(Array)
8
+ @constant = constant[0..1]
9
+ elsif constant.is_a?(Hash)
10
+ @constant = [0, 0]
11
+
12
+ if constant.key?(:x)
13
+ @constant[0] = constant[:x]
14
+ end
15
+
16
+ if constant.key?(:y)
17
+ @constant[1] = constant[:y]
18
+ end
19
+ else
20
+ @constant = [constant, constant]
21
+ end
22
+
23
+ self.relative_to ||= :superview
24
+ self.update_constraint
25
+ end
26
+
27
+ def multiplier=(multiplier)
28
+ if multiplier.is_a?(Array)
29
+ @multiplier = multiplier[0..1]
30
+ elsif multiplier.is_a?(Hash)
31
+ @multiplier = [0, 0]
32
+
33
+ if multiplier.key?(:x)
34
+ @multiplier[0] = multiplier[:x]
35
+ end
36
+
37
+ if multiplier.key?(:y)
38
+ @multiplier[1] = multiplier[:y]
39
+ end
40
+ else
41
+ @multiplier = [multiplier, multiplier]
42
+ end
43
+
44
+ self.update_constraint
45
+ end
46
+
47
+ def plus(constant)
48
+ if constant.is_a?(Array)
49
+ self.constant[0] += constant[0]
50
+ self.constant[1] += constant[1]
51
+ elsif constant.is_a?(Hash)
52
+ if constant.key?(:x)
53
+ self.constant[0] += constant[:x]
54
+ elsif constant.key?(:right)
55
+ self.constant[0] += constant[:right]
56
+ elsif constant.key?(:left)
57
+ self.constant[0] -= constant[:left]
58
+ end
59
+
60
+ if constant.key?(:y)
61
+ self.constant[1] += constant[:y]
62
+ elsif constant.key?(:up)
63
+ self.constant[1] += constant[:up]
64
+ elsif constant.key?(:down)
65
+ self.constant[1] -= constant[:down]
66
+ end
67
+ else
68
+ self.constant[0] += constant
69
+ self.constant[1] += constant
70
+ end
71
+
72
+ self.update_constraint
73
+ self
74
+ end
75
+
76
+ def minus(constant)
77
+ if constant.is_a?(Array)
78
+ self.constant[0] -= constant[0]
79
+ self.constant[1] -= constant[1]
80
+ elsif constant.is_a?(Hash)
81
+ if constant.key?(:x)
82
+ self.constant[0] -= constant[:x]
83
+ elsif constant.key?(:right)
84
+ self.constant[0] -= constant[:right]
85
+ elsif constant.key?(:left)
86
+ self.constant[0] += constant[:left]
87
+ end
88
+
89
+ if constant.key?(:y)
90
+ self.constant[1] -= constant[:y]
91
+ elsif constant.key?(:up)
92
+ self.constant[1] -= constant[:up]
93
+ elsif constant.key?(:down)
94
+ self.constant[1] += constant[:down]
95
+ end
96
+ else
97
+ self.constant[0] -= constant
98
+ self.constant[1] -= constant
99
+ end
100
+
101
+ self.update_constraint
102
+ self
103
+ end
104
+
105
+ def times(multiplier)
106
+ if multiplier.is_a?(Array)
107
+ self.multiplier[0] *= multiplier[0]
108
+ self.multiplier[1] *= multiplier[1]
109
+ elsif multiplier.is_a?(Hash)
110
+ if multiplier.key?(:x)
111
+ self.multiplier[0] *= multiplier[:x]
112
+ end
113
+
114
+ if multiplier.key?(:y)
115
+ self.multiplier[1] *= multiplier[:y]
116
+ end
117
+ else
118
+ self.multiplier[0] *= multiplier
119
+ self.multiplier[1] *= multiplier
120
+ end
121
+
122
+ self.update_constraint
123
+ self
124
+ end
125
+
126
+ def divided_by(multiplier)
127
+ if multiplier.is_a?(Array)
128
+ self.multiplier[0] /= multiplier[0].to_f
129
+ self.multiplier[1] /= multiplier[1].to_f
130
+ elsif multiplier.is_a?(Hash)
131
+ if multiplier.key?(:x)
132
+ self.multiplier[0] /= multiplier[:x].to_f
133
+ end
134
+
135
+ if multiplier.key?(:y)
136
+ self.multiplier[1] /= multiplier[:y].to_f
137
+ end
138
+ else
139
+ self.multiplier[0] /= multiplier.to_f
140
+ self.multiplier[1] /= multiplier.to_f
141
+ end
142
+
143
+ self.update_constraint
144
+ self
145
+ end
146
+
147
+ def update_constraint
148
+ if @resolved
149
+ [0, 1].each do |index|
150
+ constraint = @resolved[index]
151
+ constraint.constant = self.constant[index]
152
+ end
153
+ end
154
+ end
155
+
156
+ def resolve_all(layout, view)
157
+ @resolved ||= begin
158
+ item = Constraint.view_lookup(layout, view, self.target)
159
+ rel_item = Constraint.view_lookup(layout, view, self.relative_to)
160
+ relationship = Constraint.relationship_lookup(self.relationship)
161
+
162
+ [0, 1].map do |index|
163
+ attribute = Constraint.attribute_lookup(self.attribute[index])
164
+ mul = self.multiplier[index]
165
+ const = self.constant[index]
166
+
167
+ nsconstraint = NSLayoutConstraint.constraintWithItem(item,
168
+ attribute: attribute,
169
+ relatedBy: relationship,
170
+ toItem: rel_item,
171
+ attribute: attribute,
172
+ multiplier: mul,
173
+ constant: const
174
+ )
175
+
176
+ if self.priority
177
+ nsconstraint.priority = Constraint.priority_lookup(self.priority)
178
+ end
179
+
180
+ if self.identifier
181
+ nsconstraint.setIdentifier(self.identifier)
182
+ end
183
+
184
+ nsconstraint
185
+ end
186
+ end
187
+ end
188
+
189
+ end
190
+
191
+ end
@@ -0,0 +1,200 @@
1
+ # @requires MotionKit::CompoundConstraint
2
+ module MotionKit
3
+
4
+ class SizeConstraint < CompoundConstraint
5
+
6
+ def initialize(target, attribute=nil, relationship=:equal)
7
+ super
8
+ @attribute = [:width, :height]
9
+ @attribute2 = [:width, :height]
10
+ end
11
+
12
+ def attribute=(value)
13
+ raise NoMethodError.new("undefined method `#{:attribute=}' for #{self}:#{self.class}", :attribute=)
14
+ end
15
+
16
+ def attribute2=(value)
17
+ raise NoMethodError.new("undefined method `#{:attribute2=}' for #{self}:#{self.class}", :attribute2=)
18
+ end
19
+
20
+ def constant=(constant)
21
+ if constant.is_a?(Array)
22
+ @constant = constant[0..1]
23
+ elsif constant.is_a?(Hash)
24
+ @constant = [0, 0]
25
+
26
+ if constant.key?(:w)
27
+ @constant[0] = constant[:w]
28
+ elsif constant.key?(:width)
29
+ @constant[0] = constant[:width]
30
+ end
31
+
32
+ if constant.key?(:h)
33
+ @constant[1] = constant[:h]
34
+ elsif constant.key?(:height)
35
+ @constant[1] = constant[:height]
36
+ end
37
+ else
38
+ @constant = [constant, constant]
39
+ end
40
+
41
+ self.update_constraint
42
+ end
43
+
44
+ def multiplier=(multiplier)
45
+ if multiplier.is_a?(Array)
46
+ @multiplier = multiplier[0..1]
47
+ elsif multiplier.is_a?(Hash)
48
+ @multiplier = [0, 0]
49
+
50
+ if multiplier.key?(:w)
51
+ @multiplier[0] = multiplier[:w]
52
+ elsif multiplier.key?(:width)
53
+ @multiplier[0] = multiplier[:width]
54
+ end
55
+
56
+ if multiplier.key?(:h)
57
+ @multiplier[1] = multiplier[:h]
58
+ elsif multiplier.key?(:height)
59
+ @multiplier[1] = multiplier[:height]
60
+ end
61
+ else
62
+ @multiplier = [multiplier, multiplier]
63
+ end
64
+
65
+ self.update_constraint
66
+ end
67
+
68
+ def plus(constant)
69
+ if constant.is_a?(Array)
70
+ self.constant[0] += constant[0]
71
+ self.constant[1] += constant[1]
72
+ elsif constant.is_a?(Hash)
73
+ if constant.key?(:w)
74
+ self.constant[0] += constant[:w]
75
+ elsif constant.key?(:width)
76
+ self.constant[0] += constant[:width]
77
+ end
78
+
79
+ if constant.key?(:h)
80
+ self.constant[1] += constant[:h]
81
+ elsif constant.key?(:height)
82
+ self.constant[1] += constant[:height]
83
+ end
84
+ else
85
+ self.constant[0] += constant
86
+ self.constant[1] += constant
87
+ end
88
+
89
+ self.update_constraint
90
+ self
91
+ end
92
+
93
+ def minus(constant)
94
+ if constant.is_a?(Array)
95
+ self.constant[0] -= constant[0]
96
+ self.constant[1] -= constant[1]
97
+ elsif constant.is_a?(Hash)
98
+ if constant.key?(:w)
99
+ self.constant[0] -= constant[:w]
100
+ elsif constant.key?(:width)
101
+ self.constant[0] -= constant[:width]
102
+ end
103
+
104
+ if constant.key?(:h)
105
+ self.constant[1] -= constant[:h]
106
+ elsif constant.key?(:height)
107
+ self.constant[1] -= constant[:height]
108
+ end
109
+ else
110
+ self.constant[0] -= constant
111
+ self.constant[1] -= constant
112
+ end
113
+
114
+ self.update_constraint
115
+ self
116
+ end
117
+
118
+ def times(multiplier)
119
+ if multiplier.is_a?(Array)
120
+ self.multiplier[0] *= multiplier[0]
121
+ self.multiplier[1] *= multiplier[1]
122
+ elsif multiplier.is_a?(Hash)
123
+ if multiplier.key?(:w)
124
+ self.multiplier[0] *= multiplier[:w]
125
+ elsif multiplier.key?(:width)
126
+ self.multiplier[0] *= multiplier[:width]
127
+ end
128
+
129
+ if multiplier.key?(:h)
130
+ self.multiplier[1] *= multiplier[:h]
131
+ elsif multiplier.key?(:height)
132
+ self.multiplier[1] *= multiplier[:height]
133
+ end
134
+ else
135
+ self.multiplier[0] *= multiplier
136
+ self.multiplier[1] *= multiplier
137
+ end
138
+
139
+ self.update_constraint
140
+ self
141
+ end
142
+
143
+ def divided_by(multiplier)
144
+ if multiplier.is_a?(Array)
145
+ self.multiplier[0] /= multiplier[0].to_f
146
+ self.multiplier[1] /= multiplier[1].to_f
147
+ elsif multiplier.is_a?(Hash)
148
+ if multiplier.key?(:w)
149
+ self.multiplier[0] /= multiplier[:w].to_f
150
+ elsif multiplier.key?(:width)
151
+ self.multiplier[0] /= multiplier[:width].to_f
152
+ end
153
+
154
+ if multiplier.key?(:h)
155
+ self.multiplier[1] /= multiplier[:h].to_f
156
+ elsif multiplier.key?(:height)
157
+ self.multiplier[1] /= multiplier[:height].to_f
158
+ end
159
+ else
160
+ self.multiplier[0] /= multiplier.to_f
161
+ self.multiplier[1] /= multiplier.to_f
162
+ end
163
+
164
+ self.update_constraint
165
+ self
166
+ end
167
+
168
+ def resolve_all(layout, view)
169
+ @resolved ||= begin
170
+ item = Constraint.view_lookup(layout, view, self.target)
171
+ rel_item = Constraint.view_lookup(layout, view, self.relative_to)
172
+ relationship = Constraint.relationship_lookup(self.relationship)
173
+
174
+ [[:width, 0], [:height, 1]].map do |attr_name, index|
175
+ attribute = Constraint.attribute_lookup(attr_name)
176
+ nsconstraint = NSLayoutConstraint.constraintWithItem(item,
177
+ attribute: attribute,
178
+ relatedBy: relationship,
179
+ toItem: rel_item,
180
+ attribute: attribute,
181
+ multiplier: self.multiplier[index],
182
+ constant: self.constant[index]
183
+ )
184
+
185
+ if self.priority
186
+ nsconstraint.priority = Constraint.priority_lookup(self.priority)
187
+ end
188
+
189
+ if self.identifier
190
+ nsconstraint.setIdentifier(self.identifier)
191
+ end
192
+
193
+ nsconstraint
194
+ end
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ end
data/lib/motion-kit.rb CHANGED
@@ -10,9 +10,14 @@ Motion::Project::App.setup do |app|
10
10
  core_lib = File.join(File.dirname(__FILE__), 'motion-kit')
11
11
  cocoa_lib = File.join(File.dirname(__FILE__), 'motion-kit-cocoa')
12
12
  platform = app.respond_to?(:template) ? app.template : :ios
13
- platform_lib = File.join(File.dirname(__FILE__), "motion-kit-#{platform}")
13
+ if platform.to_s.start_with?('ios')
14
+ platform_name = 'ios'
15
+ elsif platform.to_s.start_with?('osx')
16
+ platform_name = 'osx'
17
+ end
18
+ platform_lib = File.join(File.dirname(__FILE__), "motion-kit-#{platform_name}")
14
19
  unless File.exists? platform_lib
15
- raise "Sorry, the platform #{platform.inspect} is not supported by MotionKit"
20
+ raise "Sorry, the platform #{platform.inspect} (aka #{platform_name}) is not supported by MotionKit"
16
21
  end
17
22
 
18
23
  # scans app.files until it finds app/ (the default)
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.15.0'
2
+ VERSION = '0.16.0'
3
3
  end
@@ -33,4 +33,25 @@ describe 'Custom Root Layouts' do
33
33
  @subject.view.subviews.first.subviews.first.backgroundColor.should == NSColor.blackColor
34
34
  end
35
35
 
36
+ it "shouldn't build if `build` or `view` aren't called" do
37
+ @subject.built?.should == false
38
+ end
39
+
40
+ it "should build when `build` is called" do
41
+ @subject.build
42
+ @subject.built?.should == true
43
+ end
44
+
45
+ it "should build when `view` is called" do
46
+ @subject.view
47
+ @subject.built?.should == true
48
+ end
49
+
50
+ it "should allow bare styles in layout when root is specified in initializer" do
51
+ @subject = TestNoRootLayout.new(root: @view).build
52
+ @subject.view.should == @view
53
+ @subject.view.backgroundColor.should == UIColor.redColor
54
+ @subject.view.subviews.first.should.be.kind_of?(UILabel)
55
+ end
56
+
36
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-27 00:00:00.000000000 Z
12
+ date: 2014-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbt
@@ -52,6 +52,8 @@ files:
52
52
  - lib/motion-kit-cocoa/constraints/constraint.rb
53
53
  - lib/motion-kit-cocoa/constraints/constraints_helpers.rb
54
54
  - lib/motion-kit-cocoa/constraints/constraints_target.rb
55
+ - lib/motion-kit-cocoa/constraints/point_constraint.rb
56
+ - lib/motion-kit-cocoa/constraints/size_constraint.rb
55
57
  - lib/motion-kit-cocoa/helpers/accessibility_compat.rb
56
58
  - lib/motion-kit-cocoa/helpers/cagradientlayer_helpers.rb
57
59
  - lib/motion-kit-cocoa/helpers/calayer_frame_helpers.rb