Class: RubyTUI::Widgets::Scrollbar
- Inherits:
-
Object
- Object
- RubyTUI::Widgets::Scrollbar
- Includes:
- RubyTUI::Widget
- Defined in:
- lib/rubytui/widgets/scrollbar.rb
Overview
Scrollbar renders a vertical or horizontal scroll indicator.
Constant Summary collapse
- VERTICAL =
Vertical orientation, drawn in the first column of the area.
:vertical- HORIZONTAL =
Horizontal orientation, drawn in the first row of the area.
:horizontal- TRACK_V =
Vertical track.
"\u2502"- THUMB_V =
Vertical thumb.
"\u2588"- TRACK_H =
Horizontal track.
"\u2500"- THUMB_H =
Horizontal thumb.
"\u2588"- ARROW_UP =
Up arrow.
"\u25B2"- ARROW_DOWN =
Down arrow.
"\u25BC"- ARROW_LEFT =
Left arrow.
"\u25C0"- ARROW_RIGHT =
Right arrow.
"\u25B6"
Instance Method Summary collapse
-
#initialize(content_length:, position: 0, viewport_length: nil, orientation: VERTICAL, style: Style::DEFAULT, thumb_style: nil, track_style: nil, show_arrows: true) ⇒ Scrollbar
constructor
A new instance of Scrollbar.
-
#render(area, buf) ⇒ void
Draw the track, thumb and optional arrows along the first column (vertical) or first row (horizontal) of the area.
Constructor Details
#initialize(content_length:, position: 0, viewport_length: nil, orientation: VERTICAL, style: Style::DEFAULT, thumb_style: nil, track_style: nil, show_arrows: true) ⇒ Scrollbar
Returns a new instance of Scrollbar.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubytui/widgets/scrollbar.rb', line 48 def initialize( content_length:, position: 0, viewport_length: nil, orientation: VERTICAL, style: Style::DEFAULT, thumb_style: nil, track_style: nil, show_arrows: true ) @content_length = [content_length, 1].max @position = position = @orientation = orientation @style = style @thumb_style = thumb_style || Style.new.fg(Color::WHITE) @track_style = track_style || Style.new.fg(Color::BRIGHT_BLACK) @show_arrows = show_arrows end |
Instance Method Details
#render(area, buf) ⇒ void
This method returns an undefined value.
Draw the track, thumb and optional arrows along the first column (vertical) or first row (horizontal) of the area.
The thumb fills the whole track when the content fits in the viewport. Nothing is drawn if no track cells remain after the arrows.
77 78 79 80 81 82 83 84 85 |
# File 'lib/rubytui/widgets/scrollbar.rb', line 77 def render(area, buf) return if area.empty? if @orientation == VERTICAL render_vertical(area, buf) else render_horizontal(area, buf) end end |