Class: MotionKit::NSViewLayout
- Inherits:
-
Layout
- Object
- BaseLayout
- TreeLayout
- Layout
- MotionKit::NSViewLayout
- Defined in:
- lib/motion-kit-osx/layouts/nsview_layout.rb,
lib/motion-kit-osx/layouts/nsview_layout_frame.rb,
lib/motion-kit-osx/layouts/nsview_layout_constraints.rb,
lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseLayout
Instance Method Summary collapse
- #_calculate_frame(f, from: from_view, relative_to: point) ⇒ Object
- #_fix_frame_value(value) ⇒ Object
-
#above(from_view, f = {}) ⇒ Object
The first arg can be a view or a frame.
-
#after(from_view, f = {}) ⇒ Object
(also: #right_of)
The first arg can be a view or a frame.
- #autoresizing_mask(*values) ⇒ Object (also: #autoresizingMask)
-
#before(from_view, f = {}) ⇒ Object
(also: #left_of)
The first arg can be a view or a frame.
-
#below(from_view, f = {}) ⇒ Object
The first arg can be a view or a frame.
- #bottom(value) ⇒ Object
- #center(value) ⇒ Object (also: #middle)
- #center_x(value) ⇒ Object (also: #middle_x)
- #center_y(value) ⇒ Object (also: #middle_y)
- #constraints(view = nil, &block) ⇒ Object
- #flipped? ⇒ Boolean
- #frame(value) ⇒ Object
-
#from_bottom(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_bottom_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_bottom_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_center(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_top(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_top_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
-
#from_top_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame.
- #height(value) ⇒ Object (also: #h)
- #origin(value) ⇒ Object
-
#relative_to(from_view, f) ⇒ Object
The first arg must be a view.
- #right(value) ⇒ Object
- #size(value) ⇒ Object
- #top(value) ⇒ Object
- #width(value) ⇒ Object (also: #w)
- #x(value) ⇒ Object (also: #left)
- #y(value) ⇒ Object
Methods inherited from Layout
#add_child, #default_root, #reapply!, #remove_child
Methods inherited from TreeLayout
#add, #all, #build, #built?, #call_style_method, #create, #create_default_root_context, #first, #get, #initial, #last, #nth, #reapply, #reapply!, #remove, #root, #view, view
Methods inherited from BaseLayout
#add_deferred_block, #apply, #apply_with_context, #apply_with_target, #context, #deferred, #deferred_blocks, delegate_method_fix, #initialize, #ipad?, #iphone35?, #iphone4?, #iphone?, method_added, #method_missing, #orientation?, overridden_methods, override_start, override_stop, overrides, #retina?, #run_deferred, #set_layout, #target, #v
Methods included from BaseLayoutClassMethods
#layout_for, #memoize, #new_child, #target_klasses, #targets
Constructor Details
This class inherits a constructor from MotionKit::BaseLayout
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MotionKit::BaseLayout
Instance Method Details
#_calculate_frame(f, from: from_view, relative_to: point) ⇒ Object
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 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 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 147 def _calculate_frame(f, from: from_view, relative_to: point) if from_view.is_a?(Symbol) from_view = self.get(from_view) end from_view_size = from_view.frame.size o = from_view.convertPoint([0, 0], toView: target.superview) calculate_view = target if point[:x] == :reset || point[:y] == :reset calculate_view = NSView.alloc.initWithFrame([[0, 0], target.frame.size]) end if f.is_a?(Hash) f = f.merge(relative: true, flipped: flipped?) end f = MotionKit.calculate(calculate_view, :frame, f, from_view) f.origin.x += o.x f.origin.y += o.y case point[:x] when :min, :reset # pass when :mid f.origin.x += (from_view_size.width - f.size.width) / 2.0 when :max f.origin.x += from_view_size.width - f.size.width when :before f.origin.x -= f.size.width when :after f.origin.x += from_view_size.width else f.origin.x += point[:x] end case point[:y] when :reset # pass when :min unless flipped? f.origin.y += from_view_size.height - f.size.height end when :mid f.origin.y += (from_view_size.height - f.size.height) / 2.0 when :max if flipped? f.origin.y += from_view_size.height - f.size.height end when :above if flipped? f.origin.y += from_view_size.height else f.origin.y -= from_view_size.height + f.size.height end when :below if flipped? f.origin.y -= f.size.height else # pass end else f.origin.y += point[:y] end return f end |
#_fix_frame_value(value) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 6 def _fix_frame_value(value) if value.is_a?(Hash) && value[:relative] return value.merge(flipped: flipped?) end return value end |
#above(from_view, f = {}) ⇒ Object
The first arg can be a view or a frame
343 344 345 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 343 def above(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :above }) end |
#after(from_view, f = {}) ⇒ Object Also known as: right_of
The first arg can be a view or a frame
362 363 364 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 362 def after(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :after, y: :reset }) end |
#autoresizing_mask(*values) ⇒ Object Also known as: autoresizingMask
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_autoresizing.rb', line 5 def autoresizing_mask(*values) value = 0 values.each do |mask| case mask when :flexible_left value |= NSViewMinXMargin when :flexible_width value |= NSViewWidthSizable when :flexible_right value |= NSViewMaxXMargin when :flexible_top value |= NSViewMaxYMargin when :flexible_height value |= NSViewHeightSizable when :flexible_bottom value |= NSViewMinYMargin when :rigid_left value ^= NSViewMinXMargin when :rigid_width value ^= NSViewWidthSizable when :rigid_right value ^= NSViewMaxXMargin when :rigid_top value ^= NSViewMaxYMargin when :rigid_height value ^= NSViewHeightSizable when :rigid_bottom value ^= NSViewMinYMargin when :fill value |= NSViewWidthSizable | NSViewHeightSizable when :fill_top value |= NSViewWidthSizable | NSViewMinYMargin when :fill_bottom value |= NSViewWidthSizable | NSViewMaxYMargin when :fill_left value |= NSViewHeightSizable | NSViewMaxXMargin when :fill_right value |= NSViewHeightSizable | NSViewMinXMargin when :pin_to_top_left value |= NSViewMaxXMargin | NSViewMinYMargin when :pin_to_top value |= NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin when :pin_to_top_right value |= NSViewMinXMargin | NSViewMinYMargin when :pin_to_left value |= NSViewMaxYMargin | NSViewMinYMargin | NSViewMaxXMargin when :pin_to_center, :pin_to_middle value |= NSViewMaxYMargin | NSViewMinYMargin | NSViewMinXMargin | NSViewMaxXMargin when :pin_to_right value |= NSViewMaxYMargin | NSViewMinYMargin | NSViewMinXMargin when :pin_to_bottom_left value |= NSViewMaxXMargin | NSViewMaxYMargin when :pin_to_bottom value |= NSViewMinXMargin | NSViewMaxXMargin | NSViewMaxYMargin when :pin_to_bottom_right value |= NSViewMinXMargin | NSViewMaxYMargin else value |= mask end end target.autoresizingMask = value value end |
#before(from_view, f = {}) ⇒ Object Also known as: left_of
The first arg can be a view or a frame
355 356 357 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 355 def before(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :before, y: :reset }) end |
#below(from_view, f = {}) ⇒ Object
The first arg can be a view or a frame
349 350 351 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 349 def below(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :below }) end |
#bottom(value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 52 def bottom(value) value = _fix_frame_value(value) f = target.frame f.origin.y = MotionKit.calculate(target, :height, value) unless flipped? f.origin.y -= f.size.height end target.frame = f if flipped? return CGRectGetMinY(target.frame) else return CGRectGetMaxY(target.frame) end end |
#center(value) ⇒ Object Also known as: middle
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 120 def center(value) value = _fix_frame_value(value) f = target.frame center = MotionKit.calculate(target, :center, value) origin = CGPoint.new(center.x, center.y) origin.x -= f.size.width / 2 origin.y -= f.size.height / 2 f.origin = origin target.frame = f return center end |
#center_x(value) ⇒ Object Also known as: middle_x
34 35 36 37 38 39 40 41 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 34 def center_x(value) value = _fix_frame_value(value) f = target.frame f.origin.x = MotionKit.calculate(target, :width, value) f.origin.x -= f.size.width / 2 target.frame = f return CGRectGetMidX(target.frame) end |
#center_y(value) ⇒ Object Also known as: middle_y
84 85 86 87 88 89 90 91 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 84 def center_y(value) value = _fix_frame_value(value) f = target.frame f.origin.y = MotionKit.calculate(target, :height, value) f.origin.y -= f.size.height / 2 target.frame = f return CGRectGetMidY(target.frame) end |
#constraints(view = nil, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_constraints.rb', line 5 def constraints(view=nil, &block) view ||= target if view.is_a?(Symbol) view = self.get(view) end view.setTranslatesAutoresizingMaskIntoConstraints(false) deferred do constraints_target = ConstraintsTarget.new(view) context(constraints_target, &block) constraints_target.apply_all_constraints(self, view) end end |
#flipped? ⇒ Boolean
13 14 15 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 13 def flipped? target.superview && !target.superview.flipped? end |
#frame(value) ⇒ Object
141 142 143 144 145 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 141 def frame(value) value = _fix_frame_value(value) target.frame = MotionKit.calculate(target, :frame, value) return target.frame end |
#from_bottom(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
317 318 319 320 321 322 323 324 325 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 317 def from_bottom(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :min }) end |
#from_bottom_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
303 304 305 306 307 308 309 310 311 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 303 def from_bottom_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :min }) end |
#from_bottom_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
331 332 333 334 335 336 337 338 339 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 331 def from_bottom_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :min }) end |
#from_center(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
275 276 277 278 279 280 281 282 283 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 275 def from_center(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :mid }) end |
#from_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
261 262 263 264 265 266 267 268 269 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 261 def from_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :mid }) end |
#from_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
289 290 291 292 293 294 295 296 297 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 289 def from_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :mid }) end |
#from_top(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
233 234 235 236 237 238 239 240 241 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 233 def from_top(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :max }) end |
#from_top_left(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
219 220 221 222 223 224 225 226 227 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 219 def from_top_left(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :max }) end |
#from_top_right(from_view = nil, f = nil) ⇒ Object
The first arg can be a view or a frame
247 248 249 250 251 252 253 254 255 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 247 def from_top_right(from_view=nil, f=nil) if from_view.is_a?(Hash) f = from_view from_view = nil end f ||= {} from_view ||= target.superview _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :max }) end |
#height(value) ⇒ Object Also known as: h
103 104 105 106 107 108 109 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 103 def height(value) value = _fix_frame_value(value) f = target.frame f.size.height = MotionKit.calculate(target, :height, value) target.frame = f return CGRectGetHeight(f) end |
#origin(value) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 112 def origin(value) value = _fix_frame_value(value) f = target.frame f.origin = MotionKit.calculate(target, :origin, value) target.frame = f return target.frame.origin end |
#relative_to(from_view, f) ⇒ Object
The first arg must be a view
369 370 371 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 369 def relative_to(from_view, f) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :reset }) end |
#right(value) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 26 def right(value) value = _fix_frame_value(value) f = target.frame f.origin.x = MotionKit.calculate(target, :width, value) - f.size.width target.frame = f return CGRectGetMaxX(f) end |
#size(value) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 133 def size(value) value = _fix_frame_value(value) f = target.frame f.size = MotionKit.calculate(target, :size, value) target.frame = f return target.frame.size end |
#top(value) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 68 def top(value) value = _fix_frame_value(value) f = target.frame f.origin.y = MotionKit.calculate(target, :height, value) if flipped? f.origin.y -= f.size.height end target.frame = f if flipped? return CGRectGetMaxY(f) else return CGRectGetMinY(f) end end |
#width(value) ⇒ Object Also known as: w
94 95 96 97 98 99 100 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 94 def width(value) value = _fix_frame_value(value) f = target.frame f.size.width = MotionKit.calculate(target, :width, value) target.frame = f return CGRectGetWidth(f) end |