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_missing, #orientation?, #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
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 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 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 146 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
5 6 7 8 9 10 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 5 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
342 343 344 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 342 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
361 362 363 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 361 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
354 355 356 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 354 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
348 349 350 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 348 def below(from_view, f={}) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :below }) end |
#bottom(value) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 51 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
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 119 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
33 34 35 36 37 38 39 40 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 33 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
83 84 85 86 87 88 89 90 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 83 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
12 13 14 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 12 def flipped? target.superview && !target.superview.flipped? end |
#frame(value) ⇒ Object
140 141 142 143 144 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 140 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
316 317 318 319 320 321 322 323 324 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 316 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
302 303 304 305 306 307 308 309 310 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 302 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
330 331 332 333 334 335 336 337 338 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 330 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
274 275 276 277 278 279 280 281 282 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 274 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
260 261 262 263 264 265 266 267 268 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 260 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
288 289 290 291 292 293 294 295 296 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 288 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
232 233 234 235 236 237 238 239 240 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 232 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
218 219 220 221 222 223 224 225 226 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 218 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
246 247 248 249 250 251 252 253 254 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 246 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
102 103 104 105 106 107 108 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 102 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
111 112 113 114 115 116 117 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 111 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
368 369 370 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 368 def relative_to(from_view, f) _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :reset }) end |
#right(value) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 25 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
132 133 134 135 136 137 138 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 132 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 67 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
93 94 95 96 97 98 99 |
# File 'lib/motion-kit-osx/layouts/nsview_layout_frame.rb', line 93 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 |