Sha256: 346ddfff6d51f93f85165a8993c4ba5f551d08d15682e05d28778ffa14840b7d

Contents?: true

Size: 950 Bytes

Versions: 14

Compression:

Stored size: 950 Bytes

Contents

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

    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
motion-prime-0.7.0 motion-prime/elements/label.rb
motion-prime-0.6.0 motion-prime/elements/label.rb
motion-prime-0.5.7 motion-prime/elements/label.rb
motion-prime-0.5.6 motion-prime/elements/label.rb
motion-prime-0.5.5 motion-prime/elements/label.rb
motion-prime-0.5.4 motion-prime/elements/label.rb
motion-prime-0.5.3 motion-prime/elements/label.rb
motion-prime-0.5.2 motion-prime/elements/label.rb
motion-prime-0.5.1 motion-prime/elements/label.rb
motion-prime-0.5.0 motion-prime/elements/label.rb
motion-prime-0.4.5 motion-prime/elements/label.rb
motion-prime-0.4.4 motion-prime/elements/label.rb
motion-prime-0.4.3 motion-prime/elements/label.rb
motion-prime-0.4.2 motion-prime/elements/label.rb