1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Formgenerator; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Canvas element. |
8
|
|
|
* |
9
|
|
|
* @package Formgenerator |
10
|
|
|
* @author Stefanius <[email protected]> |
11
|
|
|
* @copyright MIT License - see the LICENSE file for details |
12
|
|
|
*/ |
13
|
|
|
class FormCanvas extends FormInput |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create o canvas element. |
17
|
|
|
* All attributes and styles can except height and width can be set through |
18
|
|
|
* the methods <ul> |
19
|
|
|
* <li> addAttribute() </li> |
20
|
|
|
* <li> addStyle() </li></ul> |
21
|
|
|
* @param string $strID |
22
|
|
|
* @param int $iWidth |
23
|
|
|
* @param int $iHeight |
24
|
|
|
*/ |
25
|
|
|
public function __construct(string $strID, int $iWidth, int $iHeight) |
26
|
|
|
{ |
27
|
|
|
$this->oFlags = new FormFlags(); |
28
|
|
|
$this->strID = $strID; |
29
|
|
|
|
30
|
|
|
// Note: set attributes for width and height-styles will change internal behaviour of canvas |
31
|
|
|
$this->addAttribute('height', (string)$iHeight); |
32
|
|
|
$this->addAttribute('width', (string)$iWidth); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritDoc} |
37
|
|
|
* @see \SKien\Formgenerator\FormElement::fromXML() |
38
|
|
|
*/ |
39
|
|
|
static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement |
40
|
|
|
{ |
41
|
|
|
$strId = self::getAttribString($oXMLElement, 'id', ''); |
42
|
|
|
$iWidth = self::getAttribInt($oXMLElement, 'width', 100); |
43
|
|
|
$iHeight = self::getAttribInt($oXMLElement, 'height', 100); |
44
|
|
|
$oFormElement = new self($strId, $iWidth, $iHeight); |
45
|
|
|
$oFormParent->add($oFormElement); |
46
|
|
|
$oFormElement->readAdditionalXML($oXMLElement); |
47
|
|
|
return $oFormElement; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* build the HTML-notation for the cancas element |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getHTML() : string |
56
|
|
|
{ |
57
|
|
|
$strHTML = $this->buildContainerDiv(); |
58
|
|
|
|
59
|
|
|
$strHTML .= ' <canvas id="' . $this->strID . '"'; |
60
|
|
|
$strHTML .= $this->buildStyle(); |
61
|
|
|
$strHTML .= $this->buildAttributes(); |
62
|
|
|
$strHTML .= '></canvas>' . PHP_EOL; |
63
|
|
|
$strHTML .= '</div>' . PHP_EOL; |
64
|
|
|
|
65
|
|
|
return $strHTML; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|