rm-extensions 0.1.7 → 0.1.8

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: def362607872dfcd691017faa171e66967d0630c
4
- data.tar.gz: bbeb76a150653503536aa8e2cf02565d48d0bca9
3
+ metadata.gz: ca18caba001487c996e9f8af26733232b557e383
4
+ data.tar.gz: 1e9972eb5b2810de67b5c8088312afba316c7563
5
5
  SHA512:
6
- metadata.gz: 3fc8a7624f1ecfe03c8af4bcea0f7c31092c3403091bc99754071efde2d98b2927531c361ca809c817b4a70753357ca0395e9e2c5563c3c8506856e20cda9de6
7
- data.tar.gz: 608c671f2a9d9656961005e4e86d2e21a0d14e050dfbea5eb5bc759404ac992bc1d486507936bc149d9a0c4147e0a4937152d3b4ddebe90c027e66dc46c4f852
6
+ metadata.gz: 908c30a6f6a5193b07ef296879cff08f80e1cb1b88ef1f4d88871e9937f0c10b8e3d0c9395503bf34a9ab1a9a73551695ca234b588b19bfc64ee7009f38fc7de
7
+ data.tar.gz: 136c28f62665b1817bb4991ba90fd5b3265c6a1a5c8fb41aead3083455717462dce2f7dd46426e4c135ca28bbc8ba41a7e74771c6a785d7c7ca7a6081364d6d1
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## 0.1.8
2
+
3
+ [Commit history](https://github.com/joenoon/rm-extensions/compare/v0.1.7...v0.1.8)
4
+
5
+ * Added RMExtensions::Layout#clear! which is a shortcut to view.removeConstraints(view.constraints).
6
+ It must be called after the `view` is set.
7
+ * Added 'max' as a valid priority shortcut, since it reads better than 'required' in many cases.
8
+ * Comments are now allowed on a line by themselves inside a `eqs` string, to make for easier commenting,
9
+ or to easily comment out an equation.
10
+ * Added a special `last_visible` view identifier which can be used instead of an actual view name
11
+ inside an equation. It will refer to the last view a constraint was applied to that was not hidden.
12
+ This can be used to more easily lay out constraints when some views should not be anchored against.
13
+ For example, you have 3 labels, A, B, and C, that you want stacked vertically:
14
+ A.top == 0
15
+ B.top == A.bottom + 5
16
+ C.top == B.bottom + 5
17
+ If B is hidden, there would be 10px in between A and C. Instead, you can let RMExtensions::Layout handle
18
+ this for you:
19
+ A.top == 0 # last_visible is set to A
20
+ B.top == last_visible.bottom + 5 # B is hidden, so last_visible remains A
21
+ C.top == last_visible.bottom + 5 # C now aligns to the bottom of A
22
+ It is usually easier and cleaner to build all possible views and mark some hidden than it is to have
23
+ many if/else view creation and constraint construction specific to what should be displayed.
data/lib/motion/layout.rb CHANGED
@@ -27,6 +27,7 @@ module RMExtensions
27
27
  RELATED_BY_LOOKUP_INVERSE = RELATED_BY_LOOKUP.invert
28
28
 
29
29
  PRIORITY_LOOKUP = {
30
+ "max" => UILayoutPriorityRequired, # = 1000
30
31
  "required" => UILayoutPriorityRequired, # = 1000
31
32
  "high" => UILayoutPriorityDefaultHigh, # = 750
32
33
  "low" => UILayoutPriorityDefaultLow, # = 250
@@ -41,11 +42,16 @@ module RMExtensions
41
42
  }
42
43
 
43
44
  def initialize
45
+ @visible_items = []
44
46
  if block_given?
45
47
  yield self
46
48
  end
47
49
  end
48
50
 
51
+ def clear!
52
+ @view.removeConstraints(@view.constraints)
53
+ end
54
+
49
55
  def view(view)
50
56
  @view = view
51
57
  end
@@ -75,16 +81,17 @@ module RMExtensions
75
81
 
76
82
  # Constraints are of the form "view1.attr1 <relation> view2.attr2 * multiplier + constant @ priority"
77
83
  def eq(str)
84
+ parts = str.split("#", 2).first.split(" ").select { |x| !x.empty? }
85
+ return if parts.empty?
86
+
78
87
  item = nil
79
88
  item_attribute = nil
80
89
  related_by = nil
81
90
  to_item = nil
82
91
  to_item_attribute = nil
83
- multiplier = nil
84
- constant = nil
92
+ multiplier = 1.0
93
+ constant = 0.0
85
94
 
86
- parts = str.split("#", 2).first.split(" ").select { |x| !x.empty? }
87
-
88
95
  debug = parts.delete("?")
89
96
 
90
97
  # first part should always be view1.attr1
@@ -146,8 +153,12 @@ module RMExtensions
146
153
 
147
154
  # normalize
148
155
 
156
+ if item == "last_visible"
157
+ item = @visible_items.first || "view"
158
+ end
159
+
149
160
  res_item = view_for_item(item)
150
- res_constant = constant ? Float(PRIORITY_LOOKUP[constant] || constant) : 0.0
161
+ res_constant = Float(PRIORITY_LOOKUP[constant] || constant)
151
162
 
152
163
  if res_item
153
164
  case item_attribute
@@ -162,11 +173,15 @@ module RMExtensions
162
173
  end
163
174
  end
164
175
 
176
+ if to_item == "last_visible"
177
+ to_item = @visible_items.detect { |x| x != item } || "view"
178
+ end
179
+
165
180
  res_item_attribute = ATTRIBUTE_LOOKUP[item_attribute]
166
181
  res_related_by = RELATED_BY_LOOKUP[related_by]
167
182
  res_to_item = to_item ? view_for_item(to_item) : nil
168
183
  res_to_item_attribute = ATTRIBUTE_LOOKUP[to_item_attribute]
169
- res_multiplier = multiplier ? Float(multiplier) : 1.0
184
+ res_multiplier = Float(multiplier)
170
185
  res_priority = priority ? Integer(PRIORITY_LOOKUP[priority] || priority) : nil
171
186
 
172
187
  errors = []
@@ -188,13 +203,17 @@ module RMExtensions
188
203
  p " to_item_attribute: #{to_item_attribute}"
189
204
  p " multiplier: #{multiplier}"
190
205
  p " constant: #{constant}"
191
- p " priority: #{priority}"
206
+ p " priority: #{priority || "required"}"
192
207
  end
193
208
 
194
209
  if errors.size > 0
195
210
  raise(errors.join(", "))
196
211
  end
197
212
 
213
+ unless res_item.hidden?
214
+ @visible_items.unshift(item)
215
+ end
216
+
198
217
  constraint = NSLayoutConstraint.constraintWithItem(res_item,
199
218
  attribute:res_item_attribute,
200
219
  relatedBy:res_related_by,
@@ -1,3 +1,3 @@
1
1
  module RMExtensions
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rm-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Noon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2013-09-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Extensions and helpers for dealing with various areas of rubymotion
14
14
  email:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - .gitignore
21
+ - CHANGELOG.md
21
22
  - Gemfile
22
23
  - LICENSE.txt
23
24
  - README.md