purplish-layout 0.0.1 → 0.0.2

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: 71e95201b9da629250ed3a65d578f119b9cbafe9
4
- data.tar.gz: c15def4fd40a8016509cfc919b79a948a5a295c5
3
+ metadata.gz: 1de41d16e7133d4c69b33c8351c2419983cdc0b9
4
+ data.tar.gz: fa932497034eb7ade0549a3810c493bcf1796c09
5
5
  SHA512:
6
- metadata.gz: c31fc8b5ceee87292c9e509cd3ae5d84bbabfbd15e7208cd575e4d0076d0380ef2bef0d1b83dae52063db658ad20e04a018a715f9ae1baf50f008f0eb161205d
7
- data.tar.gz: 300ecb78c82e7a0dfcaee0aa2917000a0e9d6e28400736352811b7ee92ce9d92cfb03de6bb3e80dc8d7aa7ad748600fd86ad029ac58dd50ef26c13818219f85f
6
+ metadata.gz: 71d5dbd7b5cf0db7fd688f76114ce1e655821c4fb268cbba7fd68cbc691f3aa7257f63dfbda42da9429eaa6a3fc47d6dd36d79e64d2692e96f132bc743d7a066
7
+ data.tar.gz: f8c63e4ed611fed978e7e59fb31a2028e50cc1fe1e379a24b7bb94c81fe7f6e4da0556c8a8bc6811e4eda085792714c81385d77c01713d2f929b1d793e04e77d
data/README.md CHANGED
@@ -30,7 +30,7 @@ Send `#constraints` with a block to an array with an even number of elements. Th
30
30
 
31
31
  If there are n views involved, there should be n*2 elements in the array. The block takes n+1 arguments, and the last object is the dictionary mapping generated from the array (usually unused) and the rest of the elements are constraint proxy objects representing each view, in the order specified in the array.
32
32
 
33
- To avoid confusion, it's best to keep the variable names in the block the same as the string names in the array. This syntax can be improved when Proc#parameters is available.
33
+ To avoid confusion, it's best to keep the variable names in the block the same as the string names in the array.
34
34
 
35
35
  With the exception of the first view listed in the array, `translatesAutoresizingMaskIntoConstraints` is automatically set to `false` for every view, so you'll want to specify the outermost view as the first pair.
36
36
 
@@ -52,11 +52,49 @@ You can mix the 2 creation methods:
52
52
  end
53
53
  ```
54
54
 
55
+ When specifying options argument describing the attribute and direction of layout, you can also use symbols such as `:align_center_y` (for `NSLayoutFormatAlignAllCenterY`). They are interchangeable. The options are available as `:align_left`, `:align_right`, `:align_top`, `:align_bottom`, `:align_leading`, `:align_trailing`, `:align_center_x`, `:align_center_y`, `:align_baseline`.
56
+
57
+ ie. these are equivalent:
58
+
59
+ ```ruby
60
+ cv.h '|[v1][v2][v3]|', nil, NSLayoutFormatAlignAllCenterY
61
+ cv.h '|[v1][v2][v3]|', nil, :align_center_y
62
+ ```
63
+
64
+ You can write equality “statements” in a single line:
65
+
66
+ ```ruby
67
+ b0.center_y = b1.center_y = b2.center_y = b3.center_y = b4.center_y
68
+ ```
69
+
55
70
  There are 2 attributes in the constraint proxies that you would occasionally find useful:
56
71
 
57
72
  * `last_constraint` returns the last `NSLayoutConstraint` created. It's useful if you want to hold on to a `NSLayoutConstraint` and modify it in an animation.
58
73
  * `next_priority` sets the priority for the next `NSLayoutConstraint` you create.
59
74
 
75
+ Quirks & Gotchas
76
+ ---
77
+ 1\. In a better world, the first code example would have been:
78
+
79
+ ```ruby
80
+ [inner_view, post_count_label].constraints do |celf, l, _|
81
+ celf.h '|[l]|'
82
+ celf.v '|-m-[l]-m-|', {'m' => 7}
83
+ end
84
+ ```
85
+
86
+ But since `Proc#parameters` isn't available, the syntax to invoke constraints requires duplication of names. This syntax can be improved when `Proc#parameters` is available.
87
+
88
+ 2\. In RubyMotion, local variables aren't shadowed correctly by dynamic variables. So try not to use the same names for the block args as the variables holding your views. Referring to the 1st example, if we use `post_count_label` instead of `l`:
89
+
90
+ ```ruby
91
+ ['celf', inner_view, 'post_count_label', post_count_label].constraints do |celf, post_count_label, _|
92
+ celf.h '|[post_count_label]|'
93
+ celf.v '|-m-[post_count_label]-m-|', {'m' => 7}
94
+ end
95
+ #At this point, after the block, post_count_label is the constraint proxy, and not the label as one might expect.
96
+ ```
97
+
60
98
  Installation
61
99
  ---
62
100
  1. Add this to your `Gemfile`: `gem 'purplish-layout'`
@@ -70,6 +70,30 @@ module PurplishLayout
70
70
 
71
71
  def layout(s, metrics=nil, options=0, views=nil)
72
72
  views ||= views_mapping
73
+ if options != 0
74
+ options = case options
75
+ when :align_left
76
+ NSLayoutFormatAlignAllLeft
77
+ when :align_right
78
+ NSLayoutFormatAlignAllRight
79
+ when :align_top
80
+ NSLayoutFormatAlignAllTop
81
+ when :align_bottom
82
+ NSLayoutFormatAlignAllBottom
83
+ when :align_leading
84
+ NSLayoutFormatAlignAllLeading
85
+ when :align_trailing
86
+ NSLayoutFormatAlignAllTrailing
87
+ when :align_center_x
88
+ NSLayoutFormatAlignAllCenterX
89
+ when :align_center_y
90
+ NSLayoutFormatAlignAllCenterY
91
+ when :align_baseline
92
+ NSLayoutFormatAlignAllBaseline
93
+ else
94
+ options
95
+ end
96
+ end
73
97
  #Workaround, must wrap views with NSDictionary, otherwise doesn't work for RubyMotion
74
98
  c = NSLayoutConstraint.constraintsWithVisualFormat(s, options:options, metrics:metrics, views:NSDictionary.dictionaryWithDictionary(views))
75
99
  self.last_constraint = c
@@ -1,3 +1,3 @@
1
1
  module PurplishLayout
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purplish-layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hwee-Boon Yar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: weak_attr_accessor