Class: Rvim::CompletionPopup
- Inherits:
-
Object
- Object
- Rvim::CompletionPopup
- Defined in:
- lib/rvim/completion_popup.rb
Constant Summary collapse
- DEFAULT_MAX_HEIGHT =
8- DEFAULT_MAX_WIDTH =
30
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#max_height ⇒ Object
Returns the value of attribute max_height.
-
#max_width ⇒ Object
Returns the value of attribute max_width.
-
#pointer ⇒ Object
Returns the value of attribute pointer.
-
#scroll_top ⇒ Object
readonly
Returns the value of attribute scroll_top.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(contents:, pointer: 0, max_height: DEFAULT_MAX_HEIGHT, max_width: DEFAULT_MAX_WIDTH) ⇒ CompletionPopup
constructor
A new instance of CompletionPopup.
- #needs_scrollbar? ⇒ Boolean
- #size ⇒ Object
- #visible_height ⇒ Object
- #visible_range ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(contents:, pointer: 0, max_height: DEFAULT_MAX_HEIGHT, max_width: DEFAULT_MAX_WIDTH) ⇒ CompletionPopup
Returns a new instance of CompletionPopup.
11 12 13 14 15 16 17 |
# File 'lib/rvim/completion_popup.rb', line 11 def initialize(contents:, pointer: 0, max_height: DEFAULT_MAX_HEIGHT, max_width: DEFAULT_MAX_WIDTH) @contents = contents @max_height = max_height @max_width = max_width @scroll_top = 0 self.pointer = pointer end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
8 9 10 |
# File 'lib/rvim/completion_popup.rb', line 8 def contents @contents end |
#max_height ⇒ Object
Returns the value of attribute max_height.
8 9 10 |
# File 'lib/rvim/completion_popup.rb', line 8 def max_height @max_height end |
#max_width ⇒ Object
Returns the value of attribute max_width.
8 9 10 |
# File 'lib/rvim/completion_popup.rb', line 8 def max_width @max_width end |
#pointer ⇒ Object
Returns the value of attribute pointer.
9 10 11 |
# File 'lib/rvim/completion_popup.rb', line 9 def pointer @pointer end |
#scroll_top ⇒ Object (readonly)
Returns the value of attribute scroll_top.
9 10 11 |
# File 'lib/rvim/completion_popup.rb', line 9 def scroll_top @scroll_top end |
Instance Method Details
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/rvim/completion_popup.rb', line 41 def empty? @contents.empty? end |
#needs_scrollbar? ⇒ Boolean
49 50 51 |
# File 'lib/rvim/completion_popup.rb', line 49 def @contents.size > visible_height end |
#size ⇒ Object
45 46 47 |
# File 'lib/rvim/completion_popup.rb', line 45 def size @contents.size end |
#visible_height ⇒ Object
24 25 26 |
# File 'lib/rvim/completion_popup.rb', line 24 def visible_height [@contents.size, @max_height].min end |
#visible_range ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rvim/completion_popup.rb', line 28 def visible_range return (0...0) if @contents.empty? bottom = [@scroll_top + visible_height, @contents.size].min @scroll_top...bottom end |
#width ⇒ Object
35 36 37 38 39 |
# File 'lib/rvim/completion_popup.rb', line 35 def width return 0 if @contents.empty? [@contents.map(&:length).max, @max_width].min end |