rm-extensions 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/motion/layout.rb +83 -12
- data/lib/motion/util.rb +13 -0
- data/lib/rm-extensions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4283e3df2472b537a1aa10f4324267fc9a4a90e8
|
4
|
+
data.tar.gz: 7949f50c7124319606630c82eaeab2aa689a484a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32cd5a61f8cfb11e00f2b69e1aeaa6ddeec451605719b826dbd8acca764b934130eccddb02f41843d9e4188b2465011f7f63419005af57a658c6f183cc9acf8a
|
7
|
+
data.tar.gz: c102ddcd8d60f0d611c22c0d6b7033c1952147f6c9fdcfb69e272d050b5c3d54398ae4f03aafe580d32d0162cc317d1d2970048c1d0df76948c5424c51ddeb7a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.1.9
|
2
|
+
|
3
|
+
[Commit history](https://github.com/joenoon/rm-extensions/compare/v0.1.8...v0.1.9)
|
4
|
+
|
5
|
+
* Util: Added #rmext_ivar, which is a shortcut to instance_variable_get/instance_variable_set
|
6
|
+
* Layout: Added #reopen to yield the instance to a block for further processing
|
7
|
+
* Layout: Added an internal "constraint table" to keep track of normalized equations and
|
8
|
+
NSLayoutConstraint objects. equations can now be modified simply by re-applying the same
|
9
|
+
equation with a different constant.
|
10
|
+
* Layout: Added #xeq to remove a constraint by equation
|
11
|
+
* Layout: Added #remove(constraint(s)) to remove NSLayoutConstraint obects from the view
|
12
|
+
and also from the internal constraint table.
|
13
|
+
|
1
14
|
## 0.1.8
|
2
15
|
|
3
16
|
[Commit history](https://github.com/joenoon/rm-extensions/compare/v0.1.7...v0.1.8)
|
data/lib/motion/layout.rb
CHANGED
@@ -41,17 +41,51 @@ module RMExtensions
|
|
41
41
|
"v" => UILayoutConstraintAxisVertical
|
42
42
|
}
|
43
43
|
|
44
|
+
# keeps track of views that are not #hidden? as constraints are built, so the
|
45
|
+
# special `last_visible` view name can be used in equations.
|
46
|
+
# exposed for advanced layout needs.
|
47
|
+
attr_accessor :visible_items
|
48
|
+
|
49
|
+
# Example:
|
50
|
+
# RMExtensions::Layout.new do |layout|
|
51
|
+
# ...
|
52
|
+
# end
|
44
53
|
def initialize
|
45
54
|
@visible_items = []
|
55
|
+
@constraints = {}
|
46
56
|
if block_given?
|
47
57
|
yield self
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
61
|
+
# reopens the RMExtensions::Layout instance for additional processing, ex:
|
62
|
+
# @layout.reopen do |layout|
|
63
|
+
# ...
|
64
|
+
# end
|
65
|
+
# note: you would need to store your instance somewhere on creation to be able to reopen it later, ex:
|
66
|
+
# @layout = RMExtensions::Layout.new do |layout|
|
67
|
+
# ...
|
68
|
+
# end
|
69
|
+
def reopen
|
70
|
+
if block_given?
|
71
|
+
yield self
|
72
|
+
end
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
51
76
|
def clear!
|
52
77
|
@view.removeConstraints(@view.constraints)
|
53
78
|
end
|
54
79
|
|
80
|
+
def remove(constraint)
|
81
|
+
constraints = [ constraint ].flatten
|
82
|
+
@view.removeConstraints(constraints)
|
83
|
+
@constraints.keys.each do |key|
|
84
|
+
@constraints.delete(key) if constraints.include?(@constraints.fetch(key))
|
85
|
+
end
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
55
89
|
def view(view)
|
56
90
|
@view = view
|
57
91
|
end
|
@@ -73,14 +107,17 @@ module RMExtensions
|
|
73
107
|
subviews(views)
|
74
108
|
end
|
75
109
|
|
110
|
+
# takes a string one or more equations separated by newlines and
|
111
|
+
# processes each. returns an array of constraints
|
76
112
|
def eqs(str)
|
77
113
|
str.split("\n").map(&:strip).select { |x| !x.empty? }.map do |line|
|
78
114
|
eq(line)
|
79
|
-
end
|
115
|
+
end.compact
|
80
116
|
end
|
81
117
|
|
82
118
|
# Constraints are of the form "view1.attr1 <relation> view2.attr2 * multiplier + constant @ priority"
|
83
|
-
|
119
|
+
# processes one equation string
|
120
|
+
def eq(str, remove=false)
|
84
121
|
parts = str.split("#", 2).first.split(" ").select { |x| !x.empty? }
|
85
122
|
return if parts.empty?
|
86
123
|
|
@@ -191,6 +228,8 @@ module RMExtensions
|
|
191
228
|
errors.push("Invalid view2: #{to_item}") if to_item && !res_to_item
|
192
229
|
errors.push("Invalid attr2: #{to_item_attribute}") unless res_to_item_attribute
|
193
230
|
|
231
|
+
internal_ident = "#{item}.#{item_attribute} #{related_by} #{to_item}.#{to_item_attribute} * #{multiplier} @ #{priority}"
|
232
|
+
|
194
233
|
if errors.size > 0 || debug
|
195
234
|
p "======================== constraint debug ========================"
|
196
235
|
p "given:"
|
@@ -204,6 +243,7 @@ module RMExtensions
|
|
204
243
|
p " multiplier: #{multiplier}"
|
205
244
|
p " constant: #{constant}"
|
206
245
|
p " priority: #{priority || "required"}"
|
246
|
+
p " internal_ident: #{internal_ident}"
|
207
247
|
end
|
208
248
|
|
209
249
|
if errors.size > 0
|
@@ -214,15 +254,39 @@ module RMExtensions
|
|
214
254
|
@visible_items.unshift(item)
|
215
255
|
end
|
216
256
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
257
|
+
if remove
|
258
|
+
if constraint = @constraints[internal_ident]
|
259
|
+
if debug
|
260
|
+
p "status:"
|
261
|
+
p " existing (for removal)"
|
262
|
+
end
|
263
|
+
@view.removeConstraint(constraint)
|
264
|
+
else
|
265
|
+
raise "RMExtensions::Layout could not find constraint to remove for internal_ident: `#{internal_ident}` (note: this is an internal representation of the constraint, not the exact string given). Make sure the constraint was created first."
|
266
|
+
end
|
267
|
+
elsif constraint = @constraints[internal_ident]
|
268
|
+
if debug
|
269
|
+
p "status:"
|
270
|
+
p " existing (for modification)"
|
271
|
+
end
|
272
|
+
constraint.constant = res_constant
|
273
|
+
else
|
274
|
+
constraint = NSLayoutConstraint.constraintWithItem(res_item,
|
275
|
+
attribute:res_item_attribute,
|
276
|
+
relatedBy:res_related_by,
|
277
|
+
toItem:res_to_item,
|
278
|
+
attribute:res_to_item_attribute,
|
279
|
+
multiplier:res_multiplier,
|
280
|
+
constant:res_constant)
|
281
|
+
if debug
|
282
|
+
p "status:"
|
283
|
+
p " created"
|
284
|
+
end
|
285
|
+
@constraints[internal_ident] = constraint
|
286
|
+
if res_priority
|
287
|
+
constraint.priority = res_priority
|
288
|
+
end
|
289
|
+
@view.addConstraint(constraint)
|
226
290
|
end
|
227
291
|
|
228
292
|
if debug
|
@@ -230,10 +294,17 @@ module RMExtensions
|
|
230
294
|
p " #{constraint.description}"
|
231
295
|
end
|
232
296
|
|
233
|
-
@view.addConstraint(constraint)
|
234
297
|
constraint
|
235
298
|
end
|
236
299
|
|
300
|
+
# removes the constraint matching equation string. constant is not considered.
|
301
|
+
# if no matching constraint is found, it will raise an exception.
|
302
|
+
def xeq(str)
|
303
|
+
eq(str, true)
|
304
|
+
end
|
305
|
+
|
306
|
+
# transforms an NSLayoutConstraint into a string. this string is for debugging and produces
|
307
|
+
# a verbose translation. its not meant to be copied directly as an equation.
|
237
308
|
def describe(constraint)
|
238
309
|
subviews_inverse = subviews.invert
|
239
310
|
item = subviews_inverse[constraint.firstItem]
|
data/lib/motion/util.rb
CHANGED
@@ -18,6 +18,19 @@ module RMExtensions
|
|
18
18
|
raise "This method must be called on the main thread." unless NSThread.currentThread.isMainThread
|
19
19
|
end
|
20
20
|
|
21
|
+
# Shortcut to instance_variable_get and instance_variable_get:
|
22
|
+
# 1 arg for instance_variable_get
|
23
|
+
# 2 args for instance_variable_set
|
24
|
+
def rmext_ivar(*args)
|
25
|
+
if args.size == 1
|
26
|
+
instance_variable_get("@#{args[0]}")
|
27
|
+
elsif args.size == 2
|
28
|
+
instance_variable_set("@#{args[0]}", args[1])
|
29
|
+
else
|
30
|
+
raise "rmext_ivar called with invalid arguments: #{args.inspect}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
end
|
22
35
|
|
23
36
|
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.
|
4
|
+
version: 0.1.9
|
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-09-
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extensions and helpers for dealing with various areas of rubymotion
|
14
14
|
email:
|