Class: Termplot::Renderer

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/termplot/renderer.rb

Instance Method Summary collapse

Methods included from Renderable

#debug?, #render, #render_to_string

Constructor Details

#initialize(cols: 80, rows: 20, debug: false, widgets:) ⇒ Renderer

Returns a new instance of Renderer.



12
13
14
15
16
17
# File 'lib/termplot/renderer.rb', line 12

def initialize(cols: 80, rows: 20, debug: false, widgets:)
  @window = Window.new(cols: cols, rows: rows)
  @widgets = widgets
  @debug = debug
  @errors = []
end

Instance Method Details

#render_to_windowObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/termplot/renderer.rb', line 19

def render_to_window
  window.clear
  errors.clear

  position = [0, 0]
  widgets.each do |widget|
    widget.render_to_window
    window.blit(
      widget.window,
      widget.row,
      widget.col
    )
    @errors.concat(widget.errors)
  end
end