Method: MenuWindow#initialize

Defined in:
lib/menu_window.rb

#initialize(title, scr, items, current_index, matches = nil, options = {}) ⇒ MenuWindow

Matches are passed in when a search succeeds and certain items need to be indicated as matches TODO This should be changed into a hash parameter with keys



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/menu_window.rb', line 8

def initialize(title, scr, items, current_index, matches=nil, options={})

  @options = options
  @matches = matches
  @height = scr.maxy - 6
  @width = scr.maxx - 2
  scr.clear
  scr.setpos(2, 5)
  scr.refresh

  @title = title
  @title_box = Curses::Window.new(2, @width, 2, 5)

  # @window is the main content window
  
  @window = Curses::Window.new(@height, @width, 4, 2)

  @items = items 
  if @items.empty?
    @title_box.addstr(@title)
    @title_box.refresh
    @window.clear
    @window.addstr("   No items")
    @window.refresh
    # need to disable some commands in the controller
    return
  end
  @pager = MenuPager.new(@height, @width)
  @current_index = current_index || 0

  @window.clear if @window

  # page_content is an array of hashes with keys :item and :text
  @page_index, @page_content = create_page
  
  draw_menu(@page_content)

  draw_title

  draw_arrow
  # draw pointer at current selection
  @window.refresh
end