motion-kit 0.17.0 → 0.18.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 +4 -4
- data/README.md +2 -2
- data/lib/motion-kit-cocoa/constraints/constraint.rb +67 -0
- data/lib/motion-kit-cocoa/constraints/constraints_target.rb +2 -27
- data/lib/motion-kit-osx/helpers/nstabview_helpers.rb +11 -0
- data/lib/motion-kit-osx/helpers/nsview_autoresizing_helpers.rb +1 -1
- data/lib/motion-kit/helpers/tree_layout.rb +1 -1
- data/lib/motion-kit/version.rb +1 -1
- data/spec/ios/constraints_helpers/active_constraints_spec.rb +25 -0
- data/spec/osx/constraints_helpers/active_constraints_spec.rb +25 -0
- data/spec/osx/custom_root_layout_spec.rb +2 -2
- data/spec/osx/nstabview_helper_spec.rb +27 -0
- metadata +24 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35471767d3b359768976d596f1c8c6e97231c02b
|
4
|
+
data.tar.gz: 0278f47cc49bf7aa77906ef06f143f36ea52faf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c460d3c67c1f3cb4fa50f074061ead9c34c2e9c9dacda427bd728f8f2f1e4ff354c33907b3a00c6e498d6378668e6c359776d20dd51ff881890d54874ea13fe5
|
7
|
+
data.tar.gz: fc2ec0c29a6244223a7ac889d98128e8dca3ec1b6a6d61bf350669b030eb0c48cbb2ff6640a72e2c121eb9b291ef09944acb02e4c8ab7b954a307b5e459a8aee
|
data/README.md
CHANGED
@@ -717,10 +717,10 @@ One common use case is to use a child layout to create many instances of the
|
|
717
717
|
same layout that repeat, for instance a "row" of content. In this case you will
|
718
718
|
probably have many views with the same id, and you will not know the index of
|
719
719
|
the container view that you want to add constraints to. In this situation, use
|
720
|
-
the `nearest`, `
|
720
|
+
the `nearest`, `prev` or `next` method to find a container, sibling, or
|
721
721
|
child view.
|
722
722
|
|
723
|
-
`
|
723
|
+
`prev` and `next` are easy; they just search for a sibling view. No
|
724
724
|
superviews or subviews are searched.
|
725
725
|
|
726
726
|
`nearest` will search child views, siblings, and superviews, in that order. The
|
@@ -55,6 +55,7 @@ module MotionKit
|
|
55
55
|
@constant = 0
|
56
56
|
@priority = nil
|
57
57
|
@compare_flag = false
|
58
|
+
@active = true
|
58
59
|
end
|
59
60
|
|
60
61
|
# like `equals`, but also sets `compare_flag` to true, so you can use ==,
|
@@ -270,6 +271,72 @@ module MotionKit
|
|
270
271
|
end
|
271
272
|
end
|
272
273
|
|
274
|
+
def active
|
275
|
+
@active
|
276
|
+
end
|
277
|
+
|
278
|
+
def active=(active)
|
279
|
+
if @resolved
|
280
|
+
if active
|
281
|
+
@resolved.each do |constraint|
|
282
|
+
common_ancestor.addConstraint(constraint)
|
283
|
+
end
|
284
|
+
else
|
285
|
+
@resolved.each do |constraint|
|
286
|
+
common_ancestor.removeConstraint(constraint)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
else
|
290
|
+
@active = active
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def activate
|
295
|
+
self.active = true
|
296
|
+
self
|
297
|
+
end
|
298
|
+
|
299
|
+
def deactivate
|
300
|
+
self.active = false
|
301
|
+
self
|
302
|
+
end
|
303
|
+
|
304
|
+
def common_ancestor
|
305
|
+
if @resolved
|
306
|
+
@common_ancestor ||= begin
|
307
|
+
constraint = @resolved[0]
|
308
|
+
base_view_class = MotionKit.base_view_class
|
309
|
+
|
310
|
+
if constraint.firstItem.is_a?(base_view_class) && constraint.secondItem.is_a?(base_view_class)
|
311
|
+
common_ancestor = nil
|
312
|
+
|
313
|
+
ancestors = [constraint.firstItem]
|
314
|
+
parent_view = constraint.firstItem
|
315
|
+
while parent_view = parent_view.superview
|
316
|
+
ancestors << parent_view
|
317
|
+
end
|
318
|
+
|
319
|
+
current_view = constraint.secondItem
|
320
|
+
while current_view
|
321
|
+
if ancestors.include? current_view
|
322
|
+
common_ancestor = current_view
|
323
|
+
break
|
324
|
+
end
|
325
|
+
current_view = current_view.superview
|
326
|
+
end
|
327
|
+
|
328
|
+
unless common_ancestor
|
329
|
+
raise NoCommonAncestorError.new("No common ancestors between #{constraint.firstItem} and #{constraint.secondItem}")
|
330
|
+
end
|
331
|
+
else
|
332
|
+
common_ancestor = constraint.firstItem
|
333
|
+
end
|
334
|
+
|
335
|
+
common_ancestor
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
273
340
|
class << self
|
274
341
|
|
275
342
|
def axis_lookup(axis)
|
@@ -23,34 +23,9 @@ module MotionKit
|
|
23
23
|
def apply_all_constraints(layout, target)
|
24
24
|
@constraints.map do |mk_constraint|
|
25
25
|
mk_constraint.resolve_all(layout, target).map do |constraint|
|
26
|
-
|
27
|
-
|
28
|
-
if constraint.firstItem.is_a?(base_view_class) && constraint.secondItem.is_a?(base_view_class)
|
29
|
-
common_ancestor = nil
|
30
|
-
|
31
|
-
ancestors = [constraint.firstItem]
|
32
|
-
parent_view = constraint.firstItem
|
33
|
-
while parent_view = parent_view.superview
|
34
|
-
ancestors << parent_view
|
35
|
-
end
|
36
|
-
|
37
|
-
current_view = constraint.secondItem
|
38
|
-
while current_view
|
39
|
-
if ancestors.include? current_view
|
40
|
-
common_ancestor = current_view
|
41
|
-
break
|
42
|
-
end
|
43
|
-
current_view = current_view.superview
|
44
|
-
end
|
45
|
-
|
46
|
-
unless common_ancestor
|
47
|
-
raise NoCommonAncestorError.new("No common ancestors between #{constraint.firstItem} and #{constraint.secondItem}")
|
48
|
-
end
|
49
|
-
else
|
50
|
-
common_ancestor = constraint.firstItem
|
26
|
+
if mk_constraint.active
|
27
|
+
mk_constraint.common_ancestor.addConstraint(constraint)
|
51
28
|
end
|
52
|
-
|
53
|
-
common_ancestor.addConstraint(constraint)
|
54
29
|
constraint
|
55
30
|
end
|
56
31
|
end.flatten
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class NSTabViewHelpers < MK::NSViewHelpers
|
2
|
+
targets NSTabView
|
3
|
+
|
4
|
+
def add_tab(identifier, label, &block)
|
5
|
+
tab_view_item = NSTabViewItem.alloc.initWithIdentifier(identifier)
|
6
|
+
tab_view_item.label = label
|
7
|
+
target.addTabViewItem(tab_view_item)
|
8
|
+
tab_view_item.view = NSView.alloc.initWithFrame(target.contentRect)
|
9
|
+
context(tab_view_item.view, &block)
|
10
|
+
end
|
11
|
+
end
|
@@ -39,7 +39,7 @@ module MotionKit
|
|
39
39
|
when :fill_bottom
|
40
40
|
value |= NSViewWidthSizable | NSViewMaxYMargin
|
41
41
|
when :fill_width
|
42
|
-
value |= NSViewMinYMargin | NSViewWidthSizable |
|
42
|
+
value |= NSViewMinYMargin | NSViewWidthSizable | NSViewMaxYMargin
|
43
43
|
when :fill_left
|
44
44
|
value |= NSViewHeightSizable | NSViewMaxXMargin
|
45
45
|
when :fill_right
|
@@ -197,7 +197,7 @@ module MotionKit
|
|
197
197
|
|
198
198
|
def initial(&block)
|
199
199
|
raise ArgumentError.new('Block required') unless block
|
200
|
-
puts('
|
200
|
+
puts('the `initial` method is no longer necessary! all code that *isn\'t in a `reapply` block is now only applied during initial setup.')
|
201
201
|
|
202
202
|
if initial?
|
203
203
|
yield
|
data/lib/motion-kit/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
describe 'Constraints - activate/deactivate helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MotionKit::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = UIView.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'should activate/deactivate constraints' do
|
10
|
+
|
11
|
+
@layout.context(@view) do
|
12
|
+
@layout.constraints do
|
13
|
+
@constraint = @layout.height(10)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@view.constraints.count.should == 1
|
18
|
+
@constraint.deactivate
|
19
|
+
@view.constraints.count.should == 0
|
20
|
+
@constraint.activate
|
21
|
+
@view.constraints.count.should == 1
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe 'Constraints - activate/deactivate helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MotionKit::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = NSView.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'should activate/deactivate constraints' do
|
10
|
+
|
11
|
+
@layout.context(@view) do
|
12
|
+
@layout.constraints do
|
13
|
+
@constraint = @layout.height(10)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
@view.constraints.count.should == 1
|
18
|
+
@constraint.deactivate
|
19
|
+
@view.constraints.count.should == 0
|
20
|
+
@constraint.activate
|
21
|
+
@view.constraints.count.should == 1
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -50,8 +50,8 @@ describe 'Custom Root Layouts' do
|
|
50
50
|
it "should allow bare styles in layout when root is specified in initializer" do
|
51
51
|
@subject = TestNoRootLayout.new(root: @view).build
|
52
52
|
@subject.view.should == @view
|
53
|
-
@subject.view.backgroundColor.should ==
|
54
|
-
@subject.view.subviews.first.should.be.kind_of?(
|
53
|
+
@subject.view.backgroundColor.should == NSColor.redColor
|
54
|
+
@subject.view.subviews.first.should.be.kind_of?(NSTextField)
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe 'NSTabView helpers' do
|
2
|
+
class TestTabViewLayout < MK::Layout
|
3
|
+
def layout
|
4
|
+
add NSTabView, :tab_view do
|
5
|
+
add_tab "tab_identifier", "tab_label" do
|
6
|
+
wantsLayer true
|
7
|
+
backgroundColor NSColor.redColor
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should support `add_tab` method' do
|
14
|
+
@layout = TestTabViewLayout.new
|
15
|
+
|
16
|
+
view = NSView.alloc.initWithFrame([[0, 0], [500, 500]])
|
17
|
+
view.addSubview(@layout.view)
|
18
|
+
|
19
|
+
@tab_view = @layout.get(:tab_view)
|
20
|
+
|
21
|
+
@tab_view.numberOfTabViewItems.should == 1
|
22
|
+
@tab_view.tabViewItems.first.identifier.should == "tab_identifier"
|
23
|
+
@tab_view.tabViewItems.first.label.should == "tab_label"
|
24
|
+
@tab_view.tabViewItems.first.view.wantsLayer.should == true
|
25
|
+
@tab_view.tabViewItems.first.view.backgroundColor.should == NSColor.redColor
|
26
|
+
end
|
27
|
+
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.
|
4
|
+
version: 0.18.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:
|
12
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dbt
|
@@ -34,19 +34,7 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
-
-
|
38
|
-
- lib/motion-kit/calculator/calculator.rb
|
39
|
-
- lib/motion-kit/calculator/frame_calculator.rb
|
40
|
-
- lib/motion-kit/calculator/origin_calculator.rb
|
41
|
-
- lib/motion-kit/calculator/size_calculator.rb
|
42
|
-
- lib/motion-kit/helpers/base_layout.rb
|
43
|
-
- lib/motion-kit/helpers/base_layout_class_methods.rb
|
44
|
-
- lib/motion-kit/helpers/parent.rb
|
45
|
-
- lib/motion-kit/helpers/tree_layout.rb
|
46
|
-
- lib/motion-kit/motion-kit.rb
|
47
|
-
- lib/motion-kit/object.rb
|
48
|
-
- lib/motion-kit/util.rb
|
49
|
-
- lib/motion-kit/version.rb
|
37
|
+
- README.md
|
50
38
|
- lib/motion-kit-cocoa/calculator/view_calculator.rb
|
51
39
|
- lib/motion-kit-cocoa/cocoa_util.rb
|
52
40
|
- lib/motion-kit-cocoa/constraints/constraint.rb
|
@@ -79,6 +67,7 @@ files:
|
|
79
67
|
- lib/motion-kit-osx/helpers/nsmenuitem_extensions.rb
|
80
68
|
- lib/motion-kit-osx/helpers/nstablecolumn_helpers.rb
|
81
69
|
- lib/motion-kit-osx/helpers/nstableview_helpers.rb
|
70
|
+
- lib/motion-kit-osx/helpers/nstabview_helpers.rb
|
82
71
|
- lib/motion-kit-osx/helpers/nsview_autoresizing_helpers.rb
|
83
72
|
- lib/motion-kit-osx/helpers/nsview_constraints_helpers.rb
|
84
73
|
- lib/motion-kit-osx/helpers/nsview_frame_helpers.rb
|
@@ -87,13 +76,26 @@ files:
|
|
87
76
|
- lib/motion-kit-osx/helpers/nswindow_helpers.rb
|
88
77
|
- lib/motion-kit-osx/osx_util.rb
|
89
78
|
- lib/motion-kit.rb
|
90
|
-
-
|
79
|
+
- lib/motion-kit/calculator/calculate.rb
|
80
|
+
- lib/motion-kit/calculator/calculator.rb
|
81
|
+
- lib/motion-kit/calculator/frame_calculator.rb
|
82
|
+
- lib/motion-kit/calculator/origin_calculator.rb
|
83
|
+
- lib/motion-kit/calculator/size_calculator.rb
|
84
|
+
- lib/motion-kit/helpers/base_layout.rb
|
85
|
+
- lib/motion-kit/helpers/base_layout_class_methods.rb
|
86
|
+
- lib/motion-kit/helpers/parent.rb
|
87
|
+
- lib/motion-kit/helpers/tree_layout.rb
|
88
|
+
- lib/motion-kit/motion-kit.rb
|
89
|
+
- lib/motion-kit/object.rb
|
90
|
+
- lib/motion-kit/util.rb
|
91
|
+
- lib/motion-kit/version.rb
|
91
92
|
- spec/ios/apply_styles_spec.rb
|
92
93
|
- spec/ios/autoresizing_helper_spec.rb
|
93
94
|
- spec/ios/calayer_spec.rb
|
94
95
|
- spec/ios/calculate_spec.rb
|
95
96
|
- spec/ios/calculator_spec.rb
|
96
97
|
- spec/ios/child_layouts_spec.rb
|
98
|
+
- spec/ios/constraints_helpers/active_constraints_spec.rb
|
97
99
|
- spec/ios/constraints_helpers/attribute_lookup_spec.rb
|
98
100
|
- spec/ios/constraints_helpers/axis_lookup_spec.rb
|
99
101
|
- spec/ios/constraints_helpers/center_constraints_spec.rb
|
@@ -134,6 +136,7 @@ files:
|
|
134
136
|
- spec/ios/uitextfield_spec.rb
|
135
137
|
- spec/ios/view_attr_spec.rb
|
136
138
|
- spec/osx/autoresizing_helper_spec.rb
|
139
|
+
- spec/osx/constraints_helpers/active_constraints_spec.rb
|
137
140
|
- spec/osx/constraints_helpers/orientation_lookup_spec.rb
|
138
141
|
- spec/osx/constraints_helpers/simple_constraints_spec.rb
|
139
142
|
- spec/osx/constraints_helpers/size_constraints_spec.rb
|
@@ -145,6 +148,7 @@ files:
|
|
145
148
|
- spec/osx/menu_extensions_spec.rb
|
146
149
|
- spec/osx/menu_layout_spec.rb
|
147
150
|
- spec/osx/menu_spec.rb
|
151
|
+
- spec/osx/nstabview_helper_spec.rb
|
148
152
|
- spec/osx/nsview_frame_helper_spec.rb
|
149
153
|
- spec/osx/nswindow_frame_helper_spec.rb
|
150
154
|
- spec/osx/root_menu_spec.rb
|
@@ -169,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
173
|
version: '0'
|
170
174
|
requirements: []
|
171
175
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.4.5
|
173
177
|
signing_key:
|
174
178
|
specification_version: 4
|
175
179
|
summary: The RubyMotion layout and styling gem.
|
@@ -180,6 +184,7 @@ test_files:
|
|
180
184
|
- spec/ios/calculate_spec.rb
|
181
185
|
- spec/ios/calculator_spec.rb
|
182
186
|
- spec/ios/child_layouts_spec.rb
|
187
|
+
- spec/ios/constraints_helpers/active_constraints_spec.rb
|
183
188
|
- spec/ios/constraints_helpers/attribute_lookup_spec.rb
|
184
189
|
- spec/ios/constraints_helpers/axis_lookup_spec.rb
|
185
190
|
- spec/ios/constraints_helpers/center_constraints_spec.rb
|
@@ -220,6 +225,7 @@ test_files:
|
|
220
225
|
- spec/ios/uitextfield_spec.rb
|
221
226
|
- spec/ios/view_attr_spec.rb
|
222
227
|
- spec/osx/autoresizing_helper_spec.rb
|
228
|
+
- spec/osx/constraints_helpers/active_constraints_spec.rb
|
223
229
|
- spec/osx/constraints_helpers/orientation_lookup_spec.rb
|
224
230
|
- spec/osx/constraints_helpers/simple_constraints_spec.rb
|
225
231
|
- spec/osx/constraints_helpers/size_constraints_spec.rb
|
@@ -231,6 +237,7 @@ test_files:
|
|
231
237
|
- spec/osx/menu_extensions_spec.rb
|
232
238
|
- spec/osx/menu_layout_spec.rb
|
233
239
|
- spec/osx/menu_spec.rb
|
240
|
+
- spec/osx/nstabview_helper_spec.rb
|
234
241
|
- spec/osx/nsview_frame_helper_spec.rb
|
235
242
|
- spec/osx/nswindow_frame_helper_spec.rb
|
236
243
|
- spec/osx/root_menu_spec.rb
|