1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SKien\Formgenerator; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Canvas element. |
8
|
|
|
* All attributes and styles except height and width (set with the constructor) |
9
|
|
|
* can be set through the methods <ul> |
10
|
|
|
* <li> addAttribute() </li> |
11
|
|
|
* <li> addStyle() </li></ul> |
12
|
|
|
* |
13
|
|
|
* @package Formgenerator |
14
|
|
|
* @author Stefanius <[email protected]> |
15
|
|
|
* @copyright MIT License - see the LICENSE file for details |
16
|
|
|
*/ |
17
|
|
|
class FormCanvas extends FormInput |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Create o canvas element. |
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
|
|
|
* @internall |
39
|
|
|
*/ |
40
|
|
|
static public function fromXML(\DOMElement $oXMLElement, FormCollection $oFormParent) : ?FormElement |
41
|
|
|
{ |
42
|
|
|
// id comes from FormElement::readAdditionalXML() !! |
43
|
|
|
$iWidth = self::getAttribInt($oXMLElement, 'width', 100); |
44
|
|
|
$iHeight = self::getAttribInt($oXMLElement, 'height', 100); |
45
|
|
|
$oFormElement = new self('', $iWidth, $iHeight); |
46
|
|
|
$oFormParent->add($oFormElement); |
47
|
|
|
$oFormElement->readAdditionalXML($oXMLElement); |
48
|
|
|
return $oFormElement; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Build the HTML-notation for the cancas element. |
53
|
|
|
* @return string |
54
|
|
|
* @internal |
55
|
|
|
*/ |
56
|
|
|
public function getHTML() : string |
57
|
|
|
{ |
58
|
|
|
$strHTML = $this->buildContainerDiv(); |
59
|
|
|
|
60
|
|
|
$strHTML .= ' <canvas id="' . $this->strID . '"'; |
61
|
|
|
$strHTML .= $this->buildStyle(); |
62
|
|
|
$strHTML .= $this->buildAttributes(); |
63
|
|
|
$strHTML .= '></canvas>' . PHP_EOL; |
64
|
|
|
$strHTML .= '</div>' . PHP_EOL; |
65
|
|
|
|
66
|
|
|
return $strHTML; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|