Class: MotionPrime::LabelDrawElement
- Inherits:
-
DrawElement
- Object
- BaseElement
- DrawElement
- MotionPrime::LabelDrawElement
- Defined in:
- motion-prime/elements/draw/label.rb
Instance Attribute Summary
Attributes inherited from BaseElement
#name, #options, #screen, #section, #styles, #view, #view_class, #view_name
Instance Method Summary collapse
- #default_padding_for(side) ⇒ Object
- #draw_in(rect) ⇒ Object
-
#draw_in_context(context) ⇒ Object
using hack for bug described here: stackoverflow.com/questions/19232850/nsattributedstring-drawinrect-disappears-when-the-frame-is-offset TODO: check it in iOS 7.1 and remove CGContext manuplations (pass innerRect/topLeftCorner) if fixed.
- #draw_options ⇒ Object
- #original_options ⇒ Object
- #set_text_position ⇒ Object
- #size_to_fit_if_needed ⇒ Object
Methods included from DrawBackgroundMixin
#draw_background_in_context, #draw_rect_in_context
Methods included from ElementTextMixin
#attributed_string, #extract_attributed_string_options, #html_string
Methods included from ElementContentTextMixin
#attributed_text?, #attributed_text_for_text, #cached_content_height, #cached_content_width, #content_font, #content_height, #content_text, #content_width, #current_attributed_text, #height_for_attributed_text, #height_for_text, #multiline_content_width, #width_for_attributed_text, #width_for_text
Methods inherited from DrawElement
#bind_gesture, #computed_frame, factory, #hide, #on_container_render, #render!, #rerender!, #show, #view
Methods included from ElementContentPaddingMixin
#cached_content_outer_height, #cached_content_outer_width, #content_outer_height, #content_outer_width, #content_padding_bottom, #content_padding_height, #content_padding_left, #content_padding_right, #content_padding_top, #content_padding_width
Methods included from FrameCalculatorMixin
Methods inherited from BaseElement
#add_target, after_render, before_render, #bind_gesture, #cell_element?, #cell_section?, #compute_options!, #computed_options, #dealloc, factory, #hide, #initialize, #notify_section_after_render, #notify_section_before_render, #reload!, #render, #render!, #rerender!, #show, #update, #update_options, #update_with_options
Methods included from HasClassFactory
#camelize_factory, #class_factory, #low_camelize_factory, #underscore_factory
Methods included from HasStyleOptions
Methods included from HasStyleChainBuilder
Methods included from HasNormalizer
#debug_info, #element?, #normalize_object, #normalize_options, #normalize_value
Constructor Details
This class inherits a constructor from MotionPrime::BaseElement
Instance Method Details
#default_padding_for(side) ⇒ Object
89 90 91 92 |
# File 'motion-prime/elements/draw/label.rb', line 89 def default_padding_for(side) return super unless side.to_s == 'top' @padding_top || 0 end |
#draw_in(rect) ⇒ Object
44 45 46 47 |
# File 'motion-prime/elements/draw/label.rb', line 44 def draw_in(rect) super draw_in_context(UIGraphicsGetCurrentContext()) end |
#draw_in_context(context) ⇒ Object
using hack for bug described here: stackoverflow.com/questions/19232850/nsattributedstring-drawinrect-disappears-when-the-frame-is-offset TODO: check it in iOS 7.1 and remove CGContext manuplations (pass innerRect/topLeftCorner) if fixed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'motion-prime/elements/draw/label.rb', line 51 def draw_in_context(context) return if [:hidden] size_to_fit_if_needed set_text_position draw_background_in_context(context) UIGraphicsPushContext(context) = if .slice(:is_html, :line_spacing, :line_height, :underline, :force_attributed, :fragment_color, :fragment_font).any? prepared_text = [:is_html] ? html_string() : attributed_string() CGContextSaveGState(context) if [:inner_rect] rect = [:inner_rect] CGContextTranslateCTM(context, *rect.origin.to_a) prepared_text.drawInRect(CGRectMake(0, 0, *rect.size.to_a)) else CGContextTranslateCTM(context, *[:top_left_corner].to_a) prepared_text.drawAtPoint(CGPointMake(0, 0)) end CGContextRestoreGState(context) else # regular string prepared_text = [:text] [:text_color].set if [:inner_rect] prepared_text.drawInRect([:inner_rect], withFont: [:font], lineBreakMode: [:line_break_mode], alignment: [:text_alignment]) else prepared_text.drawAtPoint([:top_left_corner], withFont: [:font]) end end UIGraphicsPopContext() end |
#draw_options ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'motion-prime/elements/draw/label.rb', line 8 def = text = ([:html] || [:text]).to_s.gsub(/\A[\n\r]+/, '') text_color = ([:text_color] || :black).uicolor font = (extract_font_from() || :system).uifont text_alignment_name = .fetch(:text_alignment, :left) text_alignment = text_alignment_name.nstextalignment default_break_mode = [:size_to_fit] ? :word_wrap : :tail_truncation line_break_mode_name = .fetch(:line_break_mode, default_break_mode) line_break_mode = line_break_mode_name.uilinebreakmode top_left_corner = CGPointMake(frame_inner_left, frame_inner_top) if [:number_of_lines].to_i.zero? inner_rect = CGRectMake(*top_left_corner.to_a, frame_width, frame_height) end super.merge({ text: text, is_html: [:html].present?, text_color: text_color, font: font, text_alignment_name: text_alignment_name, text_alignment: text_alignment, line_break_mode_name: line_break_mode_name, line_break_mode: line_break_mode, line_spacing: [:line_spacing], line_height: [:line_height], underline: [:underline], fragment_color: [:fragment_color], fragment_font: [:fragment_font], top_left_corner: top_left_corner, inner_rect: inner_rect }) end |
#original_options ⇒ Object
120 121 122 |
# File 'motion-prime/elements/draw/label.rb', line 120 def @_original_options ||= .clone end |
#set_text_position ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'motion-prime/elements/draw/label.rb', line 108 def set_text_position # FIXME: there is a bug when overriding this method for custom fonts (adjust @padding_top), you must set 'padding' to 0 if .slice(:padding_top, :padding_bottom, :padding, :size_to_fit).values.none? [:width] ||= frame_width frame_height = [:height] || frame_outer_height content_height = cached_content_height content_height = frame_height if content_height > frame_height @padding_top = (frame_height - content_height)/2 # @padding_top += 1 unless @padding_top.zero? end end |
#size_to_fit_if_needed ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'motion-prime/elements/draw/label.rb', line 94 def size_to_fit_if_needed if [:size_to_fit] [:width] = cached_content_outer_width unless [:width] [:height] = cached_content_outer_height unless [:height] reset_computed_values elsif ![:width] && (![:left] || ![:right]) [:width] = cached_content_outer_width unless [:width] reset_computed_values elsif .slice(:height, :top, :bottom).values.none? [:height] = cached_content_outer_height unless [:height] reset_computed_values end end |