Module: UnderOs::UI::Style::Positioning

Included in:
UnderOs::UI::Style
Defined in:
lib/under_os/ui/style/positioning.rb

Instance Method Summary collapse

Instance Method Details

#bottomObject



57
58
59
# File 'lib/under_os/ui/style/positioning.rb', line 57

def bottom
  parent_size.y - top
end

#bottom=(bottom) ⇒ Object



61
62
63
64
65
# File 'lib/under_os/ui/style/positioning.rb', line 61

def bottom=(bottom)
  @view.frame = @view.frame.tap do |frame|
    frame.origin.y = parent_size[:y] - convert_size(bottom, :y) - frame.size.height
  end
end

#contentHeightObject



85
86
87
# File 'lib/under_os/ui/style/positioning.rb', line 85

def contentHeight
  @view.contentSize.height rescue 0
end

#contentHeight=(value) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/under_os/ui/style/positioning.rb', line 89

def contentHeight=(value)
  return unless @view.is_a?(UIScrollView)

  if value == 'auto'
    value = 0
    @view.subviews.each do |view|
      y = view.origin.y + view.size.height
      value = y if y > value
    end
  end

  @view.contentSize = CGSizeMake(contentWidth, value)
end

#contentWidthObject



67
68
69
# File 'lib/under_os/ui/style/positioning.rb', line 67

def contentWidth
  @view.contentSize.width rescue 0
end

#contentWidth=(value) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/under_os/ui/style/positioning.rb', line 71

def contentWidth=(value)
  return unless @view.is_a?(UIScrollView)

  if value == 'auto'
    value = 0
    @view.subviews.each do |view|
      x = view.origin.x + view.size.width
      value = x if x > value
    end
  end

  @view.contentSize = CGSizeMake(value, contentHeight)
end

#heightObject



17
18
19
# File 'lib/under_os/ui/style/positioning.rb', line 17

def height
  @view.frame.size.height
end

#height=(height) ⇒ Object



21
22
23
24
25
# File 'lib/under_os/ui/style/positioning.rb', line 21

def height=(height)
  @view.frame = @view.frame.tap do |frame|
    frame.size.height = convert_size(height, :y)
  end
end

#leftObject



37
38
39
# File 'lib/under_os/ui/style/positioning.rb', line 37

def left
  @view.frame.origin.x
end

#left=(left) ⇒ Object



41
42
43
44
45
# File 'lib/under_os/ui/style/positioning.rb', line 41

def left=(left)
  @view.frame = @view.frame.tap do |frame|
    frame.origin.x = convert_size(left, :x)
  end
end

#overflowObject



111
112
113
114
115
116
117
118
119
120
# File 'lib/under_os/ui/style/positioning.rb', line 111

def overflow
  case "#{overflowX}-#{overflowY}"
  when 'visible-visible' then :visible
  when 'hidden-hidden'   then :hidden
  when 'scroll-scroll'   then :scroll
  when 'scroll-visible'  then :x
  when 'visible-scroll'  then :y
  else                   [overflowX, overflowY]
  end
end

#overflow=(value) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/under_os/ui/style/positioning.rb', line 122

def overflow=(value)
  x, y = case value.to_s
  when 'x'       then ['scroll',  'visible']
  when 'y'       then ['visible', 'scroll']
  when 'hidden'  then ['hidden',  'hidden']
  when 'visible' then ['visible', 'visible']
  else                ['scroll',  'scroll']
  end

  self.overflowX = x
  self.overflowY = y
end

#overflowXObject



135
136
137
# File 'lib/under_os/ui/style/positioning.rb', line 135

def overflowX
  @view.isScrollEnabled ? @view.showsHorizontalScrollIndicator ? :scroll : :hidden : :visible
end

#overflowX=(value) ⇒ Object



139
140
141
142
143
144
# File 'lib/under_os/ui/style/positioning.rb', line 139

def overflowX=(value)
  return unless @view.is_a?(UIScrollView)
  @view.directionalLockEnabled = overflowY == :visible
  @view.showsHorizontalScrollIndicator = value.to_s == 'scroll'
  @view.scrollEnabled = value.to_s != 'visible' || overflowY != :visible
end

#overflowYObject



146
147
148
# File 'lib/under_os/ui/style/positioning.rb', line 146

def overflowY
  @view.isScrollEnabled ? @view.showsVerticalScrollIndicator ? :scroll : :hidden : :visible
end

#overflowY=(value) ⇒ Object



150
151
152
153
154
155
# File 'lib/under_os/ui/style/positioning.rb', line 150

def overflowY=(value)
  return unless @view.is_a?(UIScrollView)
  @view.directionalLockEnabled = overflowX == :visible
  @view.showsVerticalScrollIndicator = value.to_s == 'scroll'
  @view.scrollEnabled = overflowX != :visible || value.to_s != 'visible'
end

#rightObject



47
48
49
# File 'lib/under_os/ui/style/positioning.rb', line 47

def right
  parent_size.x - left
end

#right=(right) ⇒ Object



51
52
53
54
55
# File 'lib/under_os/ui/style/positioning.rb', line 51

def right=(right)
  @view.frame = @view.frame.tap do |frame|
    frame.origin.x = parent_size[:x] - convert_size(right, :x) - frame.size.width
  end
end

#topObject



27
28
29
# File 'lib/under_os/ui/style/positioning.rb', line 27

def top
  @view.frame.origin.y
end

#top=(top) ⇒ Object



31
32
33
34
35
# File 'lib/under_os/ui/style/positioning.rb', line 31

def top=(top)
  @view.frame = @view.frame.tap do |frame|
    frame.origin.y = convert_size(top, :y)
  end
end

#widthObject



7
8
9
# File 'lib/under_os/ui/style/positioning.rb', line 7

def width
  @view.frame.size.width
end

#width=(width) ⇒ Object



11
12
13
14
15
# File 'lib/under_os/ui/style/positioning.rb', line 11

def width=(width)
  @view.frame = @view.frame.tap do |frame|
    frame.size.width = convert_size(width, :x)
  end
end

#zIndexObject



103
104
105
# File 'lib/under_os/ui/style/positioning.rb', line 103

def zIndex
  @view.layer.zPosition
end

#zIndex=(number) ⇒ Object



107
108
109
# File 'lib/under_os/ui/style/positioning.rb', line 107

def zIndex=(number)
  @view.layer.zPosition = number
end