Module: CanBeConstrained

Included in:
NSView, UIView
Defined in:
lib/purplish-layout/can_be_constrained.rb

Instance Method Summary collapse

Instance Method Details

#common_superview(v) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/purplish-layout/can_be_constrained.rb', line 11

def common_superview(v)
  if v.superview == self
    self
  elsif superview == v
    v
  else
    (superviews & v.superviews)[0]
  end
end

#constrained_views(*views, &block) ⇒ Object



7
8
9
# File 'lib/purplish-layout/can_be_constrained.rb', line 7

def constrained_views(*views, &block)
  block.call(*(views.map {|e| e.constraint}))
end

#constraintObject



2
3
4
5
# File 'lib/purplish-layout/can_be_constrained.rb', line 2

def constraint
  #Don't bother storing it, and most importantly, don't reuse it because things like multipler and constant must always be reset
  PurplishLayout::ConstraintProxy.new(self)
end

#superviewsObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/purplish-layout/can_be_constrained.rb', line 21

def superviews
  v = self
  result = []
  loop do
    v = v.superview
    break unless v
    result << v
  end
  result
end