class MotionKit::NSWindowHelpers
Public Instance Methods
_calculate_frame(f, from: from_window, relative_to: point)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 146 def _calculate_frame(f, from: from_window, relative_to: point) if from_window.is_a?(Symbol) from_window = self.get_view(from_window) end from_window_size = from_window.frame.size calculate_window = target if point[:x] == :reset || point[:y] == :reset calculate_window = NSWindow.alloc.init calculate_window.setFrame([[0, 0], target.frame.size], display: false) end if f.is_a?(Hash) f = f.merge(relative: true, flipped: true) end f = MotionKit.calculate(calculate_window, :frame, f, from_window) if from_window.is_a?(NSWindow) f.origin.x += from_window.frame.origin.x f.origin.y += from_window.frame.origin.y end case point[:x] when :min, :reset # pass when :mid f.origin.x += (from_window_size.width - f.size.width) / 2.0 when :max f.origin.x += from_window_size.width - f.size.width when :before f.origin.x -= f.size.width when :after f.origin.x += from_window_size.width else f.origin.x += point[:x] end case point[:y] when :reset, :min # pass when :mid f.origin.y += (from_window_size.height - f.size.height) / 2.0 when :max f.origin.y += from_window_size.height - f.size.height when :above f.origin.y += from_window_size.height when :below f.origin.y -= f.size.height else f.origin.y += point[:y] end return f end
_fix_frame_value(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 5 def _fix_frame_value(value) if value.is_a?(Hash) && value[:relative] return value.merge(flipped: true) end return value end
above(from_window, f={})
click to toggle source
The first arg can be a window or a frame @example
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 330 def above(from_window, f={}) _calculate_frame(f, from: from_window, relative_to: { x: :reset, y: :above }) end
after(from_window, f={})
click to toggle source
The first arg can be a window or a frame @example
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 349 def after(from_window, f={}) _calculate_frame(f, from: from_window, relative_to: { x: :after, y: :reset }) end
Also aliased as: right_of
before(from_window, f={})
click to toggle source
The first arg can be a window or a frame @example
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 342 def before(from_window, f={}) _calculate_frame(f, from: from_window, relative_to: { x: :before, y: :reset }) end
Also aliased as: left_of
below(from_window, f={})
click to toggle source
The first arg can be a window or a frame @example
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 336 def below(from_window, f={}) _calculate_frame(f, from: from_window, relative_to: { x: :reset, y: :below }) end
bottom(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 62 def bottom(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.y = MotionKit.calculate(target, :height, value, screen) target.setFrame(f, display: true) return CGRectGetMinY(target.frame) end
center(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 123 def center(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen center = MotionKit.calculate(target, :center, value, screen) origin = CGPoint.new(center.x, center.y) origin.x -= f.size.width / 2 origin.y -= f.size.height / 2 f.origin = origin target.setFrame(f, display: true) return center end
Also aliased as: middle
center_x(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 42 def center_x(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.x = MotionKit.calculate(target, :width, value, screen) f.origin.x -= f.size.width / 2 target.setFrame(f, display: true) return CGRectGetMidX(target.frame) end
Also aliased as: middle_x
center_y(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 83 def center_y(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.y = MotionKit.calculate(target, :height, value, screen) f.origin.y -= f.size.height / 2 target.setFrame(f, display: true) return CGRectGetMidY(target.frame) end
Also aliased as: middle_y
frame(value, autosave_name=nil)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 12 def frame(value, autosave_name=nil) value = _fix_frame_value(value) screen = target.screen || NSScreen.mainScreen value = MotionKit.calculate(target, :frame, value, screen) target.setFrame(value, display: true) if autosave_name target.setFrameAutosaveName(autosave_name) end return target.frame end
from_bottom(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_bottom(width: 80, height: 22) frame from_bottom(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 304 def from_bottom(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :mid, y: :min }) end
from_bottom_left(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_bottom_left(width: 80, height: 22) frame from_bottom_left(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 290 def from_bottom_left(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :min, y: :min }) end
from_bottom_right(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_bottom_right(width: 80, height: 22) frame from_bottom_right(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 318 def from_bottom_right(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :max, y: :min }) end
from_center(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_center(width: 80, height: 22) frame from_center(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 262 def from_center(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :mid, y: :mid }) end
from_left(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_left(width: 80, height: 22) frame from_left(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 248 def from_left(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :min, y: :mid }) end
from_right(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_right(width: 80, height: 22) frame from_right(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 276 def from_right(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :max, y: :mid }) end
from_top(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_top(width: 80, height: 22) frame from_top(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 220 def from_top(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :mid, y: :max }) end
from_top_left(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_top_left(width: 80, height: 22) frame from_top_left(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 206 def from_top_left(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :min, y: :max }) end
from_top_right(from_window=nil, f=nil)
click to toggle source
The first arg can be a window or a frame @example
frame from_top_right(width: 80, height: 22) frame from_top_right(another_view, width: 80, height: 22)
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 234 def from_top_right(from_window=nil, f=nil) if from_window.is_a?(Hash) f = from_window from_window = nil end f ||= {} from_window ||= target.screen || NSScreen.mainScreen _calculate_frame(f, from: from_window, relative_to: { x: :max, y: :max }) end
height(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 104 def height(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.size.height = MotionKit.calculate(target, :height, value, screen) target.setFrame(f, display: true) return CGRectGetHeight(f) end
Also aliased as: h
origin(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 114 def origin(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin = MotionKit.calculate(target, :origin, value, screen) target.setFrame(f, display: true) return target.frame.origin end
relative_to(from_window, f)
click to toggle source
The first arg must be a view @example
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 356 def relative_to(from_window, f) _calculate_frame(f, from: from_window, relative_to: { x: :reset, y: :reset }) end
right(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 33 def right(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.x = MotionKit.calculate(target, :width, value, screen) - f.size.width target.setFrame(f, display: true) return CGRectGetMaxX(f) end
size(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 137 def size(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.size = MotionKit.calculate(target, :size, value, screen) target.setFrame(f, display: true) return target.frame.size end
top(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 72 def top(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.y = MotionKit.calculate(target, :height, value, screen) f.origin.y -= f.size.height target.setFrame(f, display: true) return CGRectGetMaxY(f) end
width(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 94 def width(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.size.width = MotionKit.calculate(target, :width, value, screen) target.setFrame(f, display: true) return CGRectGetWidth(f) end
Also aliased as: w
x(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 23 def x(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.x = MotionKit.calculate(target, :width, value, screen) target.setFrame(f, display: true) return CGRectGetMinX(f) end
Also aliased as: left
y(value)
click to toggle source
# File lib/motion-kit-osx/helpers/nswindow_frame_helpers.rb, line 53 def y(value) value = _fix_frame_value(value) f = target.frame screen = target.screen || NSScreen.mainScreen f.origin.y = MotionKit.calculate(target, :height, value, screen) target.setFrame(f, display: true) return CGRectGetMinY(f) end