Method: SugarCube::CoreGraphics.EdgeInsets
- Defined in:
- lib/ios/sugarcube-coregraphics/core_graphics.rb
.EdgeInsets(top_or_inset, left = nil, bottom = nil, right = nil) ⇒ Object
Accepts 1..4 arguments. 1 argument should be an Array[Numeric * 1..4], UIEdgeInset, or Numeric 2 arguments should be top/bottom, left/right 3 arguments should be top, left/right, bottom 4 should be top, left, bottom, right
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ios/sugarcube-coregraphics/core_graphics.rb', line 135 def EdgeInsets(top_or_inset, left=nil, bottom=nil, right=nil) if left.nil? and bottom.nil? and right.nil? case top_or_inset when UIEdgeInsets top = top_or_inset.top left = top_or_inset.left bottom = top_or_inset.bottom right = top_or_inset.right when CGRect # converting a rect to insets is hard to visualize, # but it goes something like this: # +-----------.....----------+ # | origin |y | top inset | # |--------+ V | # | x .......... | # . . . . # .-------->. . right . # . left . . inset . # . inset . .<------. # . . . . # | .......... w | # | ^ +------| # | bottom inset| h| size | # +-----------.....----------+ left = top_or_inset.origin.x top = top_or_inset.origin.y right = top_or_inset.size.width bottom = top_or_inset.size.height when Array # okay, in this ONE case, I use the splat operator. return SugarCube::CoreGraphics::EdgeInsets(*top_or_inset) when Numeric top = left = bottom = right = top_or_inset else raise RuntimeError.new("Invalid argument sent to EdgeInsets(#{top_or_inset.inspect})") end elsif bottom.nil? and right.nil? return SugarCube::CoreGraphics::EdgeInsets(top_or_inset, left, top_or_inset, left) elsif right.nil? return SugarCube::CoreGraphics::EdgeInsets(top_or_inset, left, bottom, left) else top = top_or_inset end return UIEdgeInsets.new(top, left, bottom, right) end |