Class: Nuklear::EventBuffer
- Inherits:
-
Object
- Object
- Nuklear::EventBuffer
- Defined in:
- lib/nuklear/event_buffer.rb
Overview
Stores staged events waiting to be drained.
Constant Summary collapse
- EVENT_NAMES =
These correlate to methods defined by Nuklear::Context::EventSink.
[:motion, :key, :button, :scroll, :char, :glyph, :unicode]
Instance Attribute Summary collapse
-
#pending_events ⇒ Object
readonly
Returns the value of attribute pending_events.
Instance Method Summary collapse
- #add(event_name, *event_args) ⇒ Object
- #drain ⇒ Object
-
#initialize ⇒ EventBuffer
constructor
A new instance of EventBuffer.
Constructor Details
#initialize ⇒ EventBuffer
Returns a new instance of EventBuffer.
9 10 11 |
# File 'lib/nuklear/event_buffer.rb', line 9 def initialize @pending_events = [] end |
Instance Attribute Details
#pending_events ⇒ Object (readonly)
Returns the value of attribute pending_events.
7 8 9 |
# File 'lib/nuklear/event_buffer.rb', line 7 def pending_events @pending_events end |
Instance Method Details
#add(event_name, *event_args) ⇒ Object
18 19 20 21 |
# File 'lib/nuklear/event_buffer.rb', line 18 def add(event_name, *event_args) super unless EVENT_NAMES.include?(event_name) @pending_events << [event_name, *event_args] end |
#drain ⇒ Object
13 14 15 16 |
# File 'lib/nuklear/event_buffer.rb', line 13 def drain @pending_events.each { |evt| yield(evt) } @pending_events.clear end |