Class: MotionKit::WindowLayout

Inherits:
TreeLayout show all
Defined in:
lib/motion-kit-osx/layouts/nswindow_layout.rb

Direct Known Subclasses

NSWindowLayout

Instance Attribute Summary

Attributes inherited from BaseLayout

#parent

Instance Method Summary collapse

Methods inherited from TreeLayout

#_root, #add, #build, #built?, #call_style_method, #create, #create_default_root_context, #first, #initial, #initial?, #nth, #reapply, #reapply?, #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, #objc_version, #retina?, #ruby_version, #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

#add_child(subview) ⇒ Object



22
23
24
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 22

def add_child(subview)
  target.contentView.addSubview(subview)
end

#all(element_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 59

def all(element_id)
  if self._root == self.window
    found = self.all(element_id, in: self.window.contentView)
    if self.window.motion_kit_id == element_id
      found << self.window
    end
    return found
  else
    super
  end
end

#default_root ⇒ Object

platform specific default root view



13
14
15
16
17
18
19
20
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 13

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

#get(element_id) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 39

def get(element_id)
  if self.window.motion_kit_id == element_id
    return self.window
  elsif self._root == self.window
    self.get(element_id, in: self.window.contentView)
  else
    super
  end
end

#last(element_id) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 49

def last(element_id)
  if self._root == self.window && last = self.last(element_id, in: self.window.contentView)
    last
  elsif self.window.motion_kit_id == element_id
    self.window
  else
    super
  end
end

#reapply!(window = nil) ⇒ Object

NSWindow doesn't have immediate children; restyle its contentView.



31
32
33
34
35
36
37
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 31

def reapply!(window=nil)
  window ||= self.window
  call_style_method(window, window.motion_kit_id) if window.motion_kit_id
  context(window) do
    super(window.contentView)
  end
end

#remove(element_id) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 71

def remove(element_id)
  if self._root == self.window
    self.remove(element_id, from: self.window.contentView)
  else
    super
  end
end

#remove_child(subview) ⇒ Object



26
27
28
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 26

def remove_child(subview)
  subview.removeFromSuperview
end

#window ⇒ Object

A more sensible name for the window that is created.



8
9
10
# File 'lib/motion-kit-osx/layouts/nswindow_layout.rb', line 8

def window
  self.view
end