| @@ 12-167 (lines=156) @@ | ||
| 9 | use FML\Types\Renderable; |
|
| 10 | use FML\Types\ScriptFeatureable; |
|
| 11 | ||
| 12 | class layoutLine implements Renderable, ScriptFeatureable |
|
| 13 | { |
|
| 14 | private $width = 0; |
|
| 15 | private $height = 0; |
|
| 16 | /** @var Control[] */ |
|
| 17 | private $elements = []; |
|
| 18 | ||
| 19 | private $margin = 2; |
|
| 20 | /** |
|
| 21 | * @var |
|
| 22 | */ |
|
| 23 | private $startX = 0; |
|
| 24 | /** |
|
| 25 | * @var |
|
| 26 | */ |
|
| 27 | private $startY = 0; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * layoutLine constructor. |
|
| 31 | * @param $startX |
|
| 32 | * @param $startY |
|
| 33 | * @param Control[] $elements |
|
| 34 | * @param $margin |
|
| 35 | * @throws \Exception |
|
| 36 | */ |
|
| 37 | public function __construct($startX, $startY, $elements = [], $margin = 0) |
|
| 38 | { |
|
| 39 | if (!is_array($elements)) { |
|
| 40 | throw new \Exception('not an array'); |
|
| 41 | } |
|
| 42 | $this->margin = $margin; |
|
| 43 | $this->elements = $elements; |
|
| 44 | $this->startX = $startX; |
|
| 45 | $this->startY = $startY; |
|
| 46 | foreach ($this->elements as $idx => $element) { |
|
| 47 | $this->width += $element->getWidth() + $this->margin; |
|
| 48 | $this->height += $element->getHeight(); |
|
| 49 | } |
|
| 50 | ||
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Render the XML element |
|
| 55 | * |
|
| 56 | * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
| 57 | * @return \DOMElement |
|
| 58 | */ |
|
| 59 | public function render(\DOMDocument $domDocument) |
|
| 60 | { |
|
| 61 | $frame = new Frame(); |
|
| 62 | $frame->setPosition($this->startX, $this->startY); |
|
| 63 | ||
| 64 | $startX = 0; |
|
| 65 | foreach ($this->elements as $idx => $element) { |
|
| 66 | $element->setX($startX); |
|
| 67 | $startX += $element->getWidth() + $this->margin; |
|
| 68 | $frame->addChild($element); |
|
| 69 | } |
|
| 70 | ||
| 71 | return $frame->render($domDocument); |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Get the Script Features |
|
| 76 | * |
|
| 77 | * @return ScriptFeature[] |
|
| 78 | */ |
|
| 79 | public function getScriptFeatures() |
|
| 80 | { |
|
| 81 | $features = []; |
|
| 82 | foreach ($this->elements as $element) { |
|
| 83 | if ($element instanceof ScriptFeatureable) { |
|
| 84 | $features[] = $element->getScriptFeatures(); |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| 88 | return ScriptFeature::collect($features); |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * @param mixed $startX |
|
| 93 | * @return layoutLine |
|
| 94 | */ |
|
| 95 | public function setX($startX) |
|
| 96 | { |
|
| 97 | $this->startX = $startX; |
|
| 98 | ||
| 99 | return $this; |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * @param mixed $startY |
|
| 104 | * @return layoutLine |
|
| 105 | */ |
|
| 106 | public function setY($startY) |
|
| 107 | { |
|
| 108 | $this->startY = $startY; |
|
| 109 | ||
| 110 | return $this; |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * @return mixed |
|
| 115 | */ |
|
| 116 | public function getX() |
|
| 117 | { |
|
| 118 | return $this->startX; |
|
| 119 | } |
|
| 120 | ||
| 121 | /** |
|
| 122 | * @return mixed |
|
| 123 | */ |
|
| 124 | public function getY() |
|
| 125 | { |
|
| 126 | return $this->startY; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @return float |
|
| 131 | */ |
|
| 132 | public function getWidth() |
|
| 133 | { |
|
| 134 | return $this->width; |
|
| 135 | } |
|
| 136 | ||
| 137 | /** |
|
| 138 | * @param float $width |
|
| 139 | */ |
|
| 140 | public function setWidth($width) |
|
| 141 | { |
|
| 142 | $this->width = $width; |
|
| 143 | } |
|
| 144 | ||
| 145 | /** |
|
| 146 | * @return float |
|
| 147 | */ |
|
| 148 | public function getHeight() |
|
| 149 | { |
|
| 150 | return $this->height; |
|
| 151 | } |
|
| 152 | ||
| 153 | /** |
|
| 154 | * @param float $height |
|
| 155 | */ |
|
| 156 | public function setHeight($height) |
|
| 157 | { |
|
| 158 | $this->height = $height; |
|
| 159 | } |
|
| 160 | ||
| 161 | public function addElement($element) |
|
| 162 | { |
|
| 163 | $this->elements[] = $element; |
|
| 164 | $this->width += $element->getWidth() + $this->margin; |
|
| 165 | $this->height += $element->getHeight(); |
|
| 166 | } |
|
| 167 | } |
|
| 168 | ||
| @@ 12-173 (lines=162) @@ | ||
| 9 | use FML\Types\Renderable; |
|
| 10 | use FML\Types\ScriptFeatureable; |
|
| 11 | ||
| 12 | class layoutRow implements Renderable, ScriptFeatureable |
|
| 13 | { |
|
| 14 | private $height = 0; |
|
| 15 | private $width = 0; |
|
| 16 | ||
| 17 | /** @var Control[] */ |
|
| 18 | private $elements = []; |
|
| 19 | ||
| 20 | private $margin = 1; |
|
| 21 | /** |
|
| 22 | * @var |
|
| 23 | */ |
|
| 24 | private $startX; |
|
| 25 | /** |
|
| 26 | * @var |
|
| 27 | */ |
|
| 28 | private $startY; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * layoutLine constructor. |
|
| 32 | * @param $startX |
|
| 33 | * @param $startY |
|
| 34 | * @param Control[] $elements |
|
| 35 | * @param int $margin |
|
| 36 | * @throws \Exception |
|
| 37 | */ |
|
| 38 | public function __construct($startX, $startY, $elements = [], $margin = 0) |
|
| 39 | { |
|
| 40 | if (!is_array($elements)) { |
|
| 41 | throw new \Exception('not an array'); |
|
| 42 | } |
|
| 43 | ||
| 44 | $this->margin = $margin; |
|
| 45 | $this->elements = $elements; |
|
| 46 | $this->startX = $startX; |
|
| 47 | $this->startY = $startY; |
|
| 48 | ||
| 49 | foreach ($this->elements as $idx => $element) { |
|
| 50 | $this->width += $element->getWidth(); |
|
| 51 | $this->height += $element->getHeight() + $this->margin; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * Render the XML element |
|
| 57 | * |
|
| 58 | * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered |
|
| 59 | * @return \DOMElement |
|
| 60 | */ |
|
| 61 | public function render(\DOMDocument $domDocument) |
|
| 62 | { |
|
| 63 | $frame = new Frame(); |
|
| 64 | $frame->setPosition($this->startX, $this->startY); |
|
| 65 | ||
| 66 | $startY = 0; |
|
| 67 | foreach ($this->elements as $idx => $element) { |
|
| 68 | $element->setY($startY); |
|
| 69 | $startY -= $element->getHeight() + $this->margin; |
|
| 70 | $frame->addChild($element); |
|
| 71 | } |
|
| 72 | ||
| 73 | return $frame->render($domDocument); |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * Get the Script Features |
|
| 78 | * |
|
| 79 | * @return ScriptFeature[] |
|
| 80 | */ |
|
| 81 | public function getScriptFeatures() |
|
| 82 | { |
|
| 83 | $features = []; |
|
| 84 | foreach ($this->elements as $element) { |
|
| 85 | if ($element instanceof ScriptFeatureable) { |
|
| 86 | $features[] = $element->getScriptFeatures(); |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||
| 90 | return ScriptFeature::collect($features); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * @param mixed $startX |
|
| 95 | * @return static |
|
| 96 | */ |
|
| 97 | public function setX($startX) |
|
| 98 | { |
|
| 99 | $this->startX = $startX; |
|
| 100 | ||
| 101 | return $this; |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * @param mixed $startY |
|
| 106 | * @return static |
|
| 107 | */ |
|
| 108 | public function setY($startY) |
|
| 109 | { |
|
| 110 | $this->startY = $startY; |
|
| 111 | ||
| 112 | return $this; |
|
| 113 | } |
|
| 114 | ||
| 115 | /** |
|
| 116 | * @return mixed |
|
| 117 | */ |
|
| 118 | public function getX() |
|
| 119 | { |
|
| 120 | return $this->startX; |
|
| 121 | } |
|
| 122 | ||
| 123 | /** |
|
| 124 | * @return mixed |
|
| 125 | */ |
|
| 126 | public function getY() |
|
| 127 | { |
|
| 128 | return $this->startY; |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * @return float |
|
| 133 | */ |
|
| 134 | public function getHeight() |
|
| 135 | { |
|
| 136 | return $this->height; |
|
| 137 | } |
|
| 138 | ||
| 139 | /** |
|
| 140 | * @param float $height |
|
| 141 | */ |
|
| 142 | public function setHeight($height) |
|
| 143 | { |
|
| 144 | $this->height = $height; |
|
| 145 | } |
|
| 146 | ||
| 147 | /** |
|
| 148 | * @param float $width |
|
| 149 | * @return layoutRow |
|
| 150 | */ |
|
| 151 | public function setWidth($width) |
|
| 152 | { |
|
| 153 | $this->width = $width; |
|
| 154 | ||
| 155 | return $this; |
|
| 156 | } |
|
| 157 | ||
| 158 | /** |
|
| 159 | * @return float|int |
|
| 160 | */ |
|
| 161 | public function getWidth() |
|
| 162 | { |
|
| 163 | return $this->width; |
|
| 164 | } |
|
| 165 | ||
| 166 | public function addElement($element) |
|
| 167 | { |
|
| 168 | $this->elements[] = $element; |
|
| 169 | $this->width += $element->getWidth(); |
|
| 170 | $this->height += $element->getHeight() + $this->margin; |
|
| 171 | } |
|
| 172 | ||
| 173 | } |
|
| 174 | ||