scanner/ncurses/ncurses.button.php
Correl Roush a3dfc6d2b8 Updated ncurses library, now event driven!
git-svn-id: file:///srv/svn/scanner/trunk@18 a0501263-5b7a-4423-a8ba-1edf086583e7
2008-04-24 18:22:08 +00:00

63 lines
1.3 KiB
PHP

<?php
/**
* Button
*
* @package Nc
*/
class NcButton extends NcWindow {
protected $label = '';
/**
* Constructor
*
* Creates a new button widget
*
* @param NcWindow $parent Parent window
* @param integer $width Width
* @param integer $y Row
* @param integer $x Column
* @param float $max Maximum value
* @param boolean $show_pct Display the percentage alongside the progress bar
*/
public function __construct( &$parent, $height, $width, $y, $x, $label = '', $frame = true) {
parent::__construct( $parent, $height, $width, $y, $x, $frame );
$this->label($label);
}
public function title($value = false) {
parent::title('');
}
public function label($value = false) {
if( $value === false ) {
return $this->label;
} else {
if( $this->active() ) {
$this->attribute_on( NCURSES_A_REVERSE );
}
$this->write_centered(floor($this->height() / 2), $value);
$this->attribute_off(NCURSES_A_REVERSE);
$this->label = $value;
}
}
public function click() {
$this->emit('clicked');
}
public function focus() {
parent::focus();
$this->label($this->label);
}
public function blur() {
parent::blur();
$this->label($this->label);
}
public function on_key_press($key) {
switch( $key ) {
case 13:
// RETURN
$this->click();
break;
default:
parent::on_key_press($key);
}
}
}
?>