Sha256: edabc1046062aec42e7dbfcb643e10c6580a2190d59005a38205df7b203ffcb4

Contents?: true

Size: 1.5 KB

Versions: 23

Compression:

Stored size: 1.5 KB

Contents

module MotionPrime
  module SectionWithContainerMixin
    extend ::MotionSupport::Concern

    included do
      class_attribute :container_element_options
    end

    def container_view
      container_element.try(:view)
    end

    def init_container_element(options = {})
      @container_element ||= begin
        options.merge!({
          screen: screen,
          section: self.weak_ref,
          has_drawn_content: true
        })
        container_element_options = self.class.container_element_options.clone
        type = container_element_options.delete(:type)
        options.merge!(container_element_options)
        MotionPrime::BaseElement.factory(type, options)
      end
    end

    def load_container_with_elements(options = {})
      init_container_element(options[:container] || {})
      @container_element.compute_options! unless @container_element.computed_options
      compute_element_options(options[:elements] || {})

      if respond_to?(:prerender_elements_for_state) && prerender_enabled?
        prerender_elements_for_state(:normal)
      end
    end

    private
      def compute_element_options(options = {})
        self.elements.values.each do |element|
          element.size_to_fit_if_needed if element.is_a?(LabelDrawElement)
          element.compute_options! if element.respond_to?(:computed_options) && !element.computed_options
        end
      end


    module ClassMethods
      def container_element(options)
        self.container_element_options = options
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
motion-prime-0.8.2 motion-prime/sections/__section_with_container_mixin.rb
motion-prime-0.8.1 motion-prime/sections/__section_with_container_mixin.rb
motion-prime-0.8.0 motion-prime/sections/__section_with_container_mixin.rb