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



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

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

Instance Method Details

#layoutDidLoadObject



151
152
# File 'lib/teacup/teacup_controller.rb', line 151

def layoutDidLoad
end

#root(stylename = nil, properties = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/teacup/teacup_controller.rb', line 91

def root(stylename=nil, properties={})
  if stylename.is_a?(NSDictionary)
    properties = stylename
    stylename = nil
  end

  if stylename || properties
    layout(top_level_view, stylename, properties)
  else
    top_level_view
  end
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[:main]
stylesheet = :main

Returns:

  • Teacup::Stylesheet



84
85
86
87
88
89
# File 'lib/teacup/teacup_controller.rb', line 84

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).



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/teacup/teacup_controller.rb', line 108

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 = layout_definition
    layout(top_level_view, stylename, properties)
  end

  if respond_to?(:teacup_layout)
    teacup_layout
  end

  layoutDidLoad

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

  if defined?(NSLayoutConstraint)
    self.top_level_view.apply_constraints
  end
end