Class: Rain::Matrix
- Inherits:
-
Object
- Object
- Rain::Matrix
- Includes:
- LowType, Observers
- Defined in:
- lib/matrix/matrix.rb
Instance Method Summary collapse
-
#initialize(event_pool:, config: ConfigLoader.load('./config/matrix.yaml')) ⇒ Matrix
constructor
A new instance of Matrix.
-
#new_event_tree(event: Low::Events::EventTree) ⇒ Object
TODO: Introduce “on :new_event_tree do |event|” block construct in LowEvent for making event handlers more obvious.
- #redraw(screen_size:) ⇒ Object
- #render(screen_size:, show_output: true) ⇒ Object
Constructor Details
#initialize(event_pool:, config: ConfigLoader.load('./config/matrix.yaml')) ⇒ Matrix
Returns a new instance of Matrix.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/matrix/matrix.rb', line 16 def initialize(event_pool:, config: ConfigLoader.load('./config/matrix.yaml')) @event_pool = event_pool @config = config @screen_size = nil @last_stream_index = -1 @streams = {} # TODO: Could be a "stream pool" like event pool (a pool hash). @columns = [] end |
Instance Method Details
#new_event_tree(event: Low::Events::EventTree) ⇒ Object
TODO: Introduce “on :new_event_tree do |event|” block construct in LowEvent for making event handlers more obvious. TODO: Observers should allow arbitrary params when triggering and observing.
46 47 48 49 |
# File 'lib/matrix/matrix.rb', line 46 def new_event_tree(event: Low::Events::EventTree) stream = upsert_stream(event_tree: event) stream.redraw(cell_count: @screen_size[:row_count]) end |
#redraw(screen_size:) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/matrix/matrix.rb', line 27 def redraw(screen_size:) @setup ||= setup @streams.each_value do |stream| stream.redraw(cell_count: screen_size[:row_count]) end end |
#render(screen_size:, show_output: true) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/matrix/matrix.rb', line 35 def render(screen_size:, show_output: true) if screen_size != @screen_size @screen_size = screen_size redraw(screen_size:) end render_streams(show_output:) end |