Module: MotionPrime::ElementContentTextMixin

Includes:
ElementTextMixin
Included in:
ButtonElement, ErrorMessageElement, LabelDrawElement, LabelElement, TextFieldElement, TextViewElement
Defined in:
motion-prime/elements/_content_text_mixin.rb

Instance Method Summary collapse

Methods included from ElementTextMixin

#attributed_string, #html_string

Instance Method Details

#attributed_text?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'motion-prime/elements/_content_text_mixin.rb', line 53

def attributed_text?
  computed_options.slice(:html, :line_spacing, :line_height, :underline, :fragment_color).any? || computed_options[:attributed_text_options]
end

#cached_content_heightObject



49
50
51
# File 'motion-prime/elements/_content_text_mixin.rb', line 49

def cached_content_height
  @content_height ||= content_height
end

#cached_content_widthObject



38
39
40
# File 'motion-prime/elements/_content_text_mixin.rb', line 38

def cached_content_width
  @content_width ||= content_width
end

#content_attributed_textObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'motion-prime/elements/_content_text_mixin.rb', line 14

def content_attributed_text
  if view.try(:is_a?, UITextView) && view.text.present?
    text = view.attributedText
    text += ' ' if text.to_s.end_with?("\n") # does not respect \n at the end by default
    return text
  end

  options = {
    text: content_text,
    font: content_font,
    line_spacing: computed_options[:line_spacing],
    line_height: computed_options[:line_height]
  }
  computed_options[:html].present? ? html_string(options) : attributed_string(options)
end

#content_fontObject



10
11
12
# File 'motion-prime/elements/_content_text_mixin.rb', line 10

def content_font
  (is_a?(ButtonElement) ? button_content_font : input_content_font) || :system.uifont
end

#content_heightObject



42
43
44
45
46
47
# File 'motion-prime/elements/_content_text_mixin.rb', line 42

def content_height
  min, max = computed_options[:min_height].to_f, computed_options[:max_height]
  return min if content_text.blank?
  rect = get_content_rect(computed_options[:width] - content_padding_width)
  @content_height = [[rect.size.height.ceil, max].compact.min, min].max.ceil
end

#content_textObject



6
7
8
# File 'motion-prime/elements/_content_text_mixin.rb', line 6

def content_text
  is_a?(ButtonElement) ? button_content_text : input_content_text
end

#content_widthObject



30
31
32
33
34
35
36
# File 'motion-prime/elements/_content_text_mixin.rb', line 30

def content_width
  min, max = computed_options[:min_width].to_f, computed_options[:max_width]
  return min if content_text.blank?

  rect = get_content_rect(Float::MAX)
  @content_width = [[rect.size.width.ceil, max].compact.min, min].max.ceil
end