Completed
Pull Request — master (#270)
by
unknown
03:25
created

Textbox::render()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 29
nc 1
nop 1
1
<?php
2
3
namespace eXpansion\Framework\Gui\Components;
4
5
use FML\Controls\Frame;
6
use FML\Controls\Quad;
7
use FML\Controls\TextEdit;
8
use FML\Script\Script;
9
use FML\Types\Renderable;
10
11
class Textbox extends AbstractUiElement implements Renderable
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
    /**
19
     * @var string
20
     */
21
    protected $default;
22
23
    /**
24
     * @var int
25
     */
26
    protected $lines;
27
28
29
    /**
30
     *
31
     *
32
     * @param $name
33
     * @param string $default
34
     * @param int $lines
35
     * @param int $width
36
     */
37 View Code Duplication
    public function __construct($name, $default = "", $lines = 1, $width = 30)
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...
38
    {
39
        $this->name = $name;
40
        $this->default = $default;
41
        $this->lines = $lines;
42
        $this->setSize($width, ($lines * 5) + 2);
43
    }
44
45
    /**
46
     * Render the XML element
47
     *
48
     * @param \DOMDocument $domDocument DOMDocument for which the XML element should be rendered
49
     * @return \DOMElement
50
     */
51
    public function render(\DOMDocument $domDocument)
52
    {
53
        $frame = new Frame();
54
        $frame->setPosition($this->posX, $this->posY, $this->posZ)
55
            ->setSize($this->width, $this->height)
56
            ->addClasses(["uiContainer", "uiTextbox"]);
57
58
        $quad = new Quad();
59
        $quad->setSize(($this->width * 2), ($this->height * 2))
60
            ->setScale(0.5)
61
            ->setPosition(0, 0)
62
            ->setStyles('Bgs1', 'BgColorContour')
63
            ->setAlign("left", "top")
64
            ->setBackgroundColor('FFFA');
65
66
67
        $input = new TextEdit();
68
        $input->setSize($this->width, $this->height - 2)
69
            ->setPosition(1, -1)
70
            ->setDefault($this->default)
71
            ->setAlign("left", "top")
72
            ->addClass("UiInput")
73
            ->setAreaColor("0005")
74
            ->setAreaFocusColor('000a')
75
            ->setTextFormat('Basic')
76
            ->setName($this->name)
77
            ->setScriptEvents(true)
78
            ->addClasses($this->_classes)
79
            ->setTextSize(1.5)
80
            ->setDataAttributes($this->_dataAttributes);
81
82
        $frame->addChild($quad);
83
        $frame->addChild($input);
84
85
        return $frame->render($domDocument);
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getName()
92
    {
93
        return $this->name;
94
    }
95
96
    /**
97
     * @param string $name
98
     */
99
    public function setName($name)
100
    {
101
        $this->name = $name;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getDefault()
110
    {
111
        return $this->default;
112
    }
113
114
    /**
115
     * @param string $default
116
     */
117
    public function setDefault($default)
118
    {
119
        $this->default = $default;
120
121
        return $this;
122
    }
123
124
    /**
125
     * @return integer
126
     */
127
    public function getWidth()
128
    {
129
        return $this->width;
130
    }
131
132
    /**
133
     * @param float $width
134
     */
135
    public function setWidth($width)
136
    {
137
        $this->width = $width;
0 ignored issues
show
Documentation Bug introduced by
The property $width was declared of type integer, but $width is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
138
139
        return $this;
140
    }
141
142
    /**
143
     * Prepare the given Script for rendering by adding the needed Labels, etc.
144
     *
145
     * @param Script $script Script to prepare
146
     * @return static
147
     */
148
    public function prepare(Script $script)
149
    {
150
        // do nothing
151
    }
152
153
    /**
154
     * @return int
155
     */
156
    public function getLines()
157
    {
158
        return $this->lines;
159
    }
160
161
    /**
162
     * @param int $lines
163
     */
164
    public function setLines($lines)
165
    {
166
        $this->lines = $lines;
167
168
        return $this;
169
    }
170
171
    public function getHeight()
172
    {
173
        return $this->height + 2;
174
    }
175
}
176