motion-kit 0.9.4 → 0.9.6
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 +71 -88
- data/lib/motion-kit/calculate.rb +3 -3
- data/lib/motion-kit/layouts/base_layout.rb +11 -11
- data/lib/motion-kit/layouts/{view_layout.rb → tree_layout.rb} +16 -14
- data/lib/motion-kit/version.rb +1 -1
- data/lib/motion-kit-cocoa/constraints/constraint.rb +2 -2
- data/lib/motion-kit-cocoa/layouts/cagradientlayer_layout.rb +2 -2
- data/lib/motion-kit-cocoa/layouts/calayer_layout.rb +2 -2
- data/lib/motion-kit-ios/ios_util.rb +4 -0
- data/lib/motion-kit-ios/layouts/uiview_layout.rb +2 -2
- data/lib/motion-kit-ios/layouts/uiview_layout_frame.rb +16 -1
- data/lib/motion-kit-osx/layouts/nsmenu_layout.rb +2 -2
- data/lib/motion-kit-osx/layouts/nsview_layout.rb +2 -2
- data/lib/motion-kit-osx/layouts/nswindow_layout.rb +2 -2
- data/lib/motion-kit-osx/osx_util.rb +4 -0
- data/lib/motion-kit.rb +1 -0
- data/spec/ios/apply_styles_spec.rb +1 -0
- data/spec/ios/frame_helper_spec.rb +11 -0
- data/spec/ios/uibutton_layout_spec.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca8bcc4c3162610c0090bb119ed03e2c1ebf5484
|
4
|
+
data.tar.gz: 002fd919664672e8b07fc6a56ac8103e4d61b75b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 125fd67fafeeccbed6778c15281a9bdd4f1e4cb48d28f57edd18dec56089345cec1069a3a7b2c407e194efe8241d9c6285179fff28354078467810027e1239b5
|
7
|
+
data.tar.gz: 85d2bf979800eee4f63d2114fc0cda48a2a2918ee0b2a8f9f2a38828e97f482b571ef6e4702930ddc2d17ddecdd0f22368a35a79c99e817fd6f3c829a1764bb2
|
data/README.md
CHANGED
@@ -43,6 +43,12 @@ be replaced with a new project, rather than upgraded or refactored.
|
|
43
43
|
|
44
44
|
## Usage
|
45
45
|
|
46
|
+
Install:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem install 'motion-kit'
|
50
|
+
```
|
51
|
+
|
46
52
|
From your controller you will instantiate a `MotionKit::Layout` instance, and
|
47
53
|
request views from it. `layout.view` is the root view, and it's common to
|
48
54
|
assign this to `self.view` in your `loadView` method. You'll also want to hook
|
@@ -346,8 +352,9 @@ module MotionKit
|
|
346
352
|
end
|
347
353
|
```
|
348
354
|
|
349
|
-
For your own custom classes,
|
350
|
-
`
|
355
|
+
For your own custom classes, or built-in classes that don't already have a
|
356
|
+
`Layout` class defined, you can provide a Layout class by calling the `targets`
|
357
|
+
method in your class body.
|
351
358
|
|
352
359
|
```ruby
|
353
360
|
# Be sure to extend an existing Layout class, otherwise you'll lose a lot of
|
@@ -494,59 +501,7 @@ be using Cocoa's Auto Layout system instead. This is the recommended way to set
|
|
494
501
|
your frames, now that Apple is introducing multiple display sizes. But beware,
|
495
502
|
Auto Layout can be frustrating... :-/
|
496
503
|
|
497
|
-
|
498
|
-
your views. We tried really hard to figure out a way to automatically add them,
|
499
|
-
but it's just an untenable problem (Teacup suffers from a similar conundrum).
|
500
|
-
|
501
|
-
Essentially, the problem comes down to this: you will often want to set
|
502
|
-
constraints that are related to the view controller's `view`, but those must be
|
503
|
-
created/set *after* `controller.view = @layout.view`. Without doing some crazy
|
504
|
-
method mangling on NS/UIView we just can't do this automatically
|
505
|
-
|
506
|
-
Long story short: If you need to create constraints that refer to the controller
|
507
|
-
view, you need to use a separate method that is called after the view hierarchy
|
508
|
-
is created.
|
509
|
-
|
510
|
-
```ruby
|
511
|
-
class MainLayout < UIViewLayout
|
512
|
-
|
513
|
-
def layout
|
514
|
-
add UILabel, :label do
|
515
|
-
constraints do
|
516
|
-
x 0
|
517
|
-
width('100%')
|
518
|
-
end
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
def add_constraints(controller)
|
523
|
-
unless @layout_constraints_added
|
524
|
-
@layout_constraints_added = true
|
525
|
-
constraints(:label) do
|
526
|
-
top.equals(controller.topLayoutGuide)
|
527
|
-
end
|
528
|
-
end
|
529
|
-
end
|
530
|
-
|
531
|
-
end
|
532
|
-
|
533
|
-
class MainController < UIViewController
|
534
|
-
|
535
|
-
def loadView
|
536
|
-
@layout = MainLayout.new
|
537
|
-
self.view = @layout
|
538
|
-
end
|
539
|
-
|
540
|
-
# for the constraints to work reliably they should be added in this method:
|
541
|
-
def updateViewConstraints
|
542
|
-
@layout.add_constraints(self) # !!!
|
543
|
-
super
|
544
|
-
end
|
545
|
-
|
546
|
-
end
|
547
|
-
```
|
548
|
-
|
549
|
-
OK, with that hack out of the way, on to the examples!
|
504
|
+
Here are some examples to get started:
|
550
505
|
|
551
506
|
```ruby
|
552
507
|
constraints do
|
@@ -633,50 +588,61 @@ add UIView, :bar do
|
|
633
588
|
end
|
634
589
|
```
|
635
590
|
|
636
|
-
|
591
|
+
One pain point in working with constraints is determining when to add them to
|
592
|
+
your views. We tried really hard to figure out a way to automatically add them,
|
593
|
+
but it's just an untenable problem (Teacup suffers from a similar conundrum).
|
594
|
+
|
595
|
+
Essentially, the problem comes down to this: you will often want to set
|
596
|
+
constraints that are related to the view controller's `view`, but those must be
|
597
|
+
created/set *after* `controller.view = @layout.view`. Without doing some crazy
|
598
|
+
method mangling on NS/UIView we just can't do this automatically
|
637
599
|
|
638
|
-
|
600
|
+
Long story short: If you need to create constraints that refer to the controller
|
601
|
+
view, you need to use a separate method that is called after the view hierarchy
|
602
|
+
is created.
|
639
603
|
|
640
604
|
```ruby
|
641
|
-
|
642
|
-
frame [[0, 0], [320, 568]]
|
643
|
-
# using relative sizes (relative to superview)
|
644
|
-
frame [[5, 5], ['100% - 10', '100% - 10']]
|
605
|
+
class MainLayout < UIViewLayout
|
645
606
|
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
607
|
+
def layout
|
608
|
+
add UILabel, :label do
|
609
|
+
constraints do
|
610
|
+
x 0
|
611
|
+
width('100%')
|
612
|
+
end
|
613
|
+
end
|
614
|
+
end
|
653
615
|
|
654
|
-
|
655
|
-
|
616
|
+
# this method will be called from `UIViewController#updateViewConstraints`
|
617
|
+
def add_constraints(controller)
|
618
|
+
unless @layout_constraints_added
|
619
|
+
@layout_constraints_added = true
|
620
|
+
constraints(:label) do
|
621
|
+
top.equals(controller.topLayoutGuide)
|
622
|
+
end
|
623
|
+
end
|
624
|
+
end
|
656
625
|
|
657
|
-
|
658
|
-
# *any* other view.
|
659
|
-
from_bottom_right size: [100, 100] # 100x100pt in the BR corner
|
660
|
-
from_bottom size: ['100%', 32] # full width, 32pt height
|
661
|
-
from_top_right left: 5
|
626
|
+
end
|
662
627
|
|
663
|
-
|
664
|
-
# from_left from_center from_right
|
665
|
-
# from_bottom_left from_bottom from_bottom_right
|
628
|
+
class MainController < UIViewController
|
666
629
|
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
#
|
673
|
-
|
674
|
-
|
675
|
-
|
630
|
+
def loadView
|
631
|
+
@layout = MainLayout.new
|
632
|
+
self.view = @layout
|
633
|
+
end
|
634
|
+
|
635
|
+
# for the constraints to work reliably they should be added in this method:
|
636
|
+
def updateViewConstraints
|
637
|
+
@layout.add_constraints(self)
|
638
|
+
super
|
639
|
+
end
|
640
|
+
|
641
|
+
end
|
676
642
|
```
|
677
643
|
|
678
644
|
|
679
|
-
### Some handy tricks
|
645
|
+
### Some handy tricks and Features
|
680
646
|
|
681
647
|
#### Orientation specific styles
|
682
648
|
|
@@ -731,6 +697,7 @@ def login_button_style
|
|
731
697
|
end
|
732
698
|
```
|
733
699
|
|
700
|
+
|
734
701
|
#### Apply styles via module
|
735
702
|
|
736
703
|
```ruby
|
@@ -760,6 +727,22 @@ class LoginLayout < MotionKit::Layout
|
|
760
727
|
end
|
761
728
|
```
|
762
729
|
|
730
|
+
|
731
|
+
#### Setting a custom root view
|
732
|
+
|
733
|
+
If you need to use a custom root view, you can use the `root` method from within
|
734
|
+
the `layout` method. When you create or assign the root view this way, you must
|
735
|
+
assign subviews and styles *inside* a block that you pass to `root`.
|
736
|
+
|
737
|
+
```ruby
|
738
|
+
def layout
|
739
|
+
root(SomeOtherViewclass) do
|
740
|
+
add UILabel
|
741
|
+
end
|
742
|
+
end
|
743
|
+
```
|
744
|
+
|
745
|
+
|
763
746
|
# Contributing
|
764
747
|
|
765
748
|
We welcome your contributions! Please be sure to run the specs before you do,
|
data/lib/motion-kit/calculate.rb
CHANGED
@@ -57,7 +57,7 @@ module MotionKit
|
|
57
57
|
y_offset = 0
|
58
58
|
|
59
59
|
if amount.is_a?(Hash)
|
60
|
-
if amount
|
60
|
+
if amount[:relative]
|
61
61
|
if amount.key?(:x)
|
62
62
|
x = amount[:x]
|
63
63
|
else
|
@@ -91,7 +91,7 @@ module MotionKit
|
|
91
91
|
else
|
92
92
|
if amount.key?(:right)
|
93
93
|
x_offset = -my_size.width
|
94
|
-
x = amount
|
94
|
+
x = amount[:right]
|
95
95
|
elsif amount.key?(:x) || amount.key?(:left)
|
96
96
|
x = amount[:x] || amount[:left]
|
97
97
|
elsif dimension == :center
|
@@ -103,7 +103,7 @@ module MotionKit
|
|
103
103
|
|
104
104
|
if amount.key?(:bottom)
|
105
105
|
y_offset = -my_size.height
|
106
|
-
y = amount
|
106
|
+
y = amount[:bottom]
|
107
107
|
elsif amount.key?(:y) || amount.key?(:top)
|
108
108
|
y = amount[:y] || amount[:top]
|
109
109
|
elsif dimension == :center
|
@@ -8,7 +8,7 @@ module MotionKit
|
|
8
8
|
# delegated to the 'apply' method, which accepts a method name, arguments, and
|
9
9
|
# an optional block to set the new context.
|
10
10
|
#
|
11
|
-
# The
|
11
|
+
# The TreeLayout subclass defines methods that are appropriate for adding and
|
12
12
|
# removing views to a view hierarchy.
|
13
13
|
class BaseLayout
|
14
14
|
# Class methods reside in base_layout_class_methods.rb
|
@@ -167,7 +167,7 @@ module MotionKit
|
|
167
167
|
begin
|
168
168
|
target = self.target
|
169
169
|
rescue NoContextError => e
|
170
|
-
raise NoMethodError.new(method_name)
|
170
|
+
raise NoMethodError.new("undefined method `#{method_name}' for #{self}:#{self.class}", method_name)
|
171
171
|
end
|
172
172
|
|
173
173
|
if args.length == 2 && args[1].is_a?(Hash) && !args[1].empty?
|
@@ -188,7 +188,7 @@ module MotionKit
|
|
188
188
|
if block
|
189
189
|
apply_with_context(method_name, *args, &block)
|
190
190
|
else
|
191
|
-
apply_with_target(method_name, *args)
|
191
|
+
apply_with_target(method_name, *args, &block)
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
@@ -215,7 +215,7 @@ module MotionKit
|
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
|
-
def apply_with_target(method_name, *args)
|
218
|
+
def apply_with_target(method_name, *args, &block)
|
219
219
|
setter = MotionKit.setter(method_name)
|
220
220
|
assign = "#{method_name}="
|
221
221
|
if args.length == 2 && args[1].is_a?(Hash) && !args[1].empty?
|
@@ -234,24 +234,24 @@ module MotionKit
|
|
234
234
|
# combined getter/setter (`layer(val)`)
|
235
235
|
# - lastly, try again after converting to camelCase
|
236
236
|
if long_method_name && target.respond_to?(long_method_name)
|
237
|
-
target.send(long_method_name, *long_method_args)
|
237
|
+
target.send(long_method_name, *long_method_args, &block)
|
238
238
|
elsif args.empty? && target.respond_to?(method_name)
|
239
|
-
target.send(method_name, *args)
|
239
|
+
target.send(method_name, *args, &block)
|
240
240
|
elsif target.respond_to?(setter)
|
241
|
-
target.send(setter, *args)
|
241
|
+
target.send(setter, *args, &block)
|
242
242
|
elsif target.respond_to?(assign)
|
243
|
-
target.send(assign, *args)
|
243
|
+
target.send(assign, *args, &block)
|
244
244
|
elsif target.respond_to?(method_name)
|
245
|
-
target.send(method_name, *args)
|
245
|
+
target.send(method_name, *args, &block)
|
246
246
|
# UIAppearance classes are a whole OTHER thing; they never return 'true'
|
247
247
|
elsif target.is_a?(MotionKit.appearance_class)
|
248
|
-
target.send(setter, *args)
|
248
|
+
target.send(setter, *args, &block)
|
249
249
|
# Finally, try again with camel case if there's an underscore.
|
250
250
|
elsif method_name.include?('_')
|
251
251
|
objc_name = MotionKit.objective_c_method_name(method_name)
|
252
252
|
self.apply(objc_name, *args)
|
253
253
|
else
|
254
|
-
target.send(setter, *args)
|
254
|
+
target.send(setter, *args, &block)
|
255
255
|
# raise ApplyError.new("Cannot apply #{method_name.inspect} to instance of #{target.class.name} (from #{@layout_delegate && @layout_delegate.class})")
|
256
256
|
end
|
257
257
|
end
|
@@ -1,14 +1,12 @@
|
|
1
|
-
# @provides MotionKit::
|
1
|
+
# @provides MotionKit::TreeLayout
|
2
2
|
# @requires MotionKit::BaseLayout
|
3
3
|
module MotionKit
|
4
|
-
# A sensible parent class for any
|
5
|
-
# Any platform-specific tasks are offloaded to child
|
6
|
-
# remove_child).
|
7
|
-
# Actually, "view like" is misleading, since technically it only assumes "tree
|
8
|
-
# like". You could use a ViewLayout subclass to construct a hierarchy
|
4
|
+
# A sensible parent class for any Tree-like layout class. Platform agnostic.
|
5
|
+
# Any platform-specific tasks are offloaded to child elements (add_child,
|
6
|
+
# remove_child). You could use a TreeLayout subclass to construct a hierarchy
|
9
7
|
# representing a family tree, for instance. But that would be a silly use of
|
10
8
|
# MotionKit.
|
11
|
-
class
|
9
|
+
class TreeLayout < BaseLayout
|
12
10
|
|
13
11
|
class << self
|
14
12
|
|
@@ -159,9 +157,9 @@ module MotionKit
|
|
159
157
|
return self
|
160
158
|
end
|
161
159
|
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
160
|
+
# Instantiates a view via `create` and adds the view to the current target.
|
161
|
+
# If no view exists on the stack, a default root view can be created if that
|
162
|
+
# has been enabled. The block is run in the context of the new view.
|
165
163
|
def add(element, element_id=nil, &block)
|
166
164
|
# make sure we have a target - raises NoContextError if none exists
|
167
165
|
self.target
|
@@ -171,7 +169,11 @@ module MotionKit
|
|
171
169
|
create_default_root_context
|
172
170
|
end
|
173
171
|
self.apply(:add_child, element)
|
174
|
-
create(element, element_id
|
172
|
+
create(element, element_id)
|
173
|
+
|
174
|
+
if block
|
175
|
+
context(element, &block)
|
176
|
+
end
|
175
177
|
|
176
178
|
element
|
177
179
|
end
|
@@ -278,7 +280,7 @@ module MotionKit
|
|
278
280
|
if @assign_root
|
279
281
|
create_default_root_context
|
280
282
|
else
|
281
|
-
NSLog('Warning! No root view was set in
|
283
|
+
NSLog('Warning! No root view was set in TreeLayout#layout. Did you mean to call `root`?')
|
282
284
|
end
|
283
285
|
end
|
284
286
|
run_deferred(@view)
|
@@ -311,11 +313,11 @@ module MotionKit
|
|
311
313
|
# Accepts a view instance, a class (which is instantiated with 'new') or a
|
312
314
|
# `ViewLayout`, which returns the root view.
|
313
315
|
def initialize_view(elem)
|
314
|
-
if elem.is_a?(Class) && elem <
|
316
|
+
if elem.is_a?(Class) && elem < TreeLayout
|
315
317
|
elem = elem.new_child(@layout, nil, self).view
|
316
318
|
elsif elem.is_a?(Class)
|
317
319
|
elem = elem.new
|
318
|
-
elsif elem.is_a?(
|
320
|
+
elsif elem.is_a?(TreeLayout)
|
319
321
|
elem = elem.view
|
320
322
|
end
|
321
323
|
|
data/lib/motion-kit/version.rb
CHANGED
@@ -395,11 +395,11 @@ module MotionKit
|
|
395
395
|
end
|
396
396
|
|
397
397
|
def attribute=(value)
|
398
|
-
raise NoMethodError.new('attribute=
|
398
|
+
raise NoMethodError.new("undefined method `#{:attribute=}' for #{self}:#{self.class}", :attribute=)
|
399
399
|
end
|
400
400
|
|
401
401
|
def attribute2=(value)
|
402
|
-
raise NoMethodError.new('attribute2=
|
402
|
+
raise NoMethodError.new("undefined method `#{:attribute2=}' for #{self}:#{self.class}", :attribute2=)
|
403
403
|
end
|
404
404
|
|
405
405
|
def constant=(constant)
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# @provides MotionKit::CAGradientLayerLayout
|
2
2
|
# @requires MotionKit::CALayerLayout
|
3
|
-
# @requires MotionKit::
|
3
|
+
# @requires MotionKit::TreeLayout
|
4
4
|
module MotionKit
|
5
5
|
class CAGradientLayerLayout < CALayerLayout
|
6
6
|
targets CAGradientLayer
|
7
7
|
|
8
8
|
def colors(values)
|
9
|
-
target.colors = values.map { |color| color.is_a?(
|
9
|
+
target.colors = values.map { |color| color.is_a?(MotionKit.color_class) ? color.CGColor : color }
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# @provides MotionKit::Layout
|
2
2
|
# @provides MotionKit::UIViewLayout
|
3
|
-
# @requires MotionKit::
|
3
|
+
# @requires MotionKit::TreeLayout
|
4
4
|
module MotionKit
|
5
|
-
class Layout <
|
5
|
+
class Layout < TreeLayout
|
6
6
|
|
7
7
|
# platform specific default root view
|
8
8
|
def default_root
|
@@ -107,7 +107,7 @@ module MotionKit
|
|
107
107
|
if f.is_a?(Hash)
|
108
108
|
f = f.merge(relative: true)
|
109
109
|
end
|
110
|
-
f = MotionKit.calculate(calculate_view, :frame, f,
|
110
|
+
f = MotionKit.calculate(calculate_view, :frame, f, target.superview)
|
111
111
|
f.origin.x += o.x
|
112
112
|
f.origin.y += o.y
|
113
113
|
|
@@ -272,18 +272,27 @@ module MotionKit
|
|
272
272
|
|
273
273
|
# The first arg can be a view or a frame
|
274
274
|
# @example
|
275
|
+
# frame above(view, [[0, 0], [100, 20]])
|
276
|
+
# frame above(:view, x: 0, y: 0, width: 100, height: 20)
|
277
|
+
# frame above(:view, down: 0, right: 0, width: 100, height: 20)
|
275
278
|
def above(from_view, f={})
|
276
279
|
_calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :above })
|
277
280
|
end
|
278
281
|
|
279
282
|
# The first arg can be a view or a frame
|
280
283
|
# @example
|
284
|
+
# frame below(view, [[0, 0], [100, 20]])
|
285
|
+
# frame below(:view, x: 0, y: 0, width: 100, height: 20)
|
286
|
+
# frame below(:view, down: 0, right: 0, width: 100, height: 20)
|
281
287
|
def below(from_view, f={})
|
282
288
|
_calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :below })
|
283
289
|
end
|
284
290
|
|
285
291
|
# The first arg can be a view or a frame
|
286
292
|
# @example
|
293
|
+
# frame before(view, [[0, 0], [100, 20]])
|
294
|
+
# frame before(:view, x: 0, y: 0, width: 100, height: 20)
|
295
|
+
# frame before(:view, down: 0, right: 0, width: 100, height: 20)
|
287
296
|
def before(from_view, f={})
|
288
297
|
_calculate_frame(f, from: from_view, relative_to: { x: :before, y: :reset })
|
289
298
|
end
|
@@ -291,6 +300,9 @@ module MotionKit
|
|
291
300
|
|
292
301
|
# The first arg can be a view or a frame
|
293
302
|
# @example
|
303
|
+
# frame after(view, [[0, 0], [100, 20]])
|
304
|
+
# frame after(:view, x: 0, y: 0, width: 100, height: 20)
|
305
|
+
# frame after(:view, down: 0, right: 0, width: 100, height: 20)
|
294
306
|
def after(from_view, f={})
|
295
307
|
_calculate_frame(f, from: from_view, relative_to: { x: :after, y: :reset })
|
296
308
|
end
|
@@ -298,6 +310,9 @@ module MotionKit
|
|
298
310
|
|
299
311
|
# The first arg must be a view
|
300
312
|
# @example
|
313
|
+
# frame relative_to(view, [[0, 0], [100, 20]])
|
314
|
+
# frame relative_to(:view, x: 0, y: 0, width: 100, height: 20)
|
315
|
+
# frame relative_to(:view, down: 0, right: 0, width: 100, height: 20)
|
301
316
|
def relative_to(from_view, f)
|
302
317
|
_calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :reset })
|
303
318
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# @provides MotionKit::MenuLayout
|
2
2
|
# @provides MotionKit::NSMenuLayout
|
3
|
-
# @requires MotionKit::
|
3
|
+
# @requires MotionKit::TreeLayout
|
4
4
|
module MotionKit
|
5
|
-
class MenuLayout <
|
5
|
+
class MenuLayout < TreeLayout
|
6
6
|
|
7
7
|
# A more sensible name for the menu that is created.
|
8
8
|
def menu
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# @provides MotionKit::Layout
|
2
2
|
# @provides MotionKit::NSViewLayout
|
3
|
-
# @requires MotionKit::
|
3
|
+
# @requires MotionKit::TreeLayout
|
4
4
|
module MotionKit
|
5
|
-
class Layout <
|
5
|
+
class Layout < TreeLayout
|
6
6
|
|
7
7
|
# platform specific default root view
|
8
8
|
def default_root
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# @provides MotionKit::WindowLayout
|
2
2
|
# @provides MotionKit::NSWindowLayout
|
3
|
-
# @requires MotionKit::
|
3
|
+
# @requires MotionKit::TreeLayout
|
4
4
|
module MotionKit
|
5
|
-
class WindowLayout <
|
5
|
+
class WindowLayout < TreeLayout
|
6
6
|
|
7
7
|
# A more sensible name for the window that is created.
|
8
8
|
def window
|
data/lib/motion-kit.rb
CHANGED
@@ -14,6 +14,7 @@ describe "Layouts automatically apply styles" do
|
|
14
14
|
it "should apply all styles" do
|
15
15
|
@subject.get(:logo).text.should == 'MK'
|
16
16
|
@subject.get(:label).text.should == ':label'
|
17
|
+
@subject.get(:label).numberOfLines.should == 2
|
17
18
|
@subject.get(:label).font.pointSize.should == 16
|
18
19
|
@subject.get(:label).textColor.should == UIColor.blackColor
|
19
20
|
end
|
@@ -524,6 +524,17 @@ describe 'Frame helpers' do
|
|
524
524
|
@view.frame.size.height.should == @view_size.height
|
525
525
|
end
|
526
526
|
|
527
|
+
it 'should support setting the frame via `from_top(view, width: "100%")`' do
|
528
|
+
@layout.context(@view) do
|
529
|
+
retval = @layout.frame @layout.from_top(@another_view, x: 1, y: 1, width: '100%')
|
530
|
+
retval.should == @view.frame
|
531
|
+
end
|
532
|
+
@view.frame.origin.x.should == @another_view.frame.origin.x + (@another_view.frame.size.width - @view.frame.size.width) / 2 + 1
|
533
|
+
@view.frame.origin.y.should == @another_view.frame.origin.y + 1
|
534
|
+
@view.frame.size.width.should == @superview_size.width
|
535
|
+
@view.frame.size.height.should == @view_size.height
|
536
|
+
end
|
537
|
+
|
527
538
|
it 'should support setting the frame via `from_top_right`' do
|
528
539
|
@layout.context(@view) do
|
529
540
|
retval = @layout.frame @layout.from_top_right()
|
@@ -21,4 +21,17 @@ describe 'UIButton Layout and objc-style selectors' do
|
|
21
21
|
@layout.get(:button).imageForState(UIControlStateHighlighted).should == TestButtonLayout::HIGHLIGHTED_IMAGE
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'should set the titleLabel font' do
|
25
|
+
font = @layout.get(:button).titleLabel.font
|
26
|
+
should_be_font = UIFont.fontWithName(TestButtonLayout::FONT, size: TestButtonLayout::SIZE)
|
27
|
+
|
28
|
+
font.familyName.should == should_be_font.familyName
|
29
|
+
font.pointSize.should == should_be_font.pointSize
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set the titleLabel textAlignment' do
|
33
|
+
alignment = @layout.get(:button).titleLabel.textAlignment
|
34
|
+
alignment.should == NSTextAlignmentCenter
|
35
|
+
end
|
36
|
+
|
24
37
|
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.9.
|
4
|
+
version: 0.9.6
|
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: 2014-05-
|
12
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dbt
|
@@ -38,7 +38,7 @@ files:
|
|
38
38
|
- lib/motion-kit/layouts/base_layout.rb
|
39
39
|
- lib/motion-kit/layouts/base_layout_class_methods.rb
|
40
40
|
- lib/motion-kit/layouts/parent.rb
|
41
|
-
- lib/motion-kit/layouts/
|
41
|
+
- lib/motion-kit/layouts/tree_layout.rb
|
42
42
|
- lib/motion-kit/motion-kit.rb
|
43
43
|
- lib/motion-kit/object.rb
|
44
44
|
- lib/motion-kit/util.rb
|