Class: PPCurses::RadioButtonGroup

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

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) ⇒ RadioButtonGroup

label : a label for the radio button group options: an array of strings



17
18
19
20
21
22
# File 'lib/ppcurses/form/radio_button_group.rb', line 17

def initialize( label, options )

  @label = label
  @options = options
  @current_option = 0
end

Instance Attribute Details

#current_optionObject

Returns the value of attribute current_option.



11
12
13
# File 'lib/ppcurses/form/radio_button_group.rb', line 11

def current_option
  @current_option
end

#selectedObject

Returns the value of attribute selected.



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

def selected
  @selected
end

Instance Method Details

#clearObject



54
55
56
# File 'lib/ppcurses/form/radio_button_group.rb', line 54

def clear
 @current_option = 0
end

#heightObject



50
51
52
# File 'lib/ppcurses/form/radio_button_group.rb', line 50

def height
  1
end

#key_down(key) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/ppcurses/form/radio_button_group.rb', line 38

def key_down( key )
  if key == KEY_LEFT then @current_option = @current_option-1 end
  if key == KEY_RIGHT then @current_option = @current_option+1 end

  if @current_option < 0 then @current_option = @options.length-1 end
  if @current_option > @options.length-1 then @current_option = 0 end
end

#set_curs_pos(screen) ⇒ Object



46
47
48
# File 'lib/ppcurses/form/radio_button_group.rb', line 46

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

#show(screen) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ppcurses/form/radio_button_group.rb', line 24

def show(screen)
  screen.attron(Curses::A_REVERSE) if @selected
  screen.addstr(" #{@label}:")
  screen.attroff(Curses::A_REVERSE) if @selected
  @options.each_with_index  do |option, index|
    if index == @current_option
      screen.addstr(" #{option} #{RADIO_SELECTED}  ")
    else
      screen.addstr(" #{option} #{RADIO_NOT_SELECTED}  ")
    end
  end
end