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



106
107
108
109
# File 'motion-prime/elements/draw.rb', line 106

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



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

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

#computed_frameObject



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

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

#default_padding_for(side) ⇒ Object



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

def default_padding_for(side)
  0
end

#draw_in(rect) ⇒ Object



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

def draw_in(rect)
  if @_prev_rect_size && @_prev_rect_size != rect.size
    reset_computed_values
  end
  @_prev_rect_size = rect.size
end

#draw_optionsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'motion-prime/elements/draw.rb', line 10

def draw_options
  options = computed_options
  background_color = options[:background_color].try(:uicolor)
  layer_options = options[:layer] || {}
  corner_radius = layer_options[:corner_radius].to_f

  layer_options.delete(:masks_to_bounds) if layer_options[:masks_to_bounds].nil?
  options.delete(:clips_to_bounds) if options[:clips_to_bounds].nil?
  masks_to_bounds = layer_options.fetch(:masks_to_bounds, options.fetch(:clips_to_bounds, corner_radius > 0))
  {
    rect: CGRectMake(frame_left, frame_top, frame_outer_width, frame_outer_height),
    background_color: background_color,
    masks_to_bounds: masks_to_bounds,
    corner_radius: corner_radius,
    rounded_corners: layer_options[:rounded_corners],
    border_width: layer_options[:border_width].to_f,
    border_color: layer_options[:border_color].try(:uicolor) || background_color,
    border_sides: layer_options[:border_sides],
    dashes: layer_options[:dashes]
  }
end

#hideObject



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

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

#on_container_renderObject



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

def on_container_render
  @view = nil
  @computed_frame = nil
end

#render!Object



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

def render!; end

#rerender!(changed_options = []) ⇒ Object



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

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

#showObject



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

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

#viewObject



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

def view
  @view ||= section.container_view
end