Module: Apotomo::EventMethods::ClassMethods

Defined in:

Instance Method Summary collapse

Instance Method Details

#responds_to_event(*options) ⇒ Object

Instructs the widget to look out for type events. If an appropriate event starts from or passes the widget, the defined trigger state is executed.

class MouseWidget < Apotomo::Widget
  responds_to_event :squeak

  def squeak(evt)

Calls #squeak when a :squeak event is encountered.


Any option except the event type is optional.

:with => state

executes state, defaults to type.

responds_to_event :squeak, :with => :chirp

will invoke the #chirp state method.

:on => id

execute the trigger state on another widget.

responds_to_event :squeak, :on => :cat

will invoke the #squeak state on the :cat widget.

:from => id

executes the state only if the event origins from id.

responds_to_event :squeak, :from => :kid

will invoke the #squeak state if :kid triggered and if :kid is a decendent of the current widget.

:passing => id

attaches the observer to another widget. Useful if you want to catch bubbling events in root.

responds_to_event :squeak, :passing => :root

will invoke the state on the current widget if the event passes :root (which is highly probable).


Note that the observers are inherited. This allows deriving a widget class without having to redefine the responds_to_event blocks.

# File 'lib/apotomo/widget/event_methods.rb', line 71

def responds_to_event(*options)
  responds_to_event_options << options