purplish-layout 0.0.1
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 +7 -0
 - data/.gitignore +6 -0
 - data/LICENSE +10 -0
 - data/README.md +77 -0
 - data/lib/purplish-layout.rb +11 -0
 - data/lib/purplish-layout/can_be_constrained.rb +31 -0
 - data/lib/purplish-layout/ns_array.rb +16 -0
 - data/lib/purplish-layout/ns_layout_constraint.rb +27 -0
 - data/lib/purplish-layout/ns_number.rb +28 -0
 - data/lib/purplish-layout/purplish-layout.rb +135 -0
 - data/lib/purplish-layout/symbol.rb +28 -0
 - data/lib/purplish-layout/version.rb +3 -0
 - data/lib/purplish-layout/view.rb +7 -0
 - data/purplish-layout.gemspec +20 -0
 - metadata +70 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 71e95201b9da629250ed3a65d578f119b9cbafe9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c15def4fd40a8016509cfc919b79a948a5a295c5
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c31fc8b5ceee87292c9e509cd3ae5d84bbabfbd15e7208cd575e4d0076d0380ef2bef0d1b83dae52063db658ad20e04a018a715f9ae1baf50f008f0eb161205d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 300ecb78c82e7a0dfcaee0aa2917000a0e9d6e28400736352811b7ee92ce9d92cfb03de6bb3e80dc8d7aa7ad748600fd86ad029ac58dd50ef26c13818219f85f
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2014, Hwee-Boon Yar
         
     | 
| 
      
 2 
     | 
    
         
            +
            All rights reserved.
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,77 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #purplish\_layout – a [RubyMotion](http://rubymotion.com) wrapper for Auto Layout on iOS and OS X
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            About
         
     | 
| 
      
 4 
     | 
    
         
            +
            ---
         
     | 
| 
      
 5 
     | 
    
         
            +
            Ruby lends itself to creating a nice DSL for Auto Layout, so why not? I have been using this for both iOS and OS X apps since mid-2014.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Usage
         
     | 
| 
      
 8 
     | 
    
         
            +
            ---
         
     | 
| 
      
 9 
     | 
    
         
            +
            Use it with visual format strings:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            ['celf', inner_view, 'l', post_count_label].constraints do |celf, l, _|
         
     | 
| 
      
 13 
     | 
    
         
            +
              celf.h '|[l]|'
         
     | 
| 
      
 14 
     | 
    
         
            +
              celf.v '|-m-[l]-m-|', {'m' => 7}
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
            ```
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            You can also create constraint objects yourself. This is equivalent to the previous example:
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 21 
     | 
    
         
            +
            ['celf', inner_view, 'l', post_count_label].constraints do |celf, l, _|
         
     | 
| 
      
 22 
     | 
    
         
            +
              celf.left = l.left
         
     | 
| 
      
 23 
     | 
    
         
            +
              celf.right = l.right
         
     | 
| 
      
 24 
     | 
    
         
            +
              l.top = celf.top + 7
         
     | 
| 
      
 25 
     | 
    
         
            +
              l.bottom = celf.bottom - 7
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
            ```
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            Send `#constraints` with a block to an array with an even number of elements. They should be pairs – the name (a `String`) to be used in the format strings in the block, followed by the view it represents.
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 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.
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 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 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            A multipler can be supplied:
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 40 
     | 
    
         
            +
              l.width = celf.width * 0.5
         
     | 
| 
      
 41 
     | 
    
         
            +
            ```
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            The attributes are available as `:left`, `:right`, `:top`, `:bottom`, `:leading`, `:trailing`, `:width`, `:height`, `:center_x`, `:center_y` and `:baseline`.
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            You can mix the 2 creation methods:
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 48 
     | 
    
         
            +
            ['celf', inner_view, 'l', post_count_label].constraints do |celf, l, _|
         
     | 
| 
      
 49 
     | 
    
         
            +
              celf.left = l.left
         
     | 
| 
      
 50 
     | 
    
         
            +
              celf.right = l.right
         
     | 
| 
      
 51 
     | 
    
         
            +
              celf.v '|-m-[l]-m-|', {'m' => 7}
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
| 
      
 53 
     | 
    
         
            +
            ```
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            There are 2 attributes in the constraint proxies that you would occasionally find useful:
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            * `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 
     | 
    
         
            +
            * `next_priority` sets the priority for the next `NSLayoutConstraint` you create.
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            Installation
         
     | 
| 
      
 61 
     | 
    
         
            +
            ---
         
     | 
| 
      
 62 
     | 
    
         
            +
            1. Add this to your `Gemfile`: `gem 'purplish-layout'`
         
     | 
| 
      
 63 
     | 
    
         
            +
            2. Run `bundle install`
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            Dependencies
         
     | 
| 
      
 66 
     | 
    
         
            +
            ---
         
     | 
| 
      
 67 
     | 
    
         
            +
            * [weak\_attr\_accessor](https://github.com/hboon/weak_attr_accessor)
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            License
         
     | 
| 
      
 70 
     | 
    
         
            +
            ---
         
     | 
| 
      
 71 
     | 
    
         
            +
            BSD. See LICENSE file.
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            Questions
         
     | 
| 
      
 74 
     | 
    
         
            +
            ---
         
     | 
| 
      
 75 
     | 
    
         
            +
            * Email: [hboon@motionobj.com](mailto:hboon@motionobj.com)
         
     | 
| 
      
 76 
     | 
    
         
            +
            * Web: [http://hboon.com/purplish-layout](http://hboon.com/purplish-layout)
         
     | 
| 
      
 77 
     | 
    
         
            +
            * Twitter: [http://twitter.com/hboon](http://twitter.com/hboon)
         
     | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            unless defined?(Motion::Project::Config)
         
     | 
| 
      
 2 
     | 
    
         
            +
              raise "This file must be required within a RubyMotion project Rakefile."
         
     | 
| 
      
 3 
     | 
    
         
            +
            end
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Motion::Project::App.setup do |app|
         
     | 
| 
      
 6 
     | 
    
         
            +
              Dir.glob(File.join(File.dirname(__FILE__), 'purplish-layout/**/*.rb')).each do |file|
         
     | 
| 
      
 7 
     | 
    
         
            +
                app.files.unshift(file)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            require 'weak_attr_accessor'
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module CanBeConstrained
         
     | 
| 
      
 2 
     | 
    
         
            +
              def constraint
         
     | 
| 
      
 3 
     | 
    
         
            +
                #Don't bother storing it, and most importantly, don't reuse it because things like multipler and constant must always be reset
         
     | 
| 
      
 4 
     | 
    
         
            +
                PurplishLayout::ConstraintProxy.new(self)
         
     | 
| 
      
 5 
     | 
    
         
            +
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              def constrained_views(*views, &block)
         
     | 
| 
      
 8 
     | 
    
         
            +
                block.call(*(views.map {|e| e.constraint}))
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def common_superview(v)
         
     | 
| 
      
 12 
     | 
    
         
            +
                if v.superview == self
         
     | 
| 
      
 13 
     | 
    
         
            +
                  self
         
     | 
| 
      
 14 
     | 
    
         
            +
                elsif superview == v
         
     | 
| 
      
 15 
     | 
    
         
            +
                  v
         
     | 
| 
      
 16 
     | 
    
         
            +
                else
         
     | 
| 
      
 17 
     | 
    
         
            +
                  (superviews & v.superviews)[0]
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              def superviews
         
     | 
| 
      
 22 
     | 
    
         
            +
                v = self
         
     | 
| 
      
 23 
     | 
    
         
            +
                result = []
         
     | 
| 
      
 24 
     | 
    
         
            +
                loop do
         
     | 
| 
      
 25 
     | 
    
         
            +
                  v = v.superview
         
     | 
| 
      
 26 
     | 
    
         
            +
                  break unless v
         
     | 
| 
      
 27 
     | 
    
         
            +
                  result << v
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
                result
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,16 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class NSArray
         
     | 
| 
      
 2 
     | 
    
         
            +
              def constraints(&block)
         
     | 
| 
      
 3 
     | 
    
         
            +
                mapping = Hash[*self]
         
     | 
| 
      
 4 
     | 
    
         
            +
                view_constraint_proxies = each_slice(2).to_a.transpose[1].map do |e|
         
     | 
| 
      
 5 
     | 
    
         
            +
                  if e.nil?
         
     | 
| 
      
 6 
     | 
    
         
            +
                    c = nil
         
     | 
| 
      
 7 
     | 
    
         
            +
                  else
         
     | 
| 
      
 8 
     | 
    
         
            +
                    e.translatesAutoresizingMaskIntoConstraints = false if e != self[1]
         
     | 
| 
      
 9 
     | 
    
         
            +
                    c = e.constraint
         
     | 
| 
      
 10 
     | 
    
         
            +
                    c.views_mapping = mapping
         
     | 
| 
      
 11 
     | 
    
         
            +
                  end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  c
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
                block.call(*(view_constraint_proxies + [mapping]))
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class NSLayoutConstraint
         
     | 
| 
      
 2 
     | 
    
         
            +
              def inspect
         
     | 
| 
      
 3 
     | 
    
         
            +
                s = super
         
     | 
| 
      
 4 
     | 
    
         
            +
                op = case relation
         
     | 
| 
      
 5 
     | 
    
         
            +
                     when NSLayoutRelationEqual
         
     | 
| 
      
 6 
     | 
    
         
            +
                       '=='
         
     | 
| 
      
 7 
     | 
    
         
            +
                     when NSLayoutRelationLessThanOrEqual
         
     | 
| 
      
 8 
     | 
    
         
            +
                       '<='
         
     | 
| 
      
 9 
     | 
    
         
            +
                     when NSLayoutRelationGreaterThanOrEqual
         
     | 
| 
      
 10 
     | 
    
         
            +
                       '>='
         
     | 
| 
      
 11 
     | 
    
         
            +
                     end
         
     | 
| 
      
 12 
     | 
    
         
            +
                if secondAttribute == NSLayoutAttributeNotAnAttribute
         
     | 
| 
      
 13 
     | 
    
         
            +
                  "#{s} #{firstItem}.#{firstAttribute.to_layout_attribute} #{op} #{constant}"
         
     | 
| 
      
 14 
     | 
    
         
            +
                else
         
     | 
| 
      
 15 
     | 
    
         
            +
                  if constant == 0
         
     | 
| 
      
 16 
     | 
    
         
            +
                    const_s = ''
         
     | 
| 
      
 17 
     | 
    
         
            +
                  else
         
     | 
| 
      
 18 
     | 
    
         
            +
                    const_s = " + #{constant}"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if multiplier == 1
         
     | 
| 
      
 21 
     | 
    
         
            +
                    "#{s} #{firstItem}.#{firstAttribute.to_layout_attribute} #{op} #{secondItem}.#{secondAttribute.to_layout_attribute}#{const_s}"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    "#{s} #{firstItem}.#{firstAttribute.to_layout_attribute} #{op} #{secondItem}.#{secondAttribute.to_layout_attribute} * #{multiplier}#{const_s}"
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class NSNumber
         
     | 
| 
      
 2 
     | 
    
         
            +
              def to_layout_attribute
         
     | 
| 
      
 3 
     | 
    
         
            +
                case self
         
     | 
| 
      
 4 
     | 
    
         
            +
                when NSLayoutAttributeLeft
         
     | 
| 
      
 5 
     | 
    
         
            +
                  'left'
         
     | 
| 
      
 6 
     | 
    
         
            +
                when NSLayoutAttributeRight
         
     | 
| 
      
 7 
     | 
    
         
            +
                  'right'
         
     | 
| 
      
 8 
     | 
    
         
            +
                when NSLayoutAttributeTop
         
     | 
| 
      
 9 
     | 
    
         
            +
                  'top'
         
     | 
| 
      
 10 
     | 
    
         
            +
                when NSLayoutAttributeBottom
         
     | 
| 
      
 11 
     | 
    
         
            +
                  'bottom'
         
     | 
| 
      
 12 
     | 
    
         
            +
                when NSLayoutAttributeLeading
         
     | 
| 
      
 13 
     | 
    
         
            +
                  'leading'
         
     | 
| 
      
 14 
     | 
    
         
            +
                when NSLayoutAttributeTrailing
         
     | 
| 
      
 15 
     | 
    
         
            +
                  'trailing'
         
     | 
| 
      
 16 
     | 
    
         
            +
                when NSLayoutAttributeWidth
         
     | 
| 
      
 17 
     | 
    
         
            +
                  'width'
         
     | 
| 
      
 18 
     | 
    
         
            +
                when NSLayoutAttributeHeight
         
     | 
| 
      
 19 
     | 
    
         
            +
                  'height'
         
     | 
| 
      
 20 
     | 
    
         
            +
                when NSLayoutAttributeCenterX
         
     | 
| 
      
 21 
     | 
    
         
            +
                  'center_x'
         
     | 
| 
      
 22 
     | 
    
         
            +
                when NSLayoutAttributeCenterY
         
     | 
| 
      
 23 
     | 
    
         
            +
                  'center_y'
         
     | 
| 
      
 24 
     | 
    
         
            +
                when NSLayoutAttributeBaseline
         
     | 
| 
      
 25 
     | 
    
         
            +
                  'baseline'
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,135 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module PurplishLayout
         
     | 
| 
      
 2 
     | 
    
         
            +
              class ConstraintProxy
         
     | 
| 
      
 3 
     | 
    
         
            +
                weak_attr_accessor :view
         
     | 
| 
      
 4 
     | 
    
         
            +
                weak_attr_accessor :views_mapping
         
     | 
| 
      
 5 
     | 
    
         
            +
                attr_accessor :attribute, :multiplier, :constant
         
     | 
| 
      
 6 
     | 
    
         
            +
                attr_accessor :last_constraint
         
     | 
| 
      
 7 
     | 
    
         
            +
                attr_accessor :next_priority
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize(view, attribute=nil, multiplier=1, constant=0)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @view = view
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @attribute = attribute
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @multiplier = multiplier
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @constant = constant
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def *(aNumber)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  ConstraintProxy.new(view, attribute, aNumber, constant)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def +(aNumber)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  ConstraintProxy.new(view, attribute, multiplier, aNumber)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def -(aNumber)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  ConstraintProxy.new(view, attribute, multiplier, -aNumber)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def next_priority=(v)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @next_priority = v
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                def create_constraint_with_rhs(rhs)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  if rhs.kind_of? self.class
         
     | 
| 
      
 34 
     | 
    
         
            +
                    owner = rhs.view.common_superview(view)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    c = NSLayoutConstraint.constraintWithItem(view, attribute:attribute.to_layout_attribute, relatedBy:@operator, toItem:rhs.view, attribute:rhs.attribute.to_layout_attribute, multiplier:rhs.multiplier, constant:rhs.constant)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    if next_priority
         
     | 
| 
      
 37 
     | 
    
         
            +
                      c.priority = next_priority
         
     | 
| 
      
 38 
     | 
    
         
            +
                      self.next_priority = nil
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    #puts "addConstraint: #{c.inspect}"
         
     | 
| 
      
 41 
     | 
    
         
            +
                    owner.addConstraint(c)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    c
         
     | 
| 
      
 43 
     | 
    
         
            +
                  else
         
     | 
| 
      
 44 
     | 
    
         
            +
                    c = NSLayoutConstraint.constraintWithItem(view, attribute:attribute.to_layout_attribute, relatedBy:@operator, toItem:nil, attribute:NSLayoutAttributeNotAnAttribute, multiplier:0, constant:rhs)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    if next_priority
         
     | 
| 
      
 46 
     | 
    
         
            +
                      c.priority = next_priority
         
     | 
| 
      
 47 
     | 
    
         
            +
                      self.next_priority = nil
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    #puts "addConstraint: #{c.inspect}"
         
     | 
| 
      
 50 
     | 
    
         
            +
                    view.superview.addConstraint(c)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    c
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def h(s, metrics=nil, options=0, views=nil)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  if (s.start_with? 'H:') || (s.start_with? 'V:')
         
     | 
| 
      
 57 
     | 
    
         
            +
                    layout(s, metrics, options, views)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  else
         
     | 
| 
      
 59 
     | 
    
         
            +
                    layout("H:#{s}", metrics, options, views)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                def v(s, metrics=nil, options=0, views=nil)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  if (s.start_with? 'H:') || (s.start_with? 'V:')
         
     | 
| 
      
 65 
     | 
    
         
            +
                    layout(s, metrics, options, views)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    layout("V:#{s}", metrics, options, views)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                def layout(s, metrics=nil, options=0, views=nil)
         
     | 
| 
      
 72 
     | 
    
         
            +
                  views ||= views_mapping
         
     | 
| 
      
 73 
     | 
    
         
            +
                  #Workaround, must wrap views with NSDictionary, otherwise doesn't work for RubyMotion
         
     | 
| 
      
 74 
     | 
    
         
            +
                  c = NSLayoutConstraint.constraintsWithVisualFormat(s, options:options, metrics:metrics, views:NSDictionary.dictionaryWithDictionary(views))
         
     | 
| 
      
 75 
     | 
    
         
            +
                  self.last_constraint = c
         
     | 
| 
      
 76 
     | 
    
         
            +
                  if next_priority
         
     | 
| 
      
 77 
     | 
    
         
            +
                    c.each {|e|e.priority = next_priority}
         
     | 
| 
      
 78 
     | 
    
         
            +
                    self.next_priority = nil
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
                  #puts "addConstraints:"
         
     | 
| 
      
 81 
     | 
    
         
            +
                  #c.each {|e| puts "  #{e.inspect}"}
         
     | 
| 
      
 82 
     | 
    
         
            +
                  view.addConstraints(c)
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                ##Attributes
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                def attr
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @attribute = __method__
         
     | 
| 
      
 89 
     | 
    
         
            +
                  self
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                def attr=(rhs)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  #Derive reader name from writer
         
     | 
| 
      
 94 
     | 
    
         
            +
                  @attribute = __method__[0..-3].to_sym
         
     | 
| 
      
 95 
     | 
    
         
            +
                  @operator = NSLayoutRelationEqual
         
     | 
| 
      
 96 
     | 
    
         
            +
                  self.last_constraint = create_constraint_with_rhs(rhs)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  self
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                def <=(rhs)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  @operator = NSLayoutRelationLessThanOrEqual
         
     | 
| 
      
 102 
     | 
    
         
            +
                  create_constraint_with_rhs(rhs)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  self
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                def >=(rhs)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  @operator = NSLayoutRelationGreaterThanOrEqual
         
     | 
| 
      
 108 
     | 
    
         
            +
                  create_constraint_with_rhs(rhs)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  self
         
     | 
| 
      
 110 
     | 
    
         
            +
                end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                alias :left :attr
         
     | 
| 
      
 113 
     | 
    
         
            +
                alias :left= :attr=
         
     | 
| 
      
 114 
     | 
    
         
            +
                alias :right :attr
         
     | 
| 
      
 115 
     | 
    
         
            +
                alias :right= :attr=
         
     | 
| 
      
 116 
     | 
    
         
            +
                alias :top :attr
         
     | 
| 
      
 117 
     | 
    
         
            +
                alias :top= :attr=
         
     | 
| 
      
 118 
     | 
    
         
            +
                alias :bottom :attr
         
     | 
| 
      
 119 
     | 
    
         
            +
                alias :bottom= :attr=
         
     | 
| 
      
 120 
     | 
    
         
            +
                alias :leading :attr
         
     | 
| 
      
 121 
     | 
    
         
            +
                alias :leading= :attr=
         
     | 
| 
      
 122 
     | 
    
         
            +
                alias :trailing :attr
         
     | 
| 
      
 123 
     | 
    
         
            +
                alias :trailing= :attr=
         
     | 
| 
      
 124 
     | 
    
         
            +
                alias :width :attr
         
     | 
| 
      
 125 
     | 
    
         
            +
                alias :width= :attr=
         
     | 
| 
      
 126 
     | 
    
         
            +
                alias :height :attr
         
     | 
| 
      
 127 
     | 
    
         
            +
                alias :height= :attr=
         
     | 
| 
      
 128 
     | 
    
         
            +
                alias :center_x :attr
         
     | 
| 
      
 129 
     | 
    
         
            +
                alias :center_x= :attr=
         
     | 
| 
      
 130 
     | 
    
         
            +
                alias :center_y :attr
         
     | 
| 
      
 131 
     | 
    
         
            +
                alias :center_y= :attr=
         
     | 
| 
      
 132 
     | 
    
         
            +
                alias :baseline :attr
         
     | 
| 
      
 133 
     | 
    
         
            +
                alias :baseline= :attr=
         
     | 
| 
      
 134 
     | 
    
         
            +
              end
         
     | 
| 
      
 135 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Symbol
         
     | 
| 
      
 2 
     | 
    
         
            +
              def to_layout_attribute
         
     | 
| 
      
 3 
     | 
    
         
            +
                case self
         
     | 
| 
      
 4 
     | 
    
         
            +
                when :left
         
     | 
| 
      
 5 
     | 
    
         
            +
                  NSLayoutAttributeLeft
         
     | 
| 
      
 6 
     | 
    
         
            +
                when :right
         
     | 
| 
      
 7 
     | 
    
         
            +
                  NSLayoutAttributeRight
         
     | 
| 
      
 8 
     | 
    
         
            +
                when :top
         
     | 
| 
      
 9 
     | 
    
         
            +
                  NSLayoutAttributeTop
         
     | 
| 
      
 10 
     | 
    
         
            +
                when :bottom
         
     | 
| 
      
 11 
     | 
    
         
            +
                  NSLayoutAttributeBottom
         
     | 
| 
      
 12 
     | 
    
         
            +
                when :leading
         
     | 
| 
      
 13 
     | 
    
         
            +
                  NSLayoutAttributeLeading
         
     | 
| 
      
 14 
     | 
    
         
            +
                when :trailing
         
     | 
| 
      
 15 
     | 
    
         
            +
                  NSLayoutAttributeTrailing
         
     | 
| 
      
 16 
     | 
    
         
            +
                when :width
         
     | 
| 
      
 17 
     | 
    
         
            +
                  NSLayoutAttributeWidth
         
     | 
| 
      
 18 
     | 
    
         
            +
                when :height
         
     | 
| 
      
 19 
     | 
    
         
            +
                  NSLayoutAttributeHeight
         
     | 
| 
      
 20 
     | 
    
         
            +
                when :center_x
         
     | 
| 
      
 21 
     | 
    
         
            +
                  NSLayoutAttributeCenterX
         
     | 
| 
      
 22 
     | 
    
         
            +
                when :center_y
         
     | 
| 
      
 23 
     | 
    
         
            +
                  NSLayoutAttributeCenterY
         
     | 
| 
      
 24 
     | 
    
         
            +
                when :baseline
         
     | 
| 
      
 25 
     | 
    
         
            +
                  NSLayoutAttributeBaseline
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- encoding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require File.expand_path('../lib/purplish-layout/version.rb', __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            Gem::Specification.new do |gem|
         
     | 
| 
      
 5 
     | 
    
         
            +
              gem.name          = 'purplish-layout'
         
     | 
| 
      
 6 
     | 
    
         
            +
              gem.version       = PurplishLayout::VERSION
         
     | 
| 
      
 7 
     | 
    
         
            +
              gem.licenses      = ['BSD']
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              gem.authors  = ['Hwee-Boon Yar']
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              gem.description = 'A RubyMotion wrapper for Auto Layout on iOS and OS X'
         
     | 
| 
      
 12 
     | 
    
         
            +
              gem.summary = 'A RubyMotion wrapper for Auto Layout on iOS and OS X'
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem.homepage = 'http://hboon.com/purplish-layout/'
         
     | 
| 
      
 14 
     | 
    
         
            +
              gem.email = 'hboon@motionobj.com'
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              gem.add_dependency "weak_attr_accessor", "~> 0.0.2"
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.files       = `git ls-files`.split($\)
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem.require_paths = ['lib']
         
     | 
| 
      
 19 
     | 
    
         
            +
              #gem.test_files  = gem.files.grep(%r{^spec/})
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,70 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: purplish-layout
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Hwee-Boon Yar
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-02-01 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: weak_attr_accessor
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 0.0.2
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 0.0.2
         
     | 
| 
      
 27 
     | 
    
         
            +
            description: A RubyMotion wrapper for Auto Layout on iOS and OS X
         
     | 
| 
      
 28 
     | 
    
         
            +
            email: hboon@motionobj.com
         
     | 
| 
      
 29 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 30 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 31 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            files:
         
     | 
| 
      
 33 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 34 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 35 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/purplish-layout.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/purplish-layout/can_be_constrained.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/purplish-layout/ns_array.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/purplish-layout/ns_layout_constraint.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/purplish-layout/ns_number.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/purplish-layout/purplish-layout.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/purplish-layout/symbol.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/purplish-layout/version.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/purplish-layout/view.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            - purplish-layout.gemspec
         
     | 
| 
      
 46 
     | 
    
         
            +
            homepage: http://hboon.com/purplish-layout/
         
     | 
| 
      
 47 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 48 
     | 
    
         
            +
            - BSD
         
     | 
| 
      
 49 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 50 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 51 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 52 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 53 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 54 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 55 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 56 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 57 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 58 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 59 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 60 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 61 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 62 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 63 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 64 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 65 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 66 
     | 
    
         
            +
            rubygems_version: 2.4.2
         
     | 
| 
      
 67 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 68 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 69 
     | 
    
         
            +
            summary: A RubyMotion wrapper for Auto Layout on iOS and OS X
         
     | 
| 
      
 70 
     | 
    
         
            +
            test_files: []
         
     |