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