class BBS::Widgets::ScrollView
A scrollable text buffer: an Array of lines, which may carry ANSI colour codes, with a scrollbar when they do not fit.
Attributes
- lines
-
the Array of lines shown; they may carry ANSI colour codes
- scroll
-
index of the line on the top row
- lines
-
the Array of lines shown; they may carry ANSI colour codes
- scroll
-
index of the line on the top row
Public Class Methods
Source
# File lib/bbs/widgets/scroll_view.rb, line 15 def initialize(lines: [], **kw) super(**kw) @lines = lines @scroll = 0 end
Creates a view of lines scrolled to the top.
Calls superclass method
BBS::Widget::new
Public Instance Methods
Source
# File lib/bbs/widgets/scroll_view.rb, line 22 def focusable? = true
True: a scroll view takes the focus.
Source
# File lib/bbs/widgets/scroll_view.rb, line 36 def handle_event(event) if event.mouse? return nil unless event.mouse.kind == :wheel return scroll_to(@scroll + (event.mouse.button == :up ? -WHEEL_STEP : WHEEL_STEP)) end target = event.key? && target_of(event.key) target ? scroll_to(target) : nil end
Scrolls with Up, Down, Page Up, Page Down, Home and End, and by three lines on the mouse wheel. Returns :handled, or nil for other events.
Source
# File lib/bbs/widgets/scroll_view.rb, line 27 def render(frame) return if no_room? bounds.height.times { |r| draw_row(frame, r) } draw_scrollbar(frame) if @lines.size > bounds.height && bounds.width > 1 end
Draws the visible lines into the bounds of frame, each cut to the width, and a scrollbar in the rightmost column when the lines do not fit.