Class: Motion::Xray::XrayTypewriterView

Inherits:
UIView
  • Object
show all
Defined in:
lib/motion-xray/xray_typewriter.rb

Overview

Copied from the gem of the same name, but I didn't want the dependency

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from UIView

build_xray, #xray, #xray_subviews

Instance Attribute Details

#background_viewObject

Returns the value of attribute background_view


5
6
7
# File 'lib/motion-xray/xray_typewriter.rb', line 5

def background_view
  @background_view
end

#bottom_marginObject

Returns the value of attribute bottom_margin


8
9
10
# File 'lib/motion-xray/xray_typewriter.rb', line 8

def bottom_margin
  @bottom_margin
end

#centeredObject

Returns the value of attribute centered


11
12
13
# File 'lib/motion-xray/xray_typewriter.rb', line 11

def centered
  @centered
end

#horizontal_spacingObject

Returns the value of attribute horizontal_spacing


7
8
9
# File 'lib/motion-xray/xray_typewriter.rb', line 7

def horizontal_spacing
  @horizontal_spacing
end

#left_marginObject

Returns the value of attribute left_margin


9
10
11
# File 'lib/motion-xray/xray_typewriter.rb', line 9

def left_margin
  @left_margin
end

#min_heightObject

Returns the value of attribute min_height


12
13
14
# File 'lib/motion-xray/xray_typewriter.rb', line 12

def min_height
  @min_height
end

#min_widthObject

Returns the value of attribute min_width


12
13
14
# File 'lib/motion-xray/xray_typewriter.rb', line 12

def min_width
  @min_width
end

#right_marginObject

Returns the value of attribute right_margin


9
10
11
# File 'lib/motion-xray/xray_typewriter.rb', line 9

def right_margin
  @right_margin
end

#scroll_viewObject

Returns the value of attribute scroll_view


4
5
6
# File 'lib/motion-xray/xray_typewriter.rb', line 4

def scroll_view
  @scroll_view
end

#top_marginObject

Returns the value of attribute top_margin


8
9
10
# File 'lib/motion-xray/xray_typewriter.rb', line 8

def top_margin
  @top_margin
end

#vertical_spacingObject

| DEFAULTS


76
77
78
# File 'lib/motion-xray/xray_typewriter.rb', line 76

def vertical_spacing
  @vertical_spacing
end

Instance Method Details

#expandObject


31
32
33
# File 'lib/motion-xray/xray_typewriter.rb', line 31

def expand
  self.frame = self.frame.height(self.subviews[0].frame.height)
end

#initWithFrame(frame) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/motion-xray/xray_typewriter.rb', line 14

def initWithFrame(frame)
  super.tap do
    self.spacing = 0
    self.margin = 0
    self.centered = false
    self.min_width = nil
    self.min_height = nil
    self.contentMode = :bottom.uicontentmode

    @row = []
  end
end

#layoutSubviewsObject

| | START AT 0, 0, AND START FLOATING |


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/motion-xray/xray_typewriter.rb', line 104

def layoutSubviews
  super
  # super
  # the max_height of *all* the rows so far (not just the current row)
  @max_height = top_margin
  clear

  # when a row would be longer than this, it is wrapped to the next row.
  @max_x = self.frame.size.width - right_margin

  self.subviews.each do |view|
    unless view == @background_view
      view.setNeedsLayout
      view.layoutIfNeeded
      add_next(view)
    end
  end
  clear(true)  # don't add vertical spacing

  self.frame = [self.frame.origin, [self.frame.size.width, @y + bottom_margin]]
  if scroll_view
    scroll_view.scrollEnabled = (@y > scroll_view.frame.size.height)
    scroll_view.contentSize = self.frame.size
  end
  if background_view
    background_view.frame = self.bounds
  end
end

#margin=(margins) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/motion-xray/xray_typewriter.rb', line 49

def margin=(margins)
  margins = [margins] unless margins.is_a? Enumerable

  case margins.length
  when 1
    @top_margin = @bottom_margin = @left_margin = @right_margin = margins[0]
  when 2
    @top_margin = margins[0]
    @bottom_margin = margins[0]
    @left_margin = margins[1]
    @right_margin = margins[1]
  when 3
    @top_margin = margins[0]
    @bottom_margin = margins[0]
    @right_margin = margins[1]
    @left_margin = margins[2]
  when 4
    @top_margin = margins[0]
    @right_margin = margins[1]
    @bottom_margin = margins[2]
    @left_margin = margins[3]
  else
    raise "Too many arguments (#{margins.length}) sent to MarginView#margin"
  end
end

#setNeedsLayoutObject


133
134
135
# File 'lib/motion-xray/xray_typewriter.rb', line 133

def setNeedsLayout
  super
end

#shrinkObject


27
28
29
# File 'lib/motion-xray/xray_typewriter.rb', line 27

def shrink
  self.frame = self.frame.height(0)
end

#spacing=(spacing) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/motion-xray/xray_typewriter.rb', line 35

def spacing=(spacing)
  if spacing.is_a? Array
    case spacing.length
    when 1
      self.spacing = spacing[0]
    when 2
      @horizontal_spacing = spacing[0]
      @vertical_spacing = spacing[1]
    end
  else
    @horizontal_spacing = @vertical_spacing = spacing
  end
end