From 61f83bd0b754626e2b042e83ef751ddfa183f5c9 Mon Sep 17 00:00:00 2001 From: Isaac Skelton Date: Sun, 15 Sep 2019 01:11:12 +1200 Subject: [PATCH] - Added input spinner class. --- src/Components/InputSpin.php | 141 +++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/Components/InputSpin.php diff --git a/src/Components/InputSpin.php b/src/Components/InputSpin.php new file mode 100644 index 0000000..206e53f --- /dev/null +++ b/src/Components/InputSpin.php @@ -0,0 +1,141 @@ +getDefaultAttributes(); + + parent::__construct($defaultAttributes, $parent, $application); + } + + /** + * Returns default attribute values. + * + * @return array + */ + public function getDefaultAttributes() + { + return [ + 'Value' => 0, + 'MinValue' => 0, + 'MaxValue' => 100, + 'Increment' => 1, + ]; + } + + /** + * Gets component value. + * + * @return int + */ + public function getValue() + { + return $this->get('Value'); + } + + /** + * Sets component value. + * + * @param int $value + * @return self + */ + public function setValue($value) + { + $this->set('Value', (int) $value); + return $this; + } + + /** + * Gets the maximal value allowed for the component. + * + * @return int + */ + public function getMaxValue() + { + return $this->get('MaxValue'); + } + + /** + * Sets the maximal value allowed for the component. + * + * @param int $value + * @return self + */ + public function setMaxValue($value) + { + $this->set('MaxValue', (int) $value); + return $this; + } + + /** + * Gets the minimal value allowed for the component. + * + * @return int + */ + public function getMinValue() + { + return $this->get('MinValue'); + } + + /** + * Sets the minimal value allowed for the component. + * + * @param int $value + * @return self + */ + public function setMinValue($value) + { + $this->set('MinValue', (int) $value); + return $this; + } + + /** + * Gets value's increment for the component. + * + * @return int + */ + public function getIncrement() + { + return $this->get('Increment'); + } + + /** + * The value by which the value of the control should be increased/decresed when + * the user clicks one of the arrows or one of the keyboard up/down arrows. + * + * @param int $value + * @return self + */ + public function setIncrement($value) + { + $this->set('Increment', max(1, (int) $value)); + return $this; + } +}