Class: ScrollArea
- Inherits:
-
Object
- Object
- ScrollArea
- Defined in:
- lib/terminal-scroll-area/scroll_area.rb
Overview
Scroll area which only shows a specific area of the content it holds at a time. Able to scroll area in all directions to show a different area of the content.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#height ⇒ Object
Returns the value of attribute height.
-
#start_x ⇒ Object
readonly
Returns the value of attribute start_x.
-
#start_y ⇒ Object
readonly
Returns the value of attribute start_y.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #add_string(string) ⇒ Object
- #end_x ⇒ Object
- #end_y ⇒ Object
-
#initialize(width, height) ⇒ ScrollArea
constructor
A new instance of ScrollArea.
- #render ⇒ Object
- #scroll_down ⇒ Object
- #scroll_left ⇒ Object
- #scroll_right ⇒ Object
- #scroll_up ⇒ Object
Constructor Details
#initialize(width, height) ⇒ ScrollArea
Returns a new instance of ScrollArea.
10 11 12 13 14 15 16 17 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 10 def initialize(width, height) @width = width @height = height @start_x = 0 @start_y = 0 @content = '' update_content_dimensions end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 7 def content @content end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 8 def height @height end |
#start_x ⇒ Object (readonly)
Returns the value of attribute start_x.
7 8 9 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 7 def start_x @start_x end |
#start_y ⇒ Object (readonly)
Returns the value of attribute start_y.
7 8 9 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 7 def start_y @start_y end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 8 def width @width end |
Instance Method Details
#add_line(line) ⇒ Object
32 33 34 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 32 def add_line(line) self.content += "#{line}\n" end |
#add_string(string) ⇒ Object
28 29 30 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 28 def add_string(string) self.content += string end |
#end_x ⇒ Object
60 61 62 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 60 def end_x @start_x + (@width - 1) end |
#end_y ⇒ Object
64 65 66 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 64 def end_y @start_y + (@height - 1) end |
#render ⇒ Object
19 20 21 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 19 def render crop_text(@content, @start_x, @start_y, end_x, end_y) end |
#scroll_down ⇒ Object
42 43 44 45 46 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 42 def scroll_down return if @line_count < @height @start_y += 1 if end_y < (@line_count - 1) end |
#scroll_left ⇒ Object
48 49 50 51 52 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 48 def scroll_left return if @col_count < @width @start_x -= 1 if @start_x >= 1 end |
#scroll_right ⇒ Object
54 55 56 57 58 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 54 def scroll_right return if @col_count < @width @start_x += 1 if end_x < (@col_count - 1) end |
#scroll_up ⇒ Object
36 37 38 39 40 |
# File 'lib/terminal-scroll-area/scroll_area.rb', line 36 def scroll_up return if @line_count < @height @start_y -= 1 if @start_y.positive? end |