perfect-gui 3.5.0 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/package.json +1 -1
- package/src/index.js +49 -31
- package/test/src/index.html +5 -4
- package/test/src/js/demo.js +1 -2
- package/test/src/js/kill_create.js +2 -1
- package/test/src/js/multiple.js +1 -1
- package/test/src/js/other.js +1 -1
package/README.md
CHANGED
|
@@ -14,17 +14,15 @@ https://thibka.github.io/perfect-gui/public/
|
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
|
-
### NPM
|
|
18
17
|
```bash
|
|
19
18
|
npm i perfect-gui
|
|
20
19
|
```
|
|
21
|
-
```javascript
|
|
22
|
-
import GUI from 'perfect-gui';
|
|
23
|
-
```
|
|
24
20
|
|
|
25
21
|
## Usage
|
|
26
22
|
|
|
27
23
|
```javascript
|
|
24
|
+
import GUI from 'perfect-gui';
|
|
25
|
+
|
|
28
26
|
const gui = new GUI();
|
|
29
27
|
|
|
30
28
|
gui.button('Click me', callback);
|
|
@@ -45,17 +43,20 @@ const gui = new GUI({
|
|
|
45
43
|
width: 250,
|
|
46
44
|
// Width of the panel (in pixels).
|
|
47
45
|
// Default is 290.
|
|
46
|
+
|
|
47
|
+
maxHeight: 500,
|
|
48
|
+
// Maximum height beyond which scrolling is necessary.
|
|
49
|
+
// Default is the smallest value between the height of the window and the height of the container.
|
|
48
50
|
|
|
49
51
|
closed: false,
|
|
50
|
-
// Defines whether the panel should be
|
|
51
|
-
// Default is false
|
|
52
|
+
// Defines whether the panel should be closed by default.
|
|
53
|
+
// Default is false.
|
|
52
54
|
|
|
53
55
|
position: 'bottom right',
|
|
54
56
|
// Defines where to place the panel on screen.
|
|
55
|
-
// Accepted values are 'top', 'bottom', 'left' and 'right'
|
|
56
|
-
// in no particular order ('bottom right' = 'right bottom').
|
|
57
|
+
// Accepted values are 'top', 'bottom', 'left' and 'right' in no particular order ('bottom right' = 'right bottom').
|
|
57
58
|
// If multiple instances have the same position, they will be stacked horizontally.
|
|
58
|
-
// Default is 'top
|
|
59
|
+
// Default is 'top right'.
|
|
59
60
|
|
|
60
61
|
draggable: false,
|
|
61
62
|
// Defines if the panel can be manually moved across the screen.
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import styles from './styles';
|
|
|
2
2
|
|
|
3
3
|
export default class GUI {
|
|
4
4
|
constructor(options = {}) {
|
|
5
|
+
// Process options
|
|
5
6
|
if ( options.container ) {
|
|
6
7
|
this.container = typeof options.container == "string" ? document.querySelector(options.container) : options.container;
|
|
7
8
|
this.position_type = 'absolute';
|
|
@@ -18,8 +19,17 @@ export default class GUI {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
this.name = (options != undefined && typeof options.name == "string") ? options.name : '';
|
|
22
|
+
|
|
21
23
|
this.backgroundColor = options.color || null;
|
|
22
24
|
|
|
25
|
+
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
26
|
+
if ( options.maxHeight ) {
|
|
27
|
+
this.initMaxHeight = options.maxHeight;
|
|
28
|
+
this.maxHeight = Math.min(this.initMaxHeight, this.maxHeight);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.screenCorner = this._parseScreenCorner(options.position);
|
|
32
|
+
|
|
23
33
|
if ( this instanceof GUI ) {
|
|
24
34
|
if ( typeof GUI[GUI.instanceCounter] != 'number' ) {
|
|
25
35
|
GUI[GUI.instanceCounter] = 0;
|
|
@@ -39,10 +49,29 @@ export default class GUI {
|
|
|
39
49
|
// Common styles
|
|
40
50
|
if (this.instanceId == 0) {
|
|
41
51
|
this._addStyles(`${styles(this.position_type)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Instance specific styles
|
|
55
|
+
this._styleInstance();
|
|
56
|
+
|
|
57
|
+
if (options.autoRepositioning != false) {
|
|
58
|
+
window.addEventListener('resize', this._handleResize.bind(this));
|
|
42
59
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.
|
|
60
|
+
|
|
61
|
+
this._addWrapper();
|
|
62
|
+
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
63
|
+
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
64
|
+
|
|
65
|
+
this.hasBeenDragged = false;
|
|
66
|
+
if (options.draggable == true) this._makeDraggable();
|
|
67
|
+
|
|
68
|
+
this.closed = false;
|
|
69
|
+
if (options.closed) this.toggleClose();
|
|
70
|
+
|
|
71
|
+
this.folders = [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_styleInstance() {
|
|
46
75
|
this.xOffset = this.screenCorner.x == 'left' ? 0 : this.container.clientWidth - this.wrapperWidth;
|
|
47
76
|
if (this.instanceId > 0) {
|
|
48
77
|
let existingDomInstances = this.container.querySelectorAll('.p-gui');
|
|
@@ -60,14 +89,6 @@ export default class GUI {
|
|
|
60
89
|
this.yOffset = 0;
|
|
61
90
|
this.position = {prevX:this.xOffset, prevY:this.yOffset, x:this.xOffset, y:this.yOffset};
|
|
62
91
|
|
|
63
|
-
if ( options.maxHeight ) {
|
|
64
|
-
this.maxHeight = options.maxHeight;
|
|
65
|
-
} else {
|
|
66
|
-
this.maxHeight = Math.min(this.container.clientHeight, window.innerHeight)
|
|
67
|
-
}
|
|
68
|
-
window.addEventListener('resize', () => {
|
|
69
|
-
this.maxHeight = Math.min(options.maxHeight || '', Math.min(this.container.clientHeight, window.innerHeight));
|
|
70
|
-
});
|
|
71
92
|
this._addStyles(`#p-gui-${this.instanceId} {
|
|
72
93
|
width: ${this.wrapperWidth}px;
|
|
73
94
|
max-height: ${this.maxHeight}px;
|
|
@@ -75,20 +96,6 @@ export default class GUI {
|
|
|
75
96
|
${ this.screenCorner.y == 'top' ? '' : 'top: auto; bottom: 0;' }
|
|
76
97
|
${ this.backgroundColor ? 'background: ' + this.backgroundColor + ';' : '' }
|
|
77
98
|
}`);
|
|
78
|
-
|
|
79
|
-
if (options.autoRepositioning != false) window.addEventListener('resize', this._handleResize.bind(this));
|
|
80
|
-
|
|
81
|
-
this._addWrapper();
|
|
82
|
-
this.wrapper.setAttribute('data-corner-x', this.screenCorner.x);
|
|
83
|
-
this.wrapper.setAttribute('data-corner-y', this.screenCorner.y);
|
|
84
|
-
|
|
85
|
-
this.hasBeenDragged = false;
|
|
86
|
-
if (options.draggable == true) this._makeDraggable();
|
|
87
|
-
|
|
88
|
-
this.closed = false;
|
|
89
|
-
if (options.closed) this.toggleClose();
|
|
90
|
-
|
|
91
|
-
this.folders = [];
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
_folderConstructor(folderOptions) {
|
|
@@ -96,19 +103,31 @@ export default class GUI {
|
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
_parseScreenCorner(position) {
|
|
99
|
-
let parsedPosition = {x: '
|
|
106
|
+
let parsedPosition = {x: 'right', y: 'top'};
|
|
100
107
|
|
|
101
108
|
if (position == undefined) return parsedPosition;
|
|
102
|
-
else if (typeof position != 'string') console.error('[perfect-gui]
|
|
109
|
+
else if (typeof position != 'string') console.error('[perfect-gui] Position must be a string.');
|
|
103
110
|
|
|
104
|
-
if (position.includes('
|
|
111
|
+
if (position.includes('left')) parsedPosition.x = 'left';
|
|
105
112
|
if (position.includes('bottom')) parsedPosition.y = 'bottom';
|
|
106
113
|
|
|
107
114
|
return parsedPosition;
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
_getScrollbarWidth(element) {
|
|
118
|
+
if (element === document.body) {
|
|
119
|
+
return window.innerWidth - document.documentElement.clientWidth;
|
|
120
|
+
} else {
|
|
121
|
+
return element.offsetWidth - element.clientWidth;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
_handleResize() {
|
|
111
|
-
|
|
126
|
+
this.maxHeight = Math.min(this.initMaxHeight, Math.min(this.container.clientHeight, window.innerHeight));
|
|
127
|
+
|
|
128
|
+
if (this.hasBeenDragged) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
112
131
|
|
|
113
132
|
this.xOffset = this.screenCorner.x == 'left' ? 0 : this.container.clientWidth - this.wrapperWidth;
|
|
114
133
|
if (this.instanceId > 0) {
|
|
@@ -131,8 +150,7 @@ export default class GUI {
|
|
|
131
150
|
}
|
|
132
151
|
|
|
133
152
|
_createElement(element) {
|
|
134
|
-
|
|
135
|
-
element.el = element.el ? element.el : 'div';
|
|
153
|
+
element.el = element.el || 'div';
|
|
136
154
|
var domElement = document.createElement(element.el);
|
|
137
155
|
if (element.id) domElement.id = element.id;
|
|
138
156
|
if (element.class) domElement.className = element.class;
|
package/test/src/index.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<body>
|
|
12
12
|
<div class="wrapper">
|
|
13
13
|
<h1>Perfect GUI API</h1>
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
<h2>Basics</h2>
|
|
16
16
|
|
|
17
17
|
<div id="container-1" class="container">
|
|
@@ -134,14 +134,14 @@
|
|
|
134
134
|
|
|
135
135
|
<span style="color: #66d9ef">const</span> <span style="color: #a6e22e">gui_3</span> <span style="color: #f92672">=</span> <span style="color: #66d9ef">new</span> <span style="color: #a6e22e">GUI</span><span style="color: #f8f8f2">({</span>
|
|
136
136
|
<span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'GUI 3'</span><span style="color: #f8f8f2">,</span>
|
|
137
|
-
<span style="color: #a6e22e">position</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'top
|
|
137
|
+
<span style="color: #a6e22e">position</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'top left'</span>
|
|
138
138
|
<span style="color: #f8f8f2">});</span>
|
|
139
139
|
|
|
140
140
|
<span style="color: #a6e22e">gui_3</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Button'</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">()</span> <span style="color: #f92672">=></span> <span style="color: #a6e22e">element</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">style</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">backgroundColor</span> <span style="color: #f92672">=</span> <span style="color: #a6e22e">getRandomColor</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">);</span>
|
|
141
141
|
|
|
142
142
|
<span style="color: #66d9ef">const</span> <span style="color: #a6e22e">gui_4</span> <span style="color: #f92672">=</span> <span style="color: #66d9ef">new</span> <span style="color: #a6e22e">GUI</span><span style="color: #f8f8f2">({</span>
|
|
143
143
|
<span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'GUI 4'</span><span style="color: #f8f8f2">,</span>
|
|
144
|
-
<span style="color: #a6e22e">position</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'right
|
|
144
|
+
<span style="color: #a6e22e">position</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'bottom right'</span>
|
|
145
145
|
<span style="color: #f8f8f2">});</span>
|
|
146
146
|
|
|
147
147
|
<span style="color: #a6e22e">gui_4</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Button'</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">()</span> <span style="color: #f92672">=></span> <span style="color: #a6e22e">element</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">style</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">backgroundColor</span> <span style="color: #f92672">=</span> <span style="color: #a6e22e">getRandomColor</span><span style="color: #f8f8f2">()</span> <span style="color: #f8f8f2">);</span>
|
|
@@ -261,7 +261,8 @@
|
|
|
261
261
|
<span style="color: #a6e22e">guis</span><span style="color: #f8f8f2">[</span><span style="color: #a6e22e">guis</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">length</span><span style="color: #f8f8f2">]</span> <span style="color: #f92672">=</span> <span style="color: #66d9ef">new</span> <span style="color: #a6e22e">GUI</span><span style="color: #f8f8f2">({</span>
|
|
262
262
|
<span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'Created GUI'</span><span style="color: #f8f8f2">,</span>
|
|
263
263
|
<span style="color: #a6e22e">position</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'bottom left'</span><span style="color: #f8f8f2">,</span>
|
|
264
|
-
<span style="color: #a6e22e">width</span><span style="color: #f92672">:</span> <span style="color: #ae81ff">150</span>
|
|
264
|
+
<span style="color: #a6e22e">width</span><span style="color: #f92672">:</span> <span style="color: #ae81ff">150</span><span style="color: #f8f8f2">,</span>
|
|
265
|
+
<span style="color: #a6e22e">color</span><span style="color: #f92672">:</span> <span style="color: #ae81ff">'red'</span>
|
|
265
266
|
<span style="color: #f8f8f2">});</span>
|
|
266
267
|
<span style="color: #f8f8f2">});</span>
|
|
267
268
|
|
package/test/src/js/demo.js
CHANGED
|
@@ -13,7 +13,6 @@ export default function()
|
|
|
13
13
|
name: 'Control panel'
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
|
|
17
16
|
gui.button("Randomize color", () => {
|
|
18
17
|
element.style.backgroundColor = get_random_color();
|
|
19
18
|
});
|
|
@@ -62,5 +61,5 @@ export default function()
|
|
|
62
61
|
x: {min: -10, max: 10, object: position, prop: 'x'},
|
|
63
62
|
y: {min: -10, max: 10, object: position, prop: 'y'},
|
|
64
63
|
}, () => {});
|
|
65
|
-
gui2.
|
|
64
|
+
gui2.color('Color', '#ffd170', () => {});
|
|
66
65
|
}
|
package/test/src/js/multiple.js
CHANGED