Class: PPCurses::ButtonPair

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

Overview

For grouping two buttons together, i.e. SUBMIT/CANCEL

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(button1_label, button2_label) ⇒ ButtonPair

Returns a new instance of ButtonPair.



64
65
66
67
68
69
70
71
# File 'lib/ppcurses/form/button.rb', line 64

def initialize(button1_label, button2_label)
  @button1 = Button.new(button1_label)
  @button2 = Button.new(button2_label)

  @selected_button = @button1

  @selected = false
end

Instance Attribute Details

#button1Object

Returns the value of attribute button1.



61
62
63
# File 'lib/ppcurses/form/button.rb', line 61

def button1
  @button1
end

#button2Object

Returns the value of attribute button2.



62
63
64
# File 'lib/ppcurses/form/button.rb', line 62

def button2
  @button2
end

#selectedObject

Returns the value of attribute selected.



58
59
60
# File 'lib/ppcurses/form/button.rb', line 58

def selected
  @selected
end

#selected_elementObject

Returns the value of attribute selected_element.



59
60
61
# File 'lib/ppcurses/form/button.rb', line 59

def selected_element
  @selected_element
end

Instance Method Details

#clearObject



120
121
122
# File 'lib/ppcurses/form/button.rb', line 120

def clear
 # NOP
end

#heightObject



78
79
80
# File 'lib/ppcurses/form/button.rb', line 78

def height
  2
end

#key_down(key) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ppcurses/form/button.rb', line 86

def key_down( key )
  if key == KEY_RIGHT or key == KEY_LEFT
    @selected_button.selected=false

    if @selected_button == @button1
      @selected_button = @button2
    else
      @selected_button = @button1
    end

    @selected_button.selected=true
    return
  end

  @selected_button.key_down(key)

end

#set_curs_pos(screen) ⇒ Object



82
83
84
# File 'lib/ppcurses/form/button.rb', line 82

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

#show(screen) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ppcurses/form/button.rb', line 104

def show(screen)

  p = screen.cur_point
  p.y+=1
  screen.set_pos_by_point(p)


  @button1.show(screen)

  p.x += @button1.width + 2
  screen.set_pos_by_point(p)

  @button2.show(screen)

end