Sha256: 0c3eec4262a1e59b46738b2f399948385881d259c1180f4b9647427ca56a5652

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# @provides MotionKit::WindowLayout
# @provides MotionKit::NSWindowHelpers
# @requires MotionKit::TreeLayout
module MotionKit
  class WindowLayout < TreeLayout

    # A more sensible name for the window that is created.
    def window
      self.view
    end

    # platform specific default root view
    def default_root
      # child WindowLayout classes can return *their* NSView subclass from self.nsview_class
      view_class = self.class.targets || NSWindow
      view_class.alloc.initWithContentRect([[0, 0], [0, 0]],
        styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask,
        backing: NSBackingStoreBuffered,
        defer: false)
    end

    def add_child(subview, options={})
      if (sibling = options[:behind])
        target.contentView.addSubview(subview, positioned: NSWindowBelow, relativeTo: sibling)
      elsif (sibling = options[:in_front_of])
        target.contentView.addSubview(subview, positioned: NSWindowAbove, relativeTo: sibling)
      elsif (z_index = options[:z_index])
        NSLog('Warning! :z_index option not supported in OS X when adding a child view')
      else
        target.contentView.addSubview(subview)
      end
    end

    def remove_child(subview)
      subview.removeFromSuperview
    end

  end

  class NSWindowHelpers < WindowLayout
    targets NSWindow
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-kit-1.1.1 lib/motion-kit-osx/helpers/nswindow_helpers.rb