Sha256: 0bf40183a2eae808b6d18698b7e63574b20e5215b6ff2e55c430e7bc7bf09e34

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module MotionPrime
  class LabelElement < BaseElement
    include ElementContentPaddingMixin
    include ElementContentTextMixin
    include ElementTextMixin

    before_render :size_to_fit_if_needed
    after_render :size_to_fit

    def view_class
      "MPLabel"
    end

    def size_to_fit
      if computed_options[:size_to_fit]
        if computed_options[:width]
          view.setHeight([cached_content_outer_height, computed_options[:height]].compact.min)
        else
          view.sizeToFit
          # we should re-set values, because sizeToFit do not use padding
          view.setWidth(view.bounds.size.width + content_padding_width)
          view.setHeight(view.bounds.size.height + content_padding_height)
        end
      end
    end

    def size_to_fit_if_needed
      if computed_options[:size_to_fit] && computed_options[:width]
        @computed_options[:height_to_fit] = cached_content_outer_height
      end
    end

    def set_text(value)
      computed_options[:text] = value
      styler = ViewStyler.new(view, CGRectZero, computed_options)
      if styler.options[:attributed_text]
        view.attributedText = styler.options[:attributed_text]
      else
        view.text = value
      end
      @content_height = nil
      size_to_fit
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
motion-prime-0.8.2 motion-prime/elements/label.rb
motion-prime-0.8.1 motion-prime/elements/label.rb
motion-prime-0.8.0 motion-prime/elements/label.rb
motion-prime-0.7.2 motion-prime/elements/label.rb
motion-prime-0.7.1 motion-prime/elements/label.rb