Module | Apotomo::EventMethods::ClassMethods |
In: |
lib/apotomo/widget/event_methods.rb
|
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) update end
Calls squeak when a :squeak event is encountered.
Any option except the event type is optional.
responds_to_event :squeak, :with => :chirp
will invoke the +chirp+ state method.
responds_to_event :squeak, :on => :cat
will invoke the +squeak+ state on the +:cat+ widget.
responds_to_event :squeak, :from => :kid
will invoke the +squeak+ state if +:kid+ triggered and if +:kid+ is a decendent of the current widget.
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.