Completed
Pull Request — master (#100)
by
unknown
02:35
created

uiInput::getTextFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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\Script;
9
use FML\Types\Renderable;
10
11
class uiInput extends abstractUiElement implements Renderable
12
{
13
14
    const TYPE_DEFAULT = "Basic";
15
    const TYPE_PASSWORD = "Password";
16
17
    /**
18
     * @var string
19
     */
20
    protected $name;
21
    /**
22
     * @var string
23
     */
24
    protected $default;
25
26
    protected $textFormat = "Basic";
27
28 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...
29
    {
30
        $this->name = $name;
31
        $this->default = $default;
32
        $this->width = $width;
33
        $this->setSize($width, 5);
34
        $this->textFormat = $textFormat;
35
    }
36
37
    /**
38
     * Render the XML element
39
     *
40
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
41
     * @return \DOMElement
42
     */
43
    public function render(\DOMDocument $domDocument)
44
    {
45
        $frame = new Frame();
46
        $frame->setPosition($this->posX, $this->posY)
47
            ->setSize($this->width, $this->height)
48
            ->addClasses(["uiContainer", "uiInput"]);
49
50
        $quad = new Quad();
51
        $quad->setSize($this->width * 2, $this->height * 2)
52
            ->setScale(0.5)
53
            ->setPosition($this->width / 2, -$this->height / 2)
54
            ->setStyles('Bgs1', 'BgColorContour')
55
            ->setAlign("center", "center")
56
            ->setBackgroundColor('FFFA');
57
58
        $input = new Entry();
59
        $input->setSize($this->width, $this->height)
60
            ->setPosition(0, -$this->height / 2)
61
            ->setDefault($this->default)
62
            ->setSelectText(true)
63
            ->setAlign("left", "center2")
64
            ->addClass("uiInput")
65
            ->setAreaColor("0005")
66
            ->setAreaFocusColor('000a')
67
            ->setTextFormat($this->textFormat)
68
            ->setName($this->name)
69
            ->setScriptEvents(true)
70
            ->addClasses($this->_classes)
71
            ->setDataAttributes($this->_dataAttributes);
72
73
74
        $frame->addChild($quad);
75
        $frame->addChild($input);
76
77
        return $frame->render($domDocument);
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getName()
84
    {
85
        return $this->name;
86
    }
87
88
    /**
89
     * @param string $name
90
     */
91
    public function setName($name)
92
    {
93
        $this->name = $name;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getDefault()
102
    {
103
        return $this->default;
104
    }
105
106
    /**
107
     * @param string $default
108
     */
109
    public function setDefault($default)
110
    {
111
        $this->default = $default;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return float
118
     */
119
    public function getWidth()
120
    {
121
        return $this->width;
122
    }
123
124
    /**
125
     * @param float $width
126
     */
127
    public function setWidth($width)
128
    {
129
        $this->width = $width;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Prepare the given Script for rendering by adding the needed Labels, etc.
136
     *
137
     * @param Script $script Script to prepare
138
     * @return static
139
     */
140
    public function prepare(Script $script)
141
    {
142
        // do nothing
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    public function getTextFormat()
149
    {
150
        return $this->textFormat;
151
    }
152
153
    /**
154
     * @param string $textFormat
155
     * @return $this
156
     */
157
    public function setTextFormat($textFormat)
158
    {
159
        $this->textFormat = $textFormat;
160
161
        return $this;
162
    }
163
}
164