Sha256: 4f85c07eeb8542d16fac9086490203b6da5571ca58926e161cd76c1427457566

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

motion_require '../draw.rb'
module MotionPrime
  class LabelDrawElement < DrawElement
    include MotionPrime::ElementTextDimensionsMixin

    def draw_in(rect)
      options = computed_options
      return if options[:hidden]

      size_to_fit_if_needed

      # render background
      bg_color = options[:background_color]
      if bg_color
        rect = CGRectMake(
          computed_left, computed_top, computed_outer_width, computed_outer_height
        )
        bg_color.uicolor.setFill
        UIRectFill(rect)
      end

      # render text
      color = options[:text_color]
      color.uicolor.set if color
      font = options[:font] || :system
      if options[:number_of_lines] != 0
        options[:text].to_s.drawAtPoint(
          CGPointMake(computed_left, computed_top),
          withFont: font.uifont
        )
      else
        rect = CGRectMake(
          computed_inner_left, computed_inner_top,
          computed_width, computed_height
        )
        line_break = options.has_key?(:line_break_mode) ? options[:line_break_mode] : :wordwrap
        alignment = options.has_key?(:text_alignment) ? options[:text_alignment] : :left
        options[:text].to_s.drawInRect(
          rect, withFont: font.uifont,
          lineBreakMode: line_break.uilinebreakmode,
          alignment: alignment.uitextalignment
        )
      end
    end

    def size_to_fit_if_needed
      if computed_options[:size_to_fit]
        @computed_options[:width] = content_width
        if computed_options[:width]
          @computed_options[:height] = content_height
        end
        reset_computed_values
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-prime-0.3.1 motion-prime/elements/draw/label.rb