Completed
Push — master ( 3582ec...074093 )
by De Cramer
10s
created

MenuTabItem   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 4
dl 0
loc 193
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A render() 0 20 2
A prepare() 0 4 1
A getActive() 0 4 1
A setActive() 0 6 1
A addChild() 0 5 1
A add() 0 4 1
A addChildren() 0 4 1
A removeAllChildren() 0 4 1
A removeChildren() 0 4 1
A getFormat() 0 4 1
A setFormat() 0 4 1
A getChildren() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: php_r
5
 * Date: 15.4.2018
6
 * Time: 19.49
7
 */
8
9
namespace eXpansion\Bundle\Menu\Gui\Elements;
10
11
12
use eXpansion\Framework\Gui\Components\AbstractUiElement;
13
use eXpansion\Framework\Gui\Components\Label;
14
use FML\Controls\Frame;
15
use FML\Controls\Quad;
16
use FML\Elements\Format;
17
use FML\Script\Script;
18
use FML\Types\Container;
19
use FML\Types\Renderable;
20
21
class MenuTabItem extends AbstractUiElement implements Container
22
{
23
24
    /** @var string */
25
    private $text;
26
    /**
27
     * @var bool
28
     */
29
    private $active = false;
30
    private $action;
31
    protected $translate = true;
32
    private $label;
33
34
    public function __construct($text, $action)
35
    {
36
37
        $this->text = $text;
38
        $this->action = $action;
39
        $this->label  = new Label($this->text, Label::TYPE_HEADER);
40
        $this->label->setPosition(0, 0);
41
        $this->label->setSize(24, 5);
42
        $this->label->setAction($this->action);
43
        $this->label->setTextSize(3);
44
        $this->label->setTextColor('FFFFFF');
45
        $this->label->setAreaColor("0000");
46
47
        $this->label->setAlign("center", "center2");
48
        $this->label->setTextId($this->text);
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->setHorizontalAlign("center");
63
        $frame->setPosition($this->posX, $this->posY);
64
65
66
        $frame->addChild($this->label);
67
68
        if ($this->active) {
69
            $quad = Quad::create();
70
            $quad->setSize(24, 0.33);
71
            $quad->setBackgroundColor("fff");
72
            $quad->setAlign("center", "center2");
73
            $quad->setPosition(0, -3);
74
            $frame->addChild($quad);
75
        }
76
77
        return $frame->render($domDocument);
78
    }
79
80
    /**
81
     * Prepare the given Script for rendering by adding the needed Labels, etc.
82
     *
83
     * @param Script $script Script to prepare
84
     * @return static
85
     */
86
    public function prepare(Script $script)
87
    {
88
        return $this;
89
    }
90
91
    /**
92
     * @return bool
93
     */
94
    public function getActive()
95
    {
96
        return $this->active;
97
    }
98
99
    /**
100
     * @param bool $active
101
     * @return MenuTabItem
102
     */
103
    public function setActive(bool $active = true)
104
    {
105
        $this->active = $active;
106
107
        return $this;
108
    }
109
110
111
    /**
112
     * Add a new child
113
     *
114
     * @api
115
     * @param Renderable $child Child Control to add
116
     * @return static
117
     */
118
    public function addChild(Renderable $child)
119
    {
120
121
        return $this;
122
    }
123
124
    /**
125
     * Add a new child
126
     *
127
     * @api
128
     * @param Renderable $child Child Control to add
129
     * @return static
130
     * @deprecated Use addChild()
131
     * @see        Container::addChild()
132
     */
133
    public function add(Renderable $child)
134
    {
135
        return $this;
136
    }
137
138
    /**
139
     * Add new children
140
     *
141
     * @api
142
     * @param Renderable[] $children Child Controls to add
143
     * @return static
144
     */
145
    public function addChildren(array $children)
146
    {
147
        return $this;
148
    }
149
150
    /**
151
     * Remove all children
152
     *
153
     * @api
154
     * @return static
155
     */
156
    public function removeAllChildren()
157
    {
158
        return $this;
159
    }
160
161
    /**
162
     * Remove all children
163
     *
164
     * @api
165
     * @return static
166
     * @deprecated Use removeAllChildren()
167
     * @see        Container::removeAllChildren()
168
     */
169
    public function removeChildren()
170
    {
171
        return $this;
172
    }
173
174
    /**
175
     * Get the Format
176
     *
177
     * @api
178
     * @param bool $createIfEmpty If the format should be created if it doesn't exist yet
179
     * @return Format
180
     * @deprecated Use Style
181
     * @see        Style
182
     */
183
    public function getFormat($createIfEmpty = true)
184
    {
185
186
    }
187
188
    /**
189
     * Set the Format
190
     *
191
     * @api
192
     * @param Format $format New Format
193
     * @return static
194
     * @deprecated Use Style
195
     * @see        Style
196
     */
197
    public function setFormat(Format $format = null)
198
    {
199
        return $this;
200
    }
201
202
    /**
203
     * Get the children
204
     *
205
     * @api
206
     * @return Renderable[]
207
     */
208
    public function getChildren()
209
    {
210
        return [$this->label];
211
    }
212
213
}