class RETerm::Components::ScrollList
Scrolling List CDK Component
Attributes
items[R]
Public Class Methods
new(args={})
click to toggle source
Initialize the ScrollList
component
@param [Hash] args list params @option args [String] :title title of list @option args [Array<String>] :items items to
populate list with
Calls superclass method
RETerm::Component::new
# File lib/reterm/components/scroll_list.rb, line 16 def initialize(args={}) super @title = args[:title] || "" @items = args[:items] || [] end
Public Instance Methods
<<(item)
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 34 def <<(item) @items << item if window.expand? && (window.rows < (requested_rows + extra_padding) || window.cols < (requested_cols + extra_padding)) window.request_expansion requested_rows + extra_padding, requested_cols + extra_padding end end
activate!(*input)
click to toggle source
Calls superclass method
RETerm::CDKComponent#activate!
# File lib/reterm/components/scroll_list.rb, line 65 def activate!(*input) i = super return nil unless normal_exit? dispatch(:selected) @items[i] end
current()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 57 def current selected end
current_index()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 61 def current_index component.getCurrentItem end
empty!()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 49 def empty! @items.clear end
quit_on_enter=(v)
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 22 def quit_on_enter=(v) component.quit_on_enter = v end
requested_cols()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 30 def requested_cols [@title.size, max_item_size].max + 2 end
requested_rows()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 26 def requested_rows 2 + @items.size end
reset!()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 45 def reset! component.setCurrentItem(0) end
selected()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 53 def selected @items[component.getCurrentItem] end
Private Instance Methods
_component()
click to toggle source
# File lib/reterm/components/scroll_list.rb, line 74 def _component c = CDK::SCROLL.new(window.cdk_scr, # cdkscreen, CDK::CENTER, CDK::CENTER, # xplace, yplace, CDK::RIGHT, # scroll pos window.rows-2, # widget height window.cols-3, # widget width @title, @items, @items.size, # title and items false, # prefix numbers Ncurses::A_REVERSE, # highlight true, false) # box, shadow pp = lambda do |cdktype, list, scroll_list, key| scroll_list.dispatch(:entry, key) scroll_list.dispatch(:changed) end c.setPostProcess(pp, self) c end