Class: NSLayoutConstraint

Inherits:
Object show all
Defined in:
lib/sugarcube/to_s/nslayoutconstraint.rb

Constant Summary collapse

Relationships =
{
  equal: NSLayoutRelationEqual,
  lte: NSLayoutRelationLessThanOrEqual,
  gte: NSLayoutRelationGreaterThanOrEqual,
}
Attributes =
{
  left: NSLayoutAttributeLeft,
  right: NSLayoutAttributeRight,
  top: NSLayoutAttributeTop,
  bottom: NSLayoutAttributeBottom,
  leading: NSLayoutAttributeLeading,
  trailing: NSLayoutAttributeTrailing,
  width: NSLayoutAttributeWidth,
  height: NSLayoutAttributeHeight,
  center_x: NSLayoutAttributeCenterX,
  center_y: NSLayoutAttributeCenterY,
  baseline: NSLayoutAttributeBaseline,
}

Instance Method Summary collapse

Instance Method Details

#to_sObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sugarcube/to_s/nslayoutconstraint.rb', line 22

def to_s
  target = firstItem
  relative_to = secondItem

  if firstItem and secondItem
    if secondItem == firstItem
      relative_to = :self
    elsif firstItem.superview and secondItem == firstItem.superview
      relative_to = :superview
    elsif secondItem.respond_to?(:stylename) and secondItem.stylename
      relative_to = secondItem.stylename
    end

    if secondItem.superview and firstItem == secondItem.superview
      target = :superview
    elsif firstItem.respond_to?(:stylename) and firstItem.stylename
      target = firstItem.stylename
    end
  elsif firstItem
    if firstItem.respond_to?(:stylename) and firstItem.stylename
      target = firstItem.stylename
    end
  elsif secondItem
    if secondItem.respond_to?(:stylename) and secondItem.stylename
      target = secondItem.stylename
    end
  end

  op = case _to_s_relationship_reverse relation
       when :equal
         '=='
       when :gte
         '>='
       when :lte
         '<='
       end
  formula = 'first.'
  formula << _to_s_attribute_reverse(firstAttribute).to_s
  formula << ' ' << op << ' '
  if multiplier != 1
    formula << multiplier.to_s << ' × '
  end
  if secondItem
    if firstItem == secondItem
      formula << 'first.'
    else
      formula << 'second.'
    end
    formula << _to_s_attribute_reverse(secondAttribute).to_s
  end
  if constant != 0
    if secondItem
      formula << ' + '
    end
    formula << constant.to_s
  end

  return "#<#{self.class}:##{object_id.to_s(16)}" +
         " firstItem=#{target.inspect}" +
         " secondItem=#{relative_to.inspect}" +
         " priority=#{priority.inspect}" +
         " formula=#{formula.inspect}" +
         ">"
end