Class: MotionKit::Parent

Inherits:
Object show all
Defined in:
lib/motion-kit/layouts/parent.rb

Overview

Simple class that returns data about the parent element for use while setting the styles of a child element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Parent

Returns a new instance of Parent.



9
10
11
# File 'lib/motion-kit/layouts/parent.rb', line 9

def initialize(element)
  @element = element
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



7
8
9
# File 'lib/motion-kit/layouts/parent.rb', line 7

def element
  @element
end

Instance Method Details

#centerObject



45
46
47
# File 'lib/motion-kit/layouts/parent.rb', line 45

def center
  CGPointMake(center_x, center_y) if width && height
end

#center_xObject



37
38
39
# File 'lib/motion-kit/layouts/parent.rb', line 37

def center_x
  width / 2.0 if width
end

#center_yObject



41
42
43
# File 'lib/motion-kit/layouts/parent.rb', line 41

def center_y
  height / 2.0 if height
end

#heightObject



33
34
35
# File 'lib/motion-kit/layouts/parent.rb', line 33

def height
  try(:frame, :size, :height)
end

#originObject



13
14
15
# File 'lib/motion-kit/layouts/parent.rb', line 13

def origin
  try(:frame, :origin)
end

#sizeObject



17
18
19
# File 'lib/motion-kit/layouts/parent.rb', line 17

def size
  try(:frame, :size)
end

#widthObject



29
30
31
# File 'lib/motion-kit/layouts/parent.rb', line 29

def width
  try(:frame, :size, :width)
end

#xObject



21
22
23
# File 'lib/motion-kit/layouts/parent.rb', line 21

def x
  try(:frame, :origin, :x)
end

#yObject



25
26
27
# File 'lib/motion-kit/layouts/parent.rb', line 25

def y
  try(:frame, :origin, :y)
end