Class: PPCurses::ComboBox

Inherits:
View show all
Defined in:
lib/ppcurses/form/combo_box.rb

Constant Summary collapse

DOWN_ARROW =
'∇'

Instance Attribute Summary collapse

Attributes inherited from View

#frame

Attributes inherited from ResponderManager

#first_responder

Attributes inherited from Responder

#next_responder

Instance Method Summary collapse

Methods inherited from View

#display, #setFrameOrigin, #setFrameSize

Methods inherited from ResponderManager

#accepts_first_responder, #make_first_responder

Methods inherited from Responder

#accepts_first_responder, #become_first_responder, isa, #resign_first_responder

Constructor Details

#initialize(label, options) ⇒ ComboBox

Returns a new instance of ComboBox.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ppcurses/form/combo_box.rb', line 13

def initialize(label, options)
  @label = label
  @options = options

  @display_width = 13
  @choice_made = false

  @options.each do |option|
    if option.length > @display_width
      @display_width = option.length
    end
  end

end

Instance Attribute Details

#selectedObject

Does the element have focus in the form?



10
11
12
# File 'lib/ppcurses/form/combo_box.rb', line 10

def selected
  @selected
end

Instance Method Details

#clearObject



79
80
81
# File 'lib/ppcurses/form/combo_box.rb', line 79

def clear
  @choice_made = false
end

#heightObject



39
40
41
# File 'lib/ppcurses/form/combo_box.rb', line 39

def height
  1
end

#key_down(key) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ppcurses/form/combo_box.rb', line 58

def key_down(key)

  if key == ENTER

    if  @options_menu.nil?
      @options_menu = PPCurses::ChoiceMenu.new( @options )
    end

    @options_menu.set_origin(@combo_display_point)

    @options_menu.show
    @options_menu.menu_selection

    if @options_menu.pressed_enter
      @choice_made = true
    end

  end

end

#object_value_of_selected_itemObject

Return Value The object in the receiver’s internal item list corresponding to the last item selected from the pop-up list, or nil if no item is selected.



50
51
52
53
54
55
56
# File 'lib/ppcurses/form/combo_box.rb', line 50

def object_value_of_selected_item
  if  @options_menu.nil?
    return nil
  end

  @options[@options_menu.selection]
end

#set_curs_pos(screen) ⇒ Object



43
44
45
# File 'lib/ppcurses/form/combo_box.rb', line 43

def set_curs_pos(screen)
  screen.curs_set(INVISIBLE)
end

#show(screen) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/ppcurses/form/combo_box.rb', line 28

def show(screen)
  screen.attron(A_REVERSE) if @selected
  screen.addstr("#{@label}:")

  @combo_display_point = screen.cur_point

  screen.attroff(A_REVERSE) if @selected

  screen.addstr(display_string)
end