64 lines
1.3 KiB
PHP
64 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|