Class: Nuklear::EventBuffer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeEventBuffer

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_eventsObject (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

#drainObject



13
14
15
16
# File 'lib/nuklear/event_buffer.rb', line 13

def drain
  @pending_events.each { |evt| yield(evt) }
  @pending_events.clear
end