Class: PPCurses::Button

Inherits:
View show all
Defined in:
lib/ppcurses/form/button.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) ⇒ Button

Returns a new instance of Button.



11
12
13
14
15
# File 'lib/ppcurses/form/button.rb', line 11

def initialize(label)
  @label = label
  @selected = false
  @pushed = false
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



9
10
11
# File 'lib/ppcurses/form/button.rb', line 9

def action
  @action
end

#labelObject

Returns the value of attribute label.



5
6
7
# File 'lib/ppcurses/form/button.rb', line 5

def label
  @label
end

#pushedObject

Returns the value of attribute pushed.



7
8
9
# File 'lib/ppcurses/form/button.rb', line 7

def pushed
  @pushed
end

#selectedObject

Returns the value of attribute selected.



6
7
8
# File 'lib/ppcurses/form/button.rb', line 6

def selected
  @selected
end

Instance Method Details

#clearObject



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

def clear
 # NOP
end

#heightObject



30
31
32
# File 'lib/ppcurses/form/button.rb', line 30

def height
  1
end

#key_down(key) ⇒ Object



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

def key_down( key )

  if key == ENTER
    @action.call unless action.nil?
  end

end

#set_curs_pos(screen) ⇒ Object



34
35
36
# File 'lib/ppcurses/form/button.rb', line 34

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

#show(screen) ⇒ Object

Screen should be of type Curses::Window



20
21
22
23
24
# File 'lib/ppcurses/form/button.rb', line 20

def show(screen)
  screen.attron(Curses::A_REVERSE) if @selected
  screen.addstr("< #{@label} >")
  screen.attroff(Curses::A_REVERSE) if @selected
end

#widthObject



26
27
28
# File 'lib/ppcurses/form/button.rb', line 26

def width
  @label.length + 4
end