Class: Vedeu::Output::Viewport Private
- Inherits:
-
Object
- Object
- Vedeu::Output::Viewport
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/output/viewport.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A Viewport is the visible part of the content within an interface.
When a buffer has more lines than the defined height, or more columns than the defined width of the interface, this class provides ‘scrolling’ via the cursor’s position.
Instance Attribute Summary collapse
- #view ⇒ Vedeu::Views::View readonly protected private
Class Method Summary collapse
Instance Method Summary collapse
-
#columns ⇒ Range
private
private
Using the current cursor’s x position, return a range of visible columns.
-
#content_offset(offset, dimension) ⇒ Fixnum
private
private
Returns the offset for the content (the number of rows or columns to change the viewport by on either the y or x axis) determined by the offset (the cursor’s y or x offset position..
- #cursor ⇒ Vedeu::Cursors::Cursor private private
-
#geometry ⇒ Object
private
private
Returns the geometry for the interface.
-
#initialize(view) ⇒ Vedeu::Output::Viewport
constructor
private
Returns a new instance of Vedeu::Output::Viewport.
- #left ⇒ Fixnum private private
- #output ⇒ Array<Array<Vedeu::Cells::Char>> private private
-
#render ⇒ Array<Array<String>>|NilClass
private
Returns the content for the view.
-
#rows ⇒ Range
private
private
Using the current cursor’s y position, return a range of visible lines.
-
#show ⇒ Array
private
private
Returns the visible content for the view.
-
#to_s ⇒ String
(also: #to_str)
private
Returns a string representation of the viewport.
- #top ⇒ Fixnum private private
Constructor Details
#initialize(view) ⇒ Vedeu::Output::Viewport
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Output::Viewport.
45 46 47 |
# File 'lib/vedeu/output/viewport.rb', line 45 def initialize(view) @view = view end |
Instance Attribute Details
#view ⇒ Vedeu::Views::View (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/vedeu/output/viewport.rb', line 68 def view @view end |
Class Method Details
.render(view) ⇒ Array<Array<String>>|NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/vedeu/output/viewport.rb', line 37 def self.render(view) new(view).render end |
Instance Method Details
#columns ⇒ Range (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The width is reduced by one as #columns is a range of Array elements.
Using the current cursor’s x position, return a range of visible columns.
Scrolls the content horizontally when the stored cursor’s x position for the interface is outside of the visible area.
83 84 85 |
# File 'lib/vedeu/output/viewport.rb', line 83 def columns left...(left + bordered_width) end |
#content_offset(offset, dimension) ⇒ Fixnum (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the offset for the content (the number of rows or columns to change the viewport by on either the y or x axis) determined by the offset (the cursor’s y or x offset position.
94 95 96 97 98 |
# File 'lib/vedeu/output/viewport.rb', line 94 def content_offset(offset, dimension) return 0 unless offset >= dimension offset - dimension end |
#cursor ⇒ Vedeu::Cursors::Cursor (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
102 103 104 |
# File 'lib/vedeu/output/viewport.rb', line 102 def cursor Vedeu.cursors.by_name(name) end |
#geometry ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the geometry for the interface.
109 110 111 |
# File 'lib/vedeu/output/viewport.rb', line 109 def geometry Vedeu.geometries.by_name(name) end |
#left ⇒ Fixnum (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/vedeu/output/viewport.rb', line 114 def left content_offset(ox, bordered_width) end |
#output ⇒ Array<Array<Vedeu::Cells::Char>> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vedeu/output/viewport.rb', line 119 def output Vedeu.timer("Rendering content: '#{name}'") do out = [] show.each_with_index do |line, iy| line.each_with_index do |column, ix| column.position = [by + iy, bx + ix] out << column end end out end end |
#render ⇒ Array<Array<String>>|NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the content for the view.
52 53 54 |
# File 'lib/vedeu/output/viewport.rb', line 52 def render Vedeu.render_output(output) if visible? end |
#rows ⇒ Range (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The height is reduced by one as #rows is a range of Array elements.
Using the current cursor’s y position, return a range of visible lines.
Scrolls the content vertically when the stored cursor’s y position for the interface is outside of the visible area.
145 146 147 |
# File 'lib/vedeu/output/viewport.rb', line 145 def rows top...(top + bordered_height) end |
#show ⇒ Array (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
If there are no lines of content, we return an empty array. If there are no more columns of content we return a space enclosed in an array; this prevents a weird line hopping bug which occurs when the current line has no more content, but subsequent lines do.
Returns the visible content for the view.
158 159 160 |
# File 'lib/vedeu/output/viewport.rb', line 158 def show (lines[rows] || []).map { |line| (line.chars[columns] || []) } end |
#to_s ⇒ String Also known as: to_str
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a string representation of the viewport.
59 60 61 |
# File 'lib/vedeu/output/viewport.rb', line 59 def to_s Array(render).map(&:to_s).join("\n") end |
#top ⇒ Fixnum (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 |
# File 'lib/vedeu/output/viewport.rb', line 163 def top content_offset(oy, bordered_height) end |