Class: Luck::Button

Inherits:
Label show all
Defined in:
lib/luck/button.rb

Instance Attribute Summary collapse

Attributes inherited from Label

#alignment

Attributes inherited from Control

#display, #pane, #x1, #x2, #y1, #y2

Instance Method Summary collapse

Methods inherited from Label

#align, #align_text, #initialize

Methods inherited from Control

#focus!, #height, #initialize, #width

Constructor Details

This class inherits a constructor from Luck::Label

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



3
4
5
# File 'lib/luck/button.rb', line 3

def handler
  @handler
end

Instance Method Details

#handle_char(char) ⇒ Object



9
10
11
12
13
14
# File 'lib/luck/button.rb', line 9

def handle_char char
  if char == "\n"
    handler.call self, @text if handler
  end
  #redraw
end

#handle_click(button, modifiers, x, y) ⇒ Object



16
17
18
# File 'lib/luck/button.rb', line 16

def handle_click button, modifiers, x, y
  handler.call self, @text if button == :left && handler
end

#on_submit(&blck) ⇒ Object



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

def on_submit &blck
  @handler = blck
end

#redrawObject



28
29
30
31
32
33
# File 'lib/luck/button.rb', line 28

def redraw
  @display.driver.cursor = false
  print @display.color(@display.active_control == self ? '1;34' : '0;36')
  super
  print @display.color('0')
end

#textObject



20
21
22
# File 'lib/luck/button.rb', line 20

def text
  "[ #{@text} ]"
end