Class: Tuile::VerticalScrollBar
- Inherits:
-
Object
- Object
- Tuile::VerticalScrollBar
- Defined in:
- lib/tuile/vertical_scroll_bar.rb
Overview
A vertical scrollbar that computes which character to draw at each row.
Uses ‘█` for the handle (filled track) and `░` for the empty track. There are no up/down arrows; the full height is used as the track. Handle geometry is precomputed in the constructor as #handle_height, #handle_start, and #handle_end.
Instance Attribute Summary collapse
-
#handle_end ⇒ Integer
readonly
0-based row where the handle ends (height >= 1 only).
-
#handle_height ⇒ Integer
readonly
Number of track rows the handle occupies (height >= 1 only).
-
#handle_start ⇒ Integer
readonly
0-based row where the handle starts (height >= 1 only).
Instance Method Summary collapse
-
#initialize(height, line_count:, top_line:) ⇒ VerticalScrollBar
constructor
A new instance of VerticalScrollBar.
-
#scrollbar_char(row_in_viewport) ⇒ String
Returns the scrollbar character for the given viewport row.
Constructor Details
#initialize(height, line_count:, top_line:) ⇒ VerticalScrollBar
Returns a new instance of VerticalScrollBar.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tuile/vertical_scroll_bar.rb', line 23 def initialize(height, line_count:, top_line:) @height = height return unless height >= 1 if line_count <= height @handle_height = height @handle_start = 0 @handle_end = height - 1 else @handle_height = [(height * height / line_count.to_f).ceil, 1].max @handle_start = (height * top_line / line_count.to_f).floor @handle_end = @handle_start + @handle_height - 1 end end |
Instance Attribute Details
#handle_end ⇒ Integer (readonly)
Returns 0-based row where the handle ends (height >= 1 only).
17 18 19 |
# File 'lib/tuile/vertical_scroll_bar.rb', line 17 def handle_end @handle_end end |
#handle_height ⇒ Integer (readonly)
Returns number of track rows the handle occupies (height >= 1 only).
13 14 15 |
# File 'lib/tuile/vertical_scroll_bar.rb', line 13 def handle_height @handle_height end |
#handle_start ⇒ Integer (readonly)
Returns 0-based row where the handle starts (height >= 1 only).
15 16 17 |
# File 'lib/tuile/vertical_scroll_bar.rb', line 15 def handle_start @handle_start end |
Instance Method Details
#scrollbar_char(row_in_viewport) ⇒ String
Returns the scrollbar character for the given viewport row.
42 43 44 |
# File 'lib/tuile/vertical_scroll_bar.rb', line 42 def () >= @handle_start && <= @handle_end ? "█" : "░" end |