rm-extensions 0.1.4 → 0.1.5
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 +4 -4
- data/lib/motion/layout.rb +41 -39
- 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: 2ba4ba13ce05f6391b658a6d6968fd368d6eb66e
|
4
|
+
data.tar.gz: 9140c139f8dc4c75d01183e46019df8ebac3a7c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ba45a55bbee4a13e6d0d72326208e4c704377ad24b28c6e04569e857cfeb74e869e9d846e9744367432e34068f8808dd502326f79b9cf242dfcebdb541b7c6c
|
7
|
+
data.tar.gz: 03222f43b0510a630fd09b33f30bc59815c06ad6d54e41384f76880d0f645bb449ff297ee689d01988235ff66d4a8be31df1385d60b174b6c7222be4c18d7c4e
|
data/lib/motion/layout.rb
CHANGED
@@ -16,12 +16,16 @@ module RMExtensions
|
|
16
16
|
nil => NSLayoutAttributeNotAnAttribute
|
17
17
|
}
|
18
18
|
|
19
|
+
ATTRIBUTE_LOOKUP_INVERSE = ATTRIBUTE_LOOKUP.invert
|
20
|
+
|
19
21
|
RELATED_BY_LOOKUP = {
|
20
22
|
"<=" => NSLayoutRelationLessThanOrEqual,
|
21
23
|
"==" => NSLayoutRelationEqual,
|
22
24
|
">=" => NSLayoutRelationGreaterThanOrEqual
|
23
25
|
}
|
24
26
|
|
27
|
+
RELATED_BY_LOOKUP_INVERSE = RELATED_BY_LOOKUP.invert
|
28
|
+
|
25
29
|
PRIORITY_LOOKUP = {
|
26
30
|
"required" => UILayoutPriorityRequired, # = 1000
|
27
31
|
"high" => UILayoutPriorityDefaultHigh, # = 750
|
@@ -29,6 +33,8 @@ module RMExtensions
|
|
29
33
|
"fit" => UILayoutPriorityFittingSizeLevel # = 50
|
30
34
|
}
|
31
35
|
|
36
|
+
PRIORITY_LOOKUP_INVERSE = PRIORITY_LOOKUP.invert
|
37
|
+
|
32
38
|
AXIS_LOOKUP = {
|
33
39
|
"h" => UILayoutConstraintAxisHorizontal,
|
34
40
|
"v" => UILayoutConstraintAxisVertical
|
@@ -58,18 +64,14 @@ module RMExtensions
|
|
58
64
|
@subviews
|
59
65
|
end
|
60
66
|
|
61
|
-
def eqs(str
|
67
|
+
def eqs(str)
|
62
68
|
str.split("\n").map(&:strip).select { |x| !x.empty? }.map do |line|
|
63
|
-
eq(line
|
69
|
+
eq(line)
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
|
-
def eq?(str)
|
68
|
-
eq(str, true)
|
69
|
-
end
|
70
|
-
|
71
73
|
# Constraints are of the form "view1.attr1 <relation> view2.attr2 * multiplier + constant @ priority"
|
72
|
-
def eq(str
|
74
|
+
def eq(str)
|
73
75
|
item = nil
|
74
76
|
item_attribute = nil
|
75
77
|
related_by = nil
|
@@ -78,7 +80,9 @@ module RMExtensions
|
|
78
80
|
multiplier = nil
|
79
81
|
constant = nil
|
80
82
|
|
81
|
-
parts = str.split(" ").select { |x| !x.empty? }
|
83
|
+
parts = str.split("#", 2).first.split(" ").select { |x| !x.empty? }
|
84
|
+
|
85
|
+
debug = parts.delete("?")
|
82
86
|
|
83
87
|
# first part should always be view1.attr1
|
84
88
|
part = parts.shift
|
@@ -107,9 +111,9 @@ module RMExtensions
|
|
107
111
|
parts.delete_at(idx)
|
108
112
|
end
|
109
113
|
|
110
|
-
# look for
|
114
|
+
# look for multiplier
|
111
115
|
if idx = parts.index("*")
|
112
|
-
|
116
|
+
multiplier = parts[idx + 1]
|
113
117
|
parts.delete_at(idx)
|
114
118
|
parts.delete_at(idx)
|
115
119
|
end
|
@@ -137,21 +141,6 @@ module RMExtensions
|
|
137
141
|
end
|
138
142
|
end
|
139
143
|
|
140
|
-
debug_hash = nil
|
141
|
-
|
142
|
-
if debug
|
143
|
-
debug_hash = {
|
144
|
-
:item => item,
|
145
|
-
:item_attribute => item_attribute,
|
146
|
-
:related_by => related_by,
|
147
|
-
:to_item => to_item,
|
148
|
-
:to_item_attribute => to_item_attribute,
|
149
|
-
:multiplier => multiplier,
|
150
|
-
:constant => constant,
|
151
|
-
:priority => priority
|
152
|
-
}
|
153
|
-
end
|
154
|
-
|
155
144
|
# normalize
|
156
145
|
|
157
146
|
res_item = item == "view" ? @view : @subviews[item]
|
@@ -186,18 +175,18 @@ module RMExtensions
|
|
186
175
|
errors.push("Invalid attr2: #{to_item_attribute}") unless res_to_item_attribute
|
187
176
|
|
188
177
|
if errors.size > 0 || debug
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
178
|
+
p "======================== constraint debug ========================"
|
179
|
+
p "given:"
|
180
|
+
p " #{str}"
|
181
|
+
p "interpreted:"
|
182
|
+
p " item: #{item}"
|
183
|
+
p " item_attribute: #{item_attribute}"
|
184
|
+
p " related_by: #{related_by}"
|
185
|
+
p " to_item: #{to_item}"
|
186
|
+
p " to_item_attribute: #{to_item_attribute}"
|
187
|
+
p " multiplier: #{multiplier}"
|
188
|
+
p " constant: #{constant}"
|
189
|
+
p " priority: #{priority}"
|
201
190
|
end
|
202
191
|
|
203
192
|
if errors.size > 0
|
@@ -216,13 +205,26 @@ module RMExtensions
|
|
216
205
|
end
|
217
206
|
|
218
207
|
if debug
|
219
|
-
|
220
|
-
|
208
|
+
p "implemented:"
|
209
|
+
p " #{constraint.description}"
|
221
210
|
end
|
222
211
|
|
223
212
|
@view.addConstraint(constraint)
|
224
213
|
constraint
|
225
214
|
end
|
226
215
|
|
216
|
+
def describe(constraint)
|
217
|
+
subviews_inverse = subviews.invert
|
218
|
+
item = subviews_inverse[constraint.firstItem]
|
219
|
+
item_attribute = ATTRIBUTE_LOOKUP_INVERSE[constraint.firstAttribute]
|
220
|
+
related_by = RELATED_BY_LOOKUP_INVERSE[constraint.relation]
|
221
|
+
to_item = subviews_inverse[constraint.secondItem]
|
222
|
+
to_item_attribute = ATTRIBUTE_LOOKUP_INVERSE[constraint.secondAttribute]
|
223
|
+
multiplier = constraint.multiplier
|
224
|
+
constant = constraint.constant
|
225
|
+
priority = PRIORITY_LOOKUP_INVERSE[constraint.priority] || constraint.priority
|
226
|
+
"#{item}.#{item_attribute} #{related_by} #{to_item}.#{to_item_attribute} * #{multiplier} + #{constant} @ #{priority}"
|
227
|
+
end
|
228
|
+
|
227
229
|
end
|
228
230
|
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.5
|
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-
|
11
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Extensions and helpers for dealing with various areas of rubymotion
|
14
14
|
email:
|