Class: MotionPrime::DrawElement

Inherits:
BaseElement show all
Includes:
ElementContentPaddingMixin, FrameCalculatorMixin
Defined in:
motion-prime/elements/draw.rb

Instance Attribute Summary

Attributes inherited from BaseElement

#name, #options, #screen, #section, #styles, #view_class, #view_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementContentPaddingMixin

#cached_content_outer_height, #cached_content_outer_width, #content_outer_height, #content_outer_width, #content_padding_bottom, #content_padding_height, #content_padding_left, #content_padding_right, #content_padding_top, #content_padding_width

Methods included from FrameCalculatorMixin

#calculate_frome_for

Methods inherited from BaseElement

#add_target, after_render, before_render, #compute_options!, #computed_options, #initialize, #render

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory

Methods included from HasStyleChainBuilder

#build_styles_chain

Methods included from HasNormalizer

#normalize_object, #normalize_options

Constructor Details

This class inherits a constructor from MotionPrime::BaseElement

Class Method Details

.factory(type, options = {}) ⇒ Object



96
97
98
99
# File 'motion-prime/elements/draw.rb', line 96

def factory(type, options = {})
  return unless %w[view label image].include?(type.to_s.downcase)
  class_factory("#{type}_draw_element", true).new(options)
end

Instance Method Details

#bind_gesture(action, receiver = nil) ⇒ Object



63
64
65
# File 'motion-prime/elements/draw.rb', line 63

def bind_gesture(action, receiver = nil)
  section.bind_gesture_on_container_for(self, action, receiver)
end

#computed_bottomObject



57
# File 'motion-prime/elements/draw.rb', line 57

def computed_bottom; computed_top + computed_outer_height end

#computed_frameObject



29
30
31
# File 'motion-prime/elements/draw.rb', line 29

def computed_frame
  @computed_frame ||= calculate_frome_for(view.try(:bounds) || section.container_bounds, computed_options)
end

#computed_heightObject



49
# File 'motion-prime/elements/draw.rb', line 49

def computed_height; computed_outer_height - content_padding_height end

#computed_inner_bottomObject



58
# File 'motion-prime/elements/draw.rb', line 58

def computed_inner_bottom; computed_bottom - content_padding_bottom end

#computed_inner_leftObject



55
# File 'motion-prime/elements/draw.rb', line 55

def computed_inner_left; computed_left + content_padding_left end

#computed_inner_rightObject



61
# File 'motion-prime/elements/draw.rb', line 61

def computed_inner_right; computed_right - content_padding_right end

#computed_inner_topObject



52
# File 'motion-prime/elements/draw.rb', line 52

def computed_inner_top; computed_top + content_padding_top end

#computed_leftObject



54
# File 'motion-prime/elements/draw.rb', line 54

def computed_left; computed_frame.origin.x end

#computed_max_heightObject



41
42
43
# File 'motion-prime/elements/draw.rb', line 41

def computed_max_height
  view.bounds.size.height
end

#computed_max_widthObject



37
38
39
# File 'motion-prime/elements/draw.rb', line 37

def computed_max_width
  view.bounds.size.width
end

#computed_outer_heightObject



48
# File 'motion-prime/elements/draw.rb', line 48

def computed_outer_height; computed_frame.size.height end

#computed_outer_widthObject



45
# File 'motion-prime/elements/draw.rb', line 45

def computed_outer_width; computed_frame.size.width end

#computed_rightObject



60
# File 'motion-prime/elements/draw.rb', line 60

def computed_right; computed_left + computed_width end

#computed_topObject



51
# File 'motion-prime/elements/draw.rb', line 51

def computed_top; computed_frame.origin.y end

#computed_widthObject



46
# File 'motion-prime/elements/draw.rb', line 46

def computed_width; computed_outer_width - content_padding_width end

#default_padding_for(side) ⇒ Object



33
34
35
# File 'motion-prime/elements/draw.rb', line 33

def default_padding_for(side)
  0
end

#draw_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'motion-prime/elements/draw.rb', line 10

def draw_options
  options = computed_options
  background_color = options[:background_color].try(:uicolor)
  {
    rect: CGRectMake(computed_left, computed_top, computed_outer_width, computed_outer_height),
    background_color: background_color,
    masks_to_bounds: options[:layer].try(:[], :masks_to_bounds) || options[:clips_to_bounds],
    corner_radius: options[:layer].try(:[], :corner_radius).to_f,
    border_width: options[:layer].try(:[], :border_width).to_f,
    border_color: options[:layer].try(:[], :border_color).try(:uicolor) || background_color
  }
end

#hideObject



67
68
69
70
71
72
# File 'motion-prime/elements/draw.rb', line 67

def hide
  return if computed_options[:hidden]
  computed_options[:hidden] = true
  section.cached_draw_image = nil
  view.setNeedsDisplay
end

#render!Object



23
# File 'motion-prime/elements/draw.rb', line 23

def render!; end

#showObject



74
75
76
77
78
79
# File 'motion-prime/elements/draw.rb', line 74

def show
  return if !computed_options[:hidden]
  computed_options[:hidden] = false
  section.cached_draw_image = nil
  view.setNeedsDisplay
end

#update_with_options(new_options = {}) ⇒ Object



81
82
83
84
85
86
# File 'motion-prime/elements/draw.rb', line 81

def update_with_options(new_options = {})
  options.merge!(new_options)
  compute_options!
  section.cached_draw_image = nil
  view.setNeedsDisplay
end

#viewObject



25
26
27
# File 'motion-prime/elements/draw.rb', line 25

def view
  @view ||= section.container_view
end