Class: PurplishLayout::ConstraintProxy
- Inherits:
-
Object
- Object
- PurplishLayout::ConstraintProxy
- Defined in:
- lib/purplish-layout/purplish-layout.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#constant ⇒ Object
Returns the value of attribute constant.
-
#last_constraint ⇒ Object
Returns the value of attribute last_constraint.
-
#multiplier ⇒ Object
Returns the value of attribute multiplier.
-
#next_priority ⇒ Object
Returns the value of attribute next_priority.
Instance Method Summary collapse
- #*(aNumber) ⇒ Object
- #+(aNumber) ⇒ Object
- #-(aNumber) ⇒ Object
- #<=(rhs) ⇒ Object
- #>=(rhs) ⇒ Object
-
#attr ⇒ Object
(also: #left, #right, #top, #bottom, #leading, #trailing, #width, #height, #center_x, #center_y, #baseline)
Attributes.
- #attr=(rhs) ⇒ Object (also: #left=, #right=, #top=, #bottom=, #leading=, #trailing=, #width=, #height=, #center_x=, #center_y=, #baseline=)
- #create_constraint_with_rhs(rhs) ⇒ Object
- #h(s, metrics = nil, options = 0, views = nil) ⇒ Object
-
#initialize(view, attribute = nil, multiplier = 1, constant = 0) ⇒ ConstraintProxy
constructor
A new instance of ConstraintProxy.
- #layout(s, metrics = nil, options = 0, views = nil) ⇒ Object
- #v(s, metrics = nil, options = 0, views = nil) ⇒ Object
Constructor Details
#initialize(view, attribute = nil, multiplier = 1, constant = 0) ⇒ ConstraintProxy
Returns a new instance of ConstraintProxy.
9 10 11 12 13 14 |
# File 'lib/purplish-layout/purplish-layout.rb', line 9 def initialize(view, attribute=nil, multiplier=1, constant=0) @view = view @attribute = attribute @multiplier = multiplier @constant = constant end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/purplish-layout/purplish-layout.rb', line 5 def attribute @attribute end |
#constant ⇒ Object
Returns the value of attribute constant.
5 6 7 |
# File 'lib/purplish-layout/purplish-layout.rb', line 5 def constant @constant end |
#last_constraint ⇒ Object
Returns the value of attribute last_constraint.
6 7 8 |
# File 'lib/purplish-layout/purplish-layout.rb', line 6 def last_constraint @last_constraint end |
#multiplier ⇒ Object
Returns the value of attribute multiplier.
5 6 7 |
# File 'lib/purplish-layout/purplish-layout.rb', line 5 def multiplier @multiplier end |
#next_priority ⇒ Object
Returns the value of attribute next_priority.
7 8 9 |
# File 'lib/purplish-layout/purplish-layout.rb', line 7 def next_priority @next_priority end |
Instance Method Details
#*(aNumber) ⇒ Object
16 17 18 |
# File 'lib/purplish-layout/purplish-layout.rb', line 16 def *(aNumber) ConstraintProxy.new(view, attribute, aNumber, constant) end |
#+(aNumber) ⇒ Object
20 21 22 |
# File 'lib/purplish-layout/purplish-layout.rb', line 20 def +(aNumber) ConstraintProxy.new(view, attribute, multiplier, aNumber) end |
#-(aNumber) ⇒ Object
24 25 26 |
# File 'lib/purplish-layout/purplish-layout.rb', line 24 def -(aNumber) ConstraintProxy.new(view, attribute, multiplier, -aNumber) end |
#<=(rhs) ⇒ Object
100 101 102 103 104 |
# File 'lib/purplish-layout/purplish-layout.rb', line 100 def <=(rhs) @operator = NSLayoutRelationLessThanOrEqual create_constraint_with_rhs(rhs) self end |
#>=(rhs) ⇒ Object
106 107 108 109 110 |
# File 'lib/purplish-layout/purplish-layout.rb', line 106 def >=(rhs) @operator = NSLayoutRelationGreaterThanOrEqual create_constraint_with_rhs(rhs) self end |
#attr ⇒ Object Also known as: left, right, top, bottom, leading, trailing, width, height, center_x, center_y, baseline
Attributes
87 88 89 90 |
# File 'lib/purplish-layout/purplish-layout.rb', line 87 def attr @attribute = __method__ self end |
#attr=(rhs) ⇒ Object Also known as: left=, right=, top=, bottom=, leading=, trailing=, width=, height=, center_x=, center_y=, baseline=
92 93 94 95 96 97 98 |
# File 'lib/purplish-layout/purplish-layout.rb', line 92 def attr=(rhs) #Derive reader name from writer @attribute = __method__[0..-3].to_sym @operator = NSLayoutRelationEqual self.last_constraint = create_constraint_with_rhs(rhs) self end |
#create_constraint_with_rhs(rhs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/purplish-layout/purplish-layout.rb', line 32 def create_constraint_with_rhs(rhs) if rhs.kind_of? self.class owner = rhs.view.common_superview(view) 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) if next_priority c.priority = next_priority self.next_priority = nil end #puts "addConstraint: #{c.inspect}" owner.addConstraint(c) c else c = NSLayoutConstraint.constraintWithItem(view, attribute:attribute.to_layout_attribute, relatedBy:@operator, toItem:nil, attribute:NSLayoutAttributeNotAnAttribute, multiplier:0, constant:rhs) if next_priority c.priority = next_priority self.next_priority = nil end #puts "addConstraint: #{c.inspect}" view.superview.addConstraint(c) c end end |
#h(s, metrics = nil, options = 0, views = nil) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/purplish-layout/purplish-layout.rb', line 55 def h(s, metrics=nil, =0, views=nil) if (s.start_with? 'H:') || (s.start_with? 'V:') layout(s, metrics, , views) else layout("H:#{s}", metrics, , views) end end |
#layout(s, metrics = nil, options = 0, views = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/purplish-layout/purplish-layout.rb', line 71 def layout(s, metrics=nil, =0, views=nil) views ||= views_mapping #Workaround, must wrap views with NSDictionary, otherwise doesn't work for RubyMotion c = NSLayoutConstraint.constraintsWithVisualFormat(s, options:, metrics:metrics, views:NSDictionary.dictionaryWithDictionary(views)) self.last_constraint = c if next_priority c.each {|e|e.priority = next_priority} self.next_priority = nil end #puts "addConstraints:" #c.each {|e| puts " #{e.inspect}"} view.addConstraints(c) end |
#v(s, metrics = nil, options = 0, views = nil) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/purplish-layout/purplish-layout.rb', line 63 def v(s, metrics=nil, =0, views=nil) if (s.start_with? 'H:') || (s.start_with? 'V:') layout(s, metrics, , views) else layout("V:#{s}", metrics, , views) end end |