Completed
Pull Request — master (#124)
by De Cramer
03:55 queued 01:21
created

uiInput::getHeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace eXpansion\Framework\Gui\Components;
4
5
use FML\Controls\Entry;
6
use FML\Controls\Frame;
7
use FML\Controls\Quad;
8
use FML\Script\Features\ScriptFeature;
9
use FML\Script\Script;
10
use FML\Script\ScriptLabel;
11
use FML\Types\Renderable;
12
use FML\Types\ScriptFeatureable;
13
14
class uiInput extends abstractUiElement implements Renderable, ScriptFeatureable
15
{
16
17
    const TYPE_DEFAULT = "Basic";
18
    const TYPE_PASSWORD = "Password";
19
20
    /**
21
     * @var string
22
     */
23
    protected $name;
24
    /**
25
     * @var string
26
     */
27
    protected $default;
28
29
    protected $textFormat = "Basic";
30
31 View Code Duplication
    public function __construct($name, $default = "", $width = 30, $textFormat = "Basic")
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $this->name = $name;
34
        $this->default = $default;
35
        $this->width = $width;
36
        $this->setSize($width, 5);
37
        $this->textFormat = $textFormat;
38
    }
39
40
    /**
41
     * Render the XML element
42
     *
43
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
44
     * @return \DOMElement
45
     */
46
    public function render(\DOMDocument $domDocument)
47
    {
48
        $frame = new Frame();
49
        $frame->setPosition($this->posX, $this->posY)
50
            ->setSize($this->width, $this->height)
51
            ->addClasses(["uiContainer", "uiInput"]);
52
53
        $quad = new Quad();
54
        $quad->setSize($this->width * 2, $this->height * 2)
55
            ->setScale(0.5)
56
            ->setPosition($this->width / 2, -$this->height / 2)
57
            ->setStyles('Bgs1', 'BgColorContour')
58
            ->setAlign("center", "center")
59
            ->setBackgroundColor('FFFA')
60
            ->addClass("uiInput")
61
            ->setScriptEvents(true)
62
            ->setDataAttributes($this->_dataAttributes)->addClasses($this->_classes);
63
64
        $input = new Entry();
65
        $input->setSize($this->width, $this->height)
66
            ->setPosition(0, -$this->height / 2)
67
            ->setDefault($this->default)
68
            ->setSelectText(true)
69
            ->setAlign("left", "center2")
70
            ->setAreaColor("0005")
71
            ->setAreaFocusColor('000a')
72
            ->setTextFormat($this->textFormat)
73
            ->setName($this->name)
74
            ->setTextSize(2);
75
76
        $frame->addChild($quad);
77
        $frame->addChild($input);
78
79
        return $frame->render($domDocument);
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getName()
86
    {
87
        return $this->name;
88
    }
89
90
    /**
91
     * @param string $name
92
     */
93
    public function setName($name)
94
    {
95
        $this->name = $name;
96
97
        return $this;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getDefault()
104
    {
105
        return $this->default;
106
    }
107
108
    /**
109
     * @param string $default
110
     */
111
    public function setDefault($default)
112
    {
113
        $this->default = $default;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return float
120
     */
121
    public function getWidth()
122
    {
123
        return $this->width;
124
    }
125
126
    /**
127
     * @param float $width
128
     */
129
    public function setWidth($width)
130
    {
131
        $this->width = $width;
132
133
        return $this;
134
    }
135
136
    public function getHeight()
137
    {
138
        return $this->height+2;
139
    }
140
141
    /**
142
     * Prepare the given Script for rendering by adding the needed Labels, etc.
143
     *
144
     * @param Script $script Script to prepare
145
     */
146
    public function prepare(Script $script)
147
    {
148
        $script->addCustomScriptLabel(ScriptLabel::MouseClick, $this->getScriptMouseClick());
149
    }
150
151
    /**
152
     * Get the Script Features
153
     *
154
     * @return ScriptFeature[]
155
     */
156
    public function getScriptFeatures()
157
    {
158
        return ScriptFeature::collect($this);
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getTextFormat()
165
    {
166
        return $this->textFormat;
167
    }
168
169
    /**
170
     * @param string $textFormat
171
     * @return $this
172
     */
173
    public function setTextFormat($textFormat)
174
    {
175
        $this->textFormat = $textFormat;
176
177
        return $this;
178
    }
179
180
    protected function getScriptMouseClick()
181
    {
182
        return <<<EOL
183
             if (Event.Control.HasClass("uiInput") ) {              
184
                 declare CMlFrame frame <=> Event.Control.Parent;
185
                 (frame.Controls[1] as CMlEntry).StartEdition();               
186
            }					
187
EOL;
188
189
    }
190
}
191