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, #notify_section_after_render, #notify_section_before_render, #reload!, #render, #update, #update_options, #update_with_options

Methods included from HasClassFactory

#camelize_factory, #class_factory, #low_camelize_factory, #underscore_factory

Methods included from HasStyleOptions

#extract_font_from

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



91
92
93
94
# File 'motion-prime/elements/draw.rb', line 91

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



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

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

#computed_frameObject



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

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

#default_padding_for(side) ⇒ Object



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

def default_padding_for(side)
  0
end

#draw_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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,
    border_sides: options[:layer].try(:[], :border_sides),
    dashes: options[:layer].try(:[], :dashes),
  }
end

#hideObject



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

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

#on_container_renderObject



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

def on_container_render
  @view = nil
  @computed_frame = nil
end

#render!Object



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

def render!; end

#rerender!(changed_options = []) ⇒ Object



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

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

#showObject



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

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

#viewObject



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

def view
  @view ||= section.container_view
end