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

uiInput::setWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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