Module: Teacup::Controller

Included in:
NSViewController, NSWindowController, UIViewController
Defined in:
lib/teacup/teacup_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



49
50
51
# File 'lib/teacup/teacup_controller.rb', line 49

def self.included(base)
  base.extend ControllerClass
end

Instance Method Details

#layoutDidLoadObject



116
117
118
# File 'lib/teacup/teacup_controller.rb', line 116

def layoutDidLoad
  true
end

#stylesheet=(new_stylesheet) ⇒ Object

Assigning a new stylesheet triggers restyle!.

Assigning a stylesheet is an alternative to returning a Stylesheet in the stylesheet method. Note that restyle! calls stylesheet, so while assigning a stylesheet will trigger restyle!, your stylesheet will not be picked up if you don’t return it in a custom stylesheet method.

Examples:


stylesheet = Teacup::Stylesheet[:ipadhorizontal]
stylesheet = :ipadhorizontal

Returns:

  • Teacup::Stylesheet



66
67
68
69
70
71
# File 'lib/teacup/teacup_controller.rb', line 66

def stylesheet=(new_stylesheet)
  super
  if self.viewLoaded?
    self.view.restyle!
  end
end

#teacupDidLoadObject

Instantiate the layout from the class, and then call layoutDidLoad.

If you want to use Teacup in your controller, please hook into layoutDidLoad, not viewDidLoad or windowDidLoad (they call this method).



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/teacup/teacup_controller.rb', line 77

def teacupDidLoad
  # look for a layout_definition in the list of ancestors
  layout_definition = nil
  my_stylesheet = self.stylesheet
  parent_class = self.class
  while parent_class != NSObject and not (layout_definition && my_stylesheet)
    if not my_stylesheet and parent_class.respond_to?(:stylesheet)
      my_stylesheet = parent_class.stylesheet
    end

    if not layout_definition and parent_class.respond_to?(:layout_definition)
      layout_definition = parent_class.layout_definition
    end
    parent_class = parent_class.superclass
  end

  should_restyle = Teacup.should_restyle_and_block

  if my_stylesheet and not self.stylesheet
    self.stylesheet = my_stylesheet
  end

  if layout_definition
    stylename, properties, block = layout_definition
    layout(top_level_view, stylename, properties, &block)
  end

  if should_restyle
    Teacup.should_restyle!
    self.top_level_view.restyle!
  end

  if defined? NSLayoutConstraint
    self.top_level_view.apply_constraints
  end

  layoutDidLoad
end