Module: Nuklear::UI::Events
- Included in:
- Base
- Defined in:
- lib/nuklear/ui/events.rb
Instance Method Summary collapse
Instance Method Details
#event_listeners_for(event) ⇒ Object
10 11 12 13 |
# File 'lib/nuklear/ui/events.rb', line 10 def event_listeners_for(event) @event_listeners ||= {} @event_listeners[event] ||= [] end |
#on(*events, &block) ⇒ Object
4 5 6 7 8 |
# File 'lib/nuklear/ui/events.rb', line 4 def on(*events, &block) events.each do |event| event_listeners_for(event) << block end end |
#trigger(event) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/nuklear/ui/events.rb', line 15 def trigger(event) if event != @last_event # prevent triggering every frame event_listeners_for(event).each { |listener| listener.call event } @last_event = event end end |