teacup 2.1.16 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96de147670ba7ae190e6c389f563208d5d902e22
4
- data.tar.gz: e670534419eb6001161a7650229b52b898781fea
3
+ metadata.gz: 78d2c2affd8f6c85eb542169ac6f9e355ef5774e
4
+ data.tar.gz: 9d7e6c1ac113248c7259ea2eddd303f4e2a1c3e7
5
5
  SHA512:
6
- metadata.gz: e826592ea8620316ceee9c14adfa1f21b07e570cc1450b48f27ecba5e1b9a93d46a5134fecdbfbefe8a0df0af0d6524a34f58fbec1e75c5fd9cbf95641ce8548
7
- data.tar.gz: 3e399a95a2dadca2ca6a11c49009abc5ce4d0063e1311804624f3ed3398e64b590c36888338ca648e26dfced6f8d26a6fd0663fa5b91287980047be463fce39d
6
+ metadata.gz: fb517a21e621a6dc268fd12df22c4966c64e8c70e8cd63459f8170fe96f4cc9eb283148f575ae357477fcad29f552117b531b1ad8a1a05d03ff8876327db1765
7
+ data.tar.gz: 6c8237dfb7bf6620716544793ef556e7ddf7ca16a1491bd2b0b78f3b5b65f6fdb8b942e882e9eda3be2db8d3078c0e2e9b6bbb28503aba0a4d6cd8c4bc16380e
@@ -10,9 +10,9 @@ module Teacup
10
10
 
11
11
  case dimension
12
12
  when :width
13
- view.superview.frame.size.width * percent + offset
13
+ (view.superview.frame.size.width * percent + offset).round
14
14
  when :height
15
- view.superview.frame.size.height * percent + offset
15
+ (view.superview.frame.size.height * percent + offset).round
16
16
  else
17
17
  raise "Unknown dimension #{dimension}"
18
18
  end
@@ -8,6 +8,7 @@ module Teacup
8
8
  attr_accessor :multiplier
9
9
  attr_accessor :constant
10
10
  attr_accessor :priority
11
+ attr_accessor :identifier
11
12
 
12
13
  if defined? NSLayoutRelationEqual
13
14
  Priorities = {
@@ -187,6 +188,13 @@ module Teacup
187
188
  self
188
189
  end
189
190
 
191
+ def identifier(identifier=nil)
192
+ return @identifier if identifier.nil?
193
+
194
+ self.identifier = identifier
195
+ self
196
+ end
197
+
190
198
  def copy
191
199
  copy = self.class.new(self.target, self.attribute)
192
200
  copy.relationship = self.relationship
@@ -195,6 +203,7 @@ module Teacup
195
203
  copy.multiplier = self.multiplier
196
204
  copy.constant = self.constant
197
205
  copy.priority = self.priority
206
+ copy.identifier = self.identifier
198
207
  copy
199
208
  end
200
209
 
@@ -220,6 +229,7 @@ module Teacup
220
229
  constant: self.constant
221
230
  )
222
231
  nsconstraint.priority = priority_lookup(self.priority)
232
+ nsconstraint.setIdentifier(self.identifier) if self.identifier
223
233
  return nsconstraint
224
234
  end
225
235
 
@@ -29,11 +29,50 @@ module Teacup
29
29
  target[key] = value
30
30
  elsif value.is_a?(Hash) and left[key].is_a?(Hash)
31
31
  target[key] = Teacup::merge_defaults(left[key], value, (left==target ? left[key] : {}))
32
+ elsif key == :constraints
33
+ left[key] = merge_constraints(left[key], value)
32
34
  end
33
35
  end
34
36
  target
35
37
  end
36
38
 
39
+ # constraints are a special case because when we merge an array of constraints
40
+ # we need to make sure not to add more than one constraint for a given attribute
41
+ def merge_constraints(left, right)
42
+ left = left.map do |constraint|
43
+ convert_constraints(constraint)
44
+ end.flatten
45
+ right = right.map do |constraint|
46
+ convert_constraints(constraint)
47
+ end.flatten
48
+
49
+ constrained_attributes = left.map do |constraint|
50
+ constraint.attribute
51
+ end
52
+ additional_constraints = right.reject do |constraint|
53
+ constrained_attributes.include?(constraint.attribute)
54
+ end
55
+ left + additional_constraints
56
+ end
57
+
58
+ def convert_constraints(constraints)
59
+ if constraints.is_a? Array
60
+ constraints.map do |constraint|
61
+ convert_constraints(constraint)
62
+ end
63
+ elsif constraints.is_a? Hash
64
+ constraints.map do |sym, relative_to|
65
+ convert_constraints(Teacup::Constraint.from_sym(sym, relative_to))
66
+ end
67
+ elsif constraints.is_a?(Symbol)
68
+ Teacup::Constraint.from_sym(constraints)
69
+ elsif constraints.is_a?(Teacup::Constraint)
70
+ constraints
71
+ else
72
+ raise "Unsupported constraint: #{constraints.inspect}"
73
+ end
74
+ end
75
+
37
76
  # modifies left by passing it in as the `target`.
38
77
  def merge_defaults!(left, right)
39
78
  Teacup::merge_defaults(left, right, left)
@@ -148,6 +148,17 @@ module Teacup
148
148
 
149
149
  view_class = self.class
150
150
 
151
+ controller = nil
152
+ target = self
153
+ while target && controller.nil?
154
+ if target.nextResponder.is_a?(UIViewController)
155
+ controller = target.nextResponder
156
+ target = nil
157
+ else
158
+ target = target.nextResponder
159
+ end
160
+ end
161
+
151
162
  case original_constraint.target
152
163
  when view_class
153
164
  constraint.target = original_constraint.target
@@ -173,6 +184,24 @@ module Teacup
173
184
  constraint.relative_to = self
174
185
  when :superview
175
186
  constraint.relative_to = self.superview
187
+ when :top_layout_guide
188
+ if controller.respondsToSelector(:topLayoutGuide)
189
+ constraint.relative_to = controller.topLayoutGuide
190
+ else
191
+ if controller
192
+ NSLog("topLayoutGuide is only supported in >= iOS 7. Reverting to nil bound")
193
+ end
194
+ constraint.relative_to = nil
195
+ end
196
+ when :bottom_layout_guide
197
+ if controller.respondsToSelector(:bottomLayoutGuide)
198
+ constraint.relative_to = controller.bottomLayoutGuide
199
+ else
200
+ if controller
201
+ NSLog("bottomLayoutGuide is only supported in >= iOS 7. Reverting to nil bound")
202
+ end
203
+ constraint.relative_to = nil
204
+ end
176
205
  when Symbol, String
177
206
  # TODO: this re-checks lots of views - everytime it goes up to the
178
207
  # superview, it checks all the leaves again.
@@ -333,6 +362,5 @@ module Teacup
333
362
  end
334
363
  end
335
364
 
336
-
337
365
  end
338
366
  end
@@ -1,5 +1,5 @@
1
1
  module Teacup
2
2
 
3
- VERSION = '2.1.16'
3
+ VERSION = '2.2.0'
4
4
 
5
5
  end
@@ -1,6 +1,6 @@
1
1
  class Viewish
2
2
  def superview
3
- @superview ||= Viewish.new
3
+ @superview ||= self.class.new
4
4
  end
5
5
 
6
6
  def bounds
@@ -12,6 +12,12 @@ class Viewish
12
12
  end
13
13
  end
14
14
 
15
+ class IrregularBounds < Viewish
16
+ def bounds
17
+ CGRect.new([0, 0], [101, 43])
18
+ end
19
+ end
20
+
15
21
 
16
22
  describe 'Teacup.calculate' do
17
23
 
@@ -35,6 +41,11 @@ describe 'Teacup.calculate' do
35
41
  Teacup.calculate(Viewish.new, :height, '50%').should == 22
36
42
  end
37
43
 
44
+ it "should round to the nearest point" do
45
+ Teacup.calculate(IrregularBounds.new, :height, '25%').should == 11
46
+ Teacup.calculate(IrregularBounds.new, :width, '25%').should == 25
47
+ end
48
+
38
49
  describe 'should return percents with offset' do
39
50
  it ':width, 50% + 10' do
40
51
  Teacup.calculate(Viewish.new, :width, '50% + 10').should == 60
@@ -22,6 +22,20 @@ describe 'Using constraints in portrait' do
22
22
  end
23
23
  end
24
24
 
25
+ it 'should have a top_layout_view' do
26
+ @controller.top_layout_view.frame.tap do |f|
27
+ f.origin.x.should == 0
28
+ f.origin.y.should == @controller.topLayoutGuide.length
29
+ end
30
+ end
31
+
32
+ it 'should have a bottom_layout_view' do
33
+ @controller.bottom_layout_view.frame.tap do |f|
34
+ f.origin.x.should == 0
35
+ f.origin.y.should == @controller.container.frame.size.height - @controller.bottomLayoutGuide.length - 10
36
+ end
37
+ end
38
+
25
39
  it 'should have a center view' do
26
40
  @controller.center_view.frame.tap do |f|
27
41
  f.origin.x.should == 8
@@ -129,3 +143,63 @@ describe 'Using constraints in landscape' do
129
143
  end
130
144
 
131
145
  end
146
+
147
+ describe 'extends merges constraints' do
148
+ before do
149
+ Teacup::Stylesheet.stylesheets[:merge_constraints] = nil
150
+ Teacup::Stylesheet.new(:merge_constraints) do
151
+ style :button,
152
+ constraints: [
153
+ :full_width,
154
+ constrain_height(22),
155
+ constrain_top(0)
156
+ ]
157
+
158
+ style :tall_button, extends: :button,
159
+ constraints: [
160
+ constrain_width(100),
161
+ constrain_height(44),
162
+ ]
163
+ end
164
+ end
165
+
166
+ it 'should not affect "base class" style' do
167
+ merge_constraints_stylesheet = Teacup::Stylesheet[:merge_constraints]
168
+ button_style = merge_constraints_stylesheet.query(:button)
169
+ button_style[:constraints].size.should == 3
170
+
171
+ full_constraint = button_style[:constraints][0]
172
+ height_constraint = button_style[:constraints][1]
173
+ top_constraint = button_style[:constraints][2]
174
+
175
+ full_constraint.should == :full_width
176
+ height_constraint.attribute.should == Teacup::Constraint::Attributes[:height]
177
+ height_constraint.constant.should == 22
178
+ top_constraint.attribute.should == Teacup::Constraint::Attributes[:top]
179
+ top_constraint.constant.should == 0
180
+ end
181
+
182
+ it 'should merge constraints when extending styles' do
183
+ merge_constraints_stylesheet = Teacup::Stylesheet[:merge_constraints]
184
+ tall_button_style = merge_constraints_stylesheet.query(:tall_button)
185
+ tall_button_style[:constraints].size.should == 4
186
+
187
+ width_constraint = tall_button_style[:constraints][0]
188
+ height_constraint = tall_button_style[:constraints][1]
189
+ center_x_constraint = tall_button_style[:constraints][2]
190
+ top_constraint = tall_button_style[:constraints][3]
191
+
192
+ width_constraint.attribute.should == Teacup::Constraint::Attributes[:width]
193
+ width_constraint.constant.should == 100
194
+ height_constraint.attribute.should == Teacup::Constraint::Attributes[:height]
195
+ height_constraint.constant.should == 44
196
+ center_x_constraint.attribute.should == Teacup::Constraint::Attributes[:center_x]
197
+ center_x_constraint.attribute2.should == Teacup::Constraint::Attributes[:center_x]
198
+ rel_to = center_x_constraint.relative_to
199
+ # nil is a valid value for :superview
200
+ rel_to ||= :superview
201
+ rel_to.should == :superview
202
+ top_constraint.attribute.should == Teacup::Constraint::Attributes[:top]
203
+ top_constraint.constant.should == 0
204
+ end
205
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teacup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.16
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - the rubymotion community
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-27 00:00:00.000000000 Z
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Teacup is a community-driven DSL for RubyMotion. It has CSS-like styling, and