module UnderOs::UI::Style::Positioning

Public Instance Methods

bottom() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 57
def bottom
  parent_size.y - top
end
bottom=(bottom) click to toggle source
# 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
contentHeight() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 85
def contentHeight
  @view.contentSize.height rescue 0
end
contentHeight=(value) click to toggle source
# 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
contentWidth() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 67
def contentWidth
  @view.contentSize.width rescue 0
end
contentWidth=(value) click to toggle source
# 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
height() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 17
def height
  @view.frame.size.height
end
height=(height) click to toggle source
# 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
left() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 37
def left
  @view.frame.origin.x
end
left=(left) click to toggle source
# 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
overflow() click to toggle source
# 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) click to toggle source
# 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
overflowX() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 135
def overflowX
  @view.isScrollEnabled ? @view.showsHorizontalScrollIndicator ? :scroll : :hidden : :visible
end
overflowX=(value) click to toggle source
# 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
overflowY() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 146
def overflowY
  @view.isScrollEnabled ? @view.showsVerticalScrollIndicator ? :scroll : :hidden : :visible
end
overflowY=(value) click to toggle source
# 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
right() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 47
def right
  parent_size.x - left
end
right=(right) click to toggle source
# 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
top() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 27
def top
  @view.frame.origin.y
end
top=(top) click to toggle source
# 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
width() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 7
def width
  @view.frame.size.width
end
width=(width) click to toggle source
# 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
zIndex() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 103
def zIndex
  @view.layer.zPosition
end
zIndex=(number) click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 107
def zIndex=(number)
  @view.layer.zPosition = number
end

Private Instance Methods

convert_size(size, dim) click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 159
def convert_size(size, dim)
  if size.is_a?(String)
    if size.ends_with?('%')
      size = size.slice(0, size.size-1).to_f
      size = parent_size[dim] / 100.0 * size
    end
  end

  size
end
parent_size() click to toggle source
# File lib/under_os/ui/style/positioning.rb, line 170
def parent_size
  parent = view.superview

  if !parent.superview && parent == UnderOs::App.history.current_page.view._
    parent = UIScreen.mainScreen.bounds.size
  else
    parent = parent.frame.size
  end

  {x: parent.width, y: parent.height}
end