Class: PPCurses::ComboBox
- Inherits:
-
View
- Object
- Responder
- ResponderManager
- View
- PPCurses::ComboBox
- Defined in:
- lib/ppcurses/form/combo_box.rb
Constant Summary collapse
- DOWN_ARROW =
'∇'
Instance Attribute Summary collapse
-
#selected ⇒ Object
Does the element have focus in the form?.
Attributes inherited from View
Attributes inherited from ResponderManager
Attributes inherited from Responder
Instance Method Summary collapse
- #clear ⇒ Object
- #height ⇒ Object
-
#initialize(label, options) ⇒ ComboBox
constructor
A new instance of ComboBox.
- #key_down(key) ⇒ Object
-
#object_value_of_selected_item ⇒ Object
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.
- #set_curs_pos(screen) ⇒ Object
- #show(screen) ⇒ Object
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, ) @label = label = @display_width = 13 @choice_made = false .each do |option| if option.length > @display_width @display_width = option.length end end end |
Instance Attribute Details
#selected ⇒ Object
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
#clear ⇒ Object
79 80 81 |
# File 'lib/ppcurses/form/combo_box.rb', line 79 def clear @choice_made = false end |
#height ⇒ Object
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 .nil? = PPCurses::ChoiceMenu.new( ) end .set_origin(@combo_display_point) .show . if .pressed_enter @choice_made = true end end end |
#object_value_of_selected_item ⇒ Object
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 .nil? return nil end [.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 |