Class: PPCurses::RadioMenu
- Defined in:
- lib/ppcurses/menu/RadioMenu.rb
Overview
noinspection RubyResolve
Instance Attribute Summary
Attributes inherited from BaseMenu
#menu_items, #selection, #side_wall_char, #top_bot_wall_char
Instance Method Summary collapse
- #handle_menu_selection(c) ⇒ Object
-
#initialize(menu_items, action_items) ⇒ RadioMenu
constructor
TODO - duplicate code from Menu …
- #menu_selection ⇒ Object
- #selected_menu_name ⇒ Object
- #show ⇒ Object
Methods inherited from BaseMenu
#build_menu_items, #close, #create_window, #find_max_menu_width, #hide, #set_sub_menu
Constructor Details
#initialize(menu_items, action_items) ⇒ RadioMenu
TODO - duplicate code from Menu …
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 |
# File 'lib/ppcurses/menu/RadioMenu.rb', line 9 def initialize( , action_items ) @items = Array.new @actions = Array.new = 0 .each do |item| @items.push item += item.length + 5 end @selection = 0 unless action_items.nil? action_items.each do |item| @actions.push item end end w_width = + 4 @win = Window.new(3, w_width ,0, (cols - w_width) / 2) @win.timeout=-1 # Enables reading arrow keys in getch @win.keypad(true) end |
Instance Method Details
#handle_menu_selection(c) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ppcurses/menu/RadioMenu.rb', line 73 def (c) n_choices = @items.length if c == KEY_RIGHT if @selection < n_choices - 1 then @selection += 1 else @selection = 0 end self.show end if c == KEY_LEFT if @selection > 0 then @selection -= 1 else @selection = n_choices-1 end self.show end if c == ENTER then unless @actions.nil? @actions[@selection].execute self.show end end end |
#menu_selection ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ppcurses/menu/RadioMenu.rb', line 55 def while 1 c = @win.getch self.(c) if c == ESCAPE @win.clear @win.refresh break end end end |
#selected_menu_name ⇒ Object
95 96 97 |
# File 'lib/ppcurses/menu/RadioMenu.rb', line 95 def @items[@selection] end |
#show ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ppcurses/menu/RadioMenu.rb', line 38 def show @win.box('|', '-') y = 1 x = 2 @win.setpos(y, x) for i in 0...@items.length @win.addstr( @items[i] ) if @selection == i then @win.addstr(' [*] ') else @win.addstr(' [ ] ') end end @win.refresh end |