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_frame_for

Methods inherited from BaseElement

#add_target, after_render, before_render, #cell_element?, #cell_section?, #compute_options!, #computed_options, #dealloc, #initialize, #reload!, #render, #update, #update_options, #update_with_options

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory

Methods included from HasStyleChainBuilder

#build_styles_chain

Methods included from HasNormalizer

#debug_info, #element?, #normalize_object, #normalize_options, #normalize_value

Constructor Details

This class inherits a constructor from MotionPrime::BaseElement

Class Method Details

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



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

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, target = nil) ⇒ Object



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

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

#computed_frameObject



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

def computed_frame
  @computed_frame ||= calculate_frame_for(view.try(:bounds) || section.container_bounds, computed_options)
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(frame_left, frame_top, frame_outer_width, frame_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



42
43
44
45
46
# File 'motion-prime/elements/draw.rb', line 42

def hide
  return if computed_options[:hidden]
  computed_options[:hidden] = true
  rerender!
end

#render!Object



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

def render!; end

#rerender!Object



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

def rerender!
  section.cached_draw_image = nil
  view.try(:setNeedsDisplay)
end

#showObject



48
49
50
51
52
# File 'motion-prime/elements/draw.rb', line 48

def show
  return if !computed_options[:hidden]
  computed_options[:hidden] = false
  rerender!
end

#viewObject



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

def view
  @view ||= section.container_view
end