class MotionKit::ConstraintsHelpers

Public Instance Methods

above(view) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 228
def above(view)
  unless view
    raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `above` constraint.")
  end
  constraint = Constraint.new(constraint_target.view, :bottom, :equal)
  constraint.equals(view, :top)

  constraint_target.add_constraints([constraint])
  return constraint
end
after(view) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 262
def after(view)
  unless view
    raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `after` constraint.")
  end
  constraint = Constraint.new(constraint_target.view, :left, :equal)
  constraint.equals(view, :right)

  constraint_target.add_constraints([constraint])
  return constraint
end
Also aliased as: right_of
baseline(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 115
def baseline(value=nil, rel=nil)
  target_constraint(:baseline, rel, value)
end
before(view) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 250
def before(view)
  unless view
    raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `before` constraint.")
  end
  constraint = Constraint.new(constraint_target.view, :right, :equal)
  constraint.equals(view, :left)

  constraint_target.add_constraints([constraint])
  return constraint
end
Also aliased as: left_of
below(view) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 239
def below(view)
  unless view
    raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `below` constraint.")
  end
  constraint = Constraint.new(constraint_target.view, :top, :equal)
  constraint.equals(view, :bottom)

  constraint_target.add_constraints([constraint])
  return constraint
end
bottom(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 103
def bottom(value=nil, rel=nil)
  target_constraint(:bottom, rel, value)
end
bottom_left(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 204
def bottom_left(value=nil, rel=nil)
  target_constraint([:left, :bottom], rel, value, PointConstraint)
end
bottom_right(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 216
def bottom_right(value=nil, rel=nil)
  target_constraint([:right, :bottom], rel, value, PointConstraint)
end
center(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 165
def center(value=nil, rel=nil)
  target_constraint([:center_x, :center_y], rel, value, PointConstraint)
end
center_x(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 40
def center_x(value=nil, rel=nil)
  target_constraint(:center_x, rel, value)
end
center_y(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 91
def center_y(value=nil, rel=nil)
  target_constraint(:center_y, rel, value)
end
constraint_target() click to toggle source

A more sensible name for the constraint that is created.

# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 9
def constraint_target
  target
end
h(value=nil, rel=nil)
Alias for: height
height(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 140
def height(value=nil, rel=nil)
  target_constraint(:height, :equal, value)
end
Also aliased as: h
leading(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 28
def leading(value=nil, rel=nil)
  target_constraint(:leading, rel, value)
end
left(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 13
def left(value=nil, rel=nil)
  target_constraint(:left, rel, value)
end
Also aliased as: x
left_of(view)
Alias for: before
max_baseline(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 123
def max_baseline(value=nil)
  baseline(value, :lte)
end
max_bottom(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 111
def max_bottom(value=nil)
  bottom(value, :lte)
end
max_bottom_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 212
def max_bottom_left(value=nil)
  bottom_left(value, :lte)
end
max_bottom_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 224
def max_bottom_right(value=nil)
  bottom_right(value, :lte)
end
max_center(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 173
def max_center(value=nil)
  center(value, :lte)
end
max_center_x(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 48
def max_center_x(value=nil)
  center_x(value, :lte)
end
max_center_y(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 99
def max_center_y(value=nil)
  center_y(value, :lte)
end
max_height(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 149
def max_height(value=nil)
  target_constraint(:height, :lte, value)
end
max_leading(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 36
def max_leading(value=nil)
  leading(value, :lte)
end
max_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 23
def max_left(value=nil)
  left(value, :lte)
end
Also aliased as: max_x
max_origin(value=nil)
Alias for: max_top_left
max_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 60
def max_right(value=nil)
  right(value, :lte)
end
max_size(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 161
def max_size(value=nil)
  size(value, :lte)
end
max_top(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 86
def max_top(value=nil)
  top(value, :lte)
end
Also aliased as: max_y
max_top_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 187
def max_top_left(value=nil)
  top_left(value, :lte)
end
Also aliased as: max_origin
max_top_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 200
def max_top_right(value=nil)
  top_right(value, :lte)
end
max_trailing(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 72
def max_trailing(value=nil)
  trailing(value, :lte)
end
max_width(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 136
def max_width(value=nil)
  width(value, :lte)
end
max_x(value=nil)
Alias for: max_left
max_y(value=nil)
Alias for: max_top
min_baseline(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 119
def min_baseline(value=nil)
  baseline(value, :gte)
end
min_bottom(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 107
def min_bottom(value=nil)
  bottom(value, :gte)
end
min_bottom_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 208
def min_bottom_left(value=nil)
  bottom_left(value, :gte)
end
min_bottom_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 220
def min_bottom_right(value=nil)
  bottom_right(value, :gte)
end
min_center(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 169
def min_center(value=nil)
  center(value, :gte)
end
min_center_x(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 44
def min_center_x(value=nil)
  center_x(value, :gte)
end
min_center_y(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 95
def min_center_y(value=nil)
  center_y(value, :gte)
end
min_height(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 145
def min_height(value=nil)
  target_constraint(:height, :gte, value)
end
min_leading(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 32
def min_leading(value=nil)
  leading(value, :gte)
end
min_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 18
def min_left(value=nil)
  left(value, :gte)
end
Also aliased as: min_x
min_origin(value=nil)
Alias for: min_top_left
min_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 56
def min_right(value=nil)
  right(value, :gte)
end
min_size(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 157
def min_size(value=nil)
  size(value, :gte)
end
min_top(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 81
def min_top(value=nil)
  top(value, :gte)
end
Also aliased as: min_y
min_top_left(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 182
def min_top_left(value=nil)
  top_left(value, :gte)
end
Also aliased as: min_origin
min_top_right(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 196
def min_top_right(value=nil)
  top_right(value, :gte)
end
min_trailing(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 68
def min_trailing(value=nil)
  trailing(value, :gte)
end
min_width(value=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 132
def min_width(value=nil)
  width(value, :gte)
end
min_x(value=nil)
Alias for: min_left
min_y(value=nil)
Alias for: min_top
origin(value=nil, rel=nil)
Alias for: top_left
right(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 52
def right(value=nil, rel=nil)
  target_constraint(:right, rel, value)
end
right_of(view)
Alias for: after
size(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 153
def size(value=nil, rel=nil)
  target_constraint(:size, rel, value, SizeConstraint)
end
top(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 76
def top(value=nil, rel=nil)
  target_constraint(:top, rel, value)
end
Also aliased as: y
top_left(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 177
def top_left(value=nil, rel=nil)
  target_constraint([:left, :top], rel, value, PointConstraint)
end
Also aliased as: origin
top_right(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 192
def top_right(value=nil, rel=nil)
  target_constraint([:right, :top], rel, value, PointConstraint)
end
trailing(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 64
def trailing(value=nil, rel=nil)
  target_constraint(:trailing, rel, value)
end
w(value=nil, rel=nil)
Alias for: width
width(value=nil, rel=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 127
def width(value=nil, rel=nil)
  target_constraint(:width, rel, value)
end
Also aliased as: w
x(value=nil, rel=nil)
Alias for: left
y(value=nil, rel=nil)
Alias for: top

Private Instance Methods

target_constraint(attribute, relationship, value=nil, constraint_class=nil) click to toggle source
# File lib/motion-kit-cocoa/constraints/constraints_helpers.rb, line 276
def target_constraint(attribute, relationship, value=nil, constraint_class=nil)
  constraint_class ||= Constraint
  constraint = constraint_class.new(constraint_target.view, attribute, relationship)
  if value == :scale
    size = ViewCalculator.intrinsic_size(constraint_target.view)
    if attribute == :width
      constraint.equals(:self, :height).times(size.width / size.height)
    elsif attribute == :height
      constraint.equals(:self, :width).times(size.height / size.width)
    else
      raise "Cannot apply :scale relationship to #{attribute}"
    end
  elsif value
    constraint.equals(value)
  end
  constraint_target.add_constraints([constraint])
  constraint
end