Completed
Pull Request — master (#99)
by De Cramer
02:46
created

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