Module: MotionPrime::SupportControlContentAlignment

Included in:
MPButton, MPTextField
Defined in:
motion-prime/support/_control_content_alignment.rb

Constant Summary collapse

VERTICAL_ALIGNMENT_CONSTS =
{
  UIControlContentVerticalAlignmentCenter => :center,
  UIControlContentVerticalAlignmentTop => :top,
  UIControlContentVerticalAlignmentBottom => :bottom,
  UIControlContentVerticalAlignmentFill => :fill # TODO: handle this value
}

Instance Method Summary collapse

Instance Method Details

#bounds_heightObject



35
36
37
# File 'motion-prime/support/_control_content_alignment.rb', line 35

def bounds_height
  self.bounds.size.height
end

#line_heightObject



31
32
33
# File 'motion-prime/support/_control_content_alignment.rb', line 31

def line_height
  @_line_height || self.font.pointSize
end

#padding_bottomObject



27
28
29
# File 'motion-prime/support/_control_content_alignment.rb', line 27

def padding_bottom
  (bounds_height - (line_height + padding_top))
end

#padding_topObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'motion-prime/support/_control_content_alignment.rb', line 14

def padding_top
  padding_top = self.paddingTop || self.padding
  if @_content_vertical_alignment == :bottom
    padding_bottom = self.paddingBottom || self.padding
    bounds_height - padding_bottom.to_i - line_height
  elsif @_content_vertical_alignment == :top
    padding_top.to_i
  else # center label
    padding_top_offset = padding_top.to_i - (self.paddingBottom || self.padding).to_i
    (bounds_height - line_height)/2 + padding_top_offset
  end
end

#setContentVerticalAlignment(value) ⇒ Object

TODO: handle this value



9
10
11
12
# File 'motion-prime/support/_control_content_alignment.rb', line 9

def setContentVerticalAlignment(value)
  return unless @_content_vertical_alignment = VERTICAL_ALIGNMENT_CONSTS[value]
  super
end