Module: SugarCube::Adjust
- Defined in:
- lib/sugarcube/adjust.rb
Class Method Summary collapse
- .adjust(view = nil) ⇒ Object (also: a)
- .down(val = 1) ⇒ Object (also: d)
-
.frame(f = nil) ⇒ Object
(also: f)
| FRAME.
-
.left(val = 1) ⇒ Object
(also: l)
| ORIGIN.
- .origin(x = nil, y = nil) ⇒ Object (also: o)
-
.restore ⇒ Object
| RESTORE.
- .right(val = 1) ⇒ Object (also: r)
-
.shadow(shadow = nil) ⇒ Object
(also: h)
| SHADOW.
- .shorter(val = 1) ⇒ Object (also: s)
- .size(w = nil, h = nil) ⇒ Object (also: z)
- .taller(val = 1) ⇒ Object (also: t)
-
.thinner(val = 1) ⇒ Object
(also: n)
| SIZE.
-
.tree(view = nil, tab = nil, is_last = true, views_index = nil) ⇒ Object
| TREE.
- .up(val = 1) ⇒ Object (also: u)
- .wider(val = 1) ⇒ Object (also: w)
Class Method Details
.adjust(view = nil) ⇒ Object Also known as: a
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sugarcube/adjust.rb', line 5 def adjust view=nil @@sugarcube_view ||= nil return @@sugarcube_view if not view if view.is_a? Fixnum @@sugarcube_views ||= nil raise "no views have been assigned to SugarCube::Adjust::tree" unless @@sugarcube_views view = @@sugarcube_views[view] end @@sugarcube_view = view @@sugarcube_restore = { frame: SugarCube::Adjust.frame, shadow: SugarCube::Adjust.shadow, } view end |
.down(val = 1) ⇒ Object Also known as: d
58 59 60 61 62 63 64 65 |
# File 'lib/sugarcube/adjust.rb', line 58 def down val=1 @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame f.origin.y += val @@sugarcube_view.frame = f end |
.frame(f = nil) ⇒ Object Also known as: f
| FRAME
27 28 29 30 31 32 33 34 |
# File 'lib/sugarcube/adjust.rb', line 27 def frame f=nil @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view return SugarCube::CoreGraphics::Rect(@@sugarcube_view.frame) if not f @@sugarcube_view.frame = f end |
.left(val = 1) ⇒ Object Also known as: l
| ORIGIN
38 39 40 |
# File 'lib/sugarcube/adjust.rb', line 38 def left val=1 SugarCube::Adjust::right -val end |
.origin(x = nil, y = nil) ⇒ Object Also known as: o
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sugarcube/adjust.rb', line 68 def origin x=nil, y=nil @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame return SugarCube::CoreGraphics::Point(f.origin) if not x if y f.origin.x = x f.origin.y = y else f.origin = x end @@sugarcube_view.frame = f end |
.restore ⇒ Object
| RESTORE
219 220 221 222 223 224 225 226 |
# File 'lib/sugarcube/adjust.rb', line 219 def restore @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view @@sugarcube_restore.each do |msg, value| SugarCube::Adjust.send(msg, value) end end |
.right(val = 1) ⇒ Object Also known as: r
43 44 45 46 47 48 49 50 |
# File 'lib/sugarcube/adjust.rb', line 43 def right val=1 @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame f.origin.x += val @@sugarcube_view.frame = f end |
.shadow(shadow = nil) ⇒ Object Also known as: h
| SHADOW
134 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 |
# File 'lib/sugarcube/adjust.rb', line 134 def shadow shadow=nil @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view if shadow { opacity: :'shadowOpacity=', radius: :'shadowRadius=', offset: :'shadowOffset=', color: :'shadowColor=', path: :'shadowPath=', }.each { |key, msg| if value = shadow[key] if key == :color and [Symbol, Fixnum, NSString, UIImage, UIColor].any?{|klass| value.is_a? klass} value = value.uicolor.CGColor end @@sugarcube_view.layer.send(msg, value) @@sugarcube_view.layer.masksToBounds = false @@sugarcube_view.layer.shouldRasterize = true end } @@sugarcube_view else { opacity: @@sugarcube_view.layer.shadowOpacity, radius: @@sugarcube_view.layer.shadowRadius, offset: @@sugarcube_view.layer.shadowOffset, color: @@sugarcube_view.layer.shadowColor, path: @@sugarcube_view.layer.shadowPath, } end end |
.shorter(val = 1) ⇒ Object Also known as: s
101 102 103 |
# File 'lib/sugarcube/adjust.rb', line 101 def shorter val=1 SugarCube::Adjust::taller -val end |
.size(w = nil, h = nil) ⇒ Object Also known as: z
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sugarcube/adjust.rb', line 116 def size w=nil, h=nil @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame return SugarCube::CoreGraphics::Size(f.size) if not w if h f.size.width = w f.size.height = h else f.size = w end @@sugarcube_view.frame = f end |
.taller(val = 1) ⇒ Object Also known as: t
106 107 108 109 110 111 112 113 |
# File 'lib/sugarcube/adjust.rb', line 106 def taller val=1 @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame f.size.height += val @@sugarcube_view.frame = f end |
.thinner(val = 1) ⇒ Object Also known as: n
| SIZE
86 87 88 |
# File 'lib/sugarcube/adjust.rb', line 86 def thinner val=1 SugarCube::Adjust::wider -val end |
.tree(view = nil, tab = nil, is_last = true, views_index = nil) ⇒ Object
| TREE
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/sugarcube/adjust.rb', line 169 def tree(view=nil, tab=nil, is_last=true, views_index=nil) unless view @@sugarcube_view ||= nil if @@sugarcube_view view = @@sugarcube_view else view = UIApplication.sharedApplication.keyWindow end end if not views_index is_first = true @@sugarcube_views = [view] views_index = 0 else is_first = false @@sugarcube_views << view end space = ' ' if views_index < 10 print " " elsif views_index < 100 print " " elsif views_index > 999 # good god, man! space = '' end print views_index.to_s + ":" + space if tab print tab print is_last ? "`-- " : "+-- " tab += is_last ? " " : "| " else print ". " tab = "" end puts view.inspect view.subviews.each_index {|index| subview = view.subviews[index] views_index += 1 views_index = tree(subview, tab, index == view.subviews.length - 1, views_index) } return is_first ? view : views_index end |
.up(val = 1) ⇒ Object Also known as: u
53 54 55 |
# File 'lib/sugarcube/adjust.rb', line 53 def up val=1 SugarCube::Adjust::down -val end |
.wider(val = 1) ⇒ Object Also known as: w
91 92 93 94 95 96 97 98 |
# File 'lib/sugarcube/adjust.rb', line 91 def wider val=1 @@sugarcube_view ||= nil raise "no view has been assigned to SugarCube::Adjust::adjust" unless @@sugarcube_view f = @@sugarcube_view.frame f.size.width += val @@sugarcube_view.frame = f end |