Class: TuiTui::List
- Inherits:
-
Object
- Object
- TuiTui::List
- Defined in:
- lib/tui_tui/list.rb
Overview
Drawing companion for ScrollList. Row content comes from the caller, keeping the list domain-agnostic.
Instance Method Summary collapse
- #draw(canvas, rect, highlight: nil, scrollbar: nil) ⇒ Object
-
#initialize(scroll) ⇒ List
constructor
A new instance of List.
Constructor Details
#initialize(scroll) ⇒ List
Returns a new instance of List.
11 12 13 |
# File 'lib/tui_tui/list.rb', line 11 def initialize(scroll) @scroll = scroll end |
Instance Method Details
#draw(canvas, rect, highlight: nil, scrollbar: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tui_tui/list.rb', line 15 def draw(canvas, rect, highlight: nil, scrollbar: nil) body, gutter = ? rect.split_gutter : [rect, nil] @scroll.ensure_visible(body.rows) @scroll.each_visible(body.rows) do |index, offset| row = body.row + offset selected = index == @scroll.cursor canvas.fill(Rect.new(row: row, col: body.col, rows: 1, cols: body.cols), highlight) if highlight && selected canvas.line(row, body.col, as_line(yield(index, selected)).truncate(body.cols)) end (canvas, gutter, ) if gutter canvas end |