perfect-gui 3.0.5 → 3.1.0
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 +5 -4
- package/package.json +1 -1
- package/src/index.js +14 -25
- package/test/src/index.html +11 -6
- package/test/src/js/folders.js +5 -5
package/README.md
CHANGED
|
@@ -91,8 +91,7 @@ gui.image('Click this', 'path/to/image', () => {
|
|
|
91
91
|
|
|
92
92
|
```javascript
|
|
93
93
|
// Simple slider, only returns a value to the callback
|
|
94
|
-
// min
|
|
95
|
-
// max parameter is optional, default is 1
|
|
94
|
+
// min and max parameters are optional, default is 0 (min) and 1 (max)
|
|
96
95
|
// step parameter is optional, default is (max - min) * 0.01
|
|
97
96
|
gui.slider('Slide this', { value: 5, min: 0, max: 10, step: .1 }, value => {
|
|
98
97
|
console.log('Slider value : ' + value);
|
|
@@ -123,7 +122,8 @@ gui.list('Select one', ['apple', 'lime', 'peach'], function(item) {
|
|
|
123
122
|
<tr><td>vector2</td><td>
|
|
124
123
|
|
|
125
124
|
```javascript
|
|
126
|
-
|
|
125
|
+
// min and max parameters are optional, default is 0 (min) and 1 (max)
|
|
126
|
+
gui.vector2('Position', {
|
|
127
127
|
x: { object: myObject.position, prop: 'x', min: -10, max: 10 },
|
|
128
128
|
y: { object: myObject.position, prop: 'y', min: -10, max: 10 },
|
|
129
129
|
});
|
|
@@ -132,7 +132,8 @@ let folder = gui.vector2('Position', {
|
|
|
132
132
|
<tr><td>folder</td><td>
|
|
133
133
|
|
|
134
134
|
```javascript
|
|
135
|
-
let folder = gui.folder(
|
|
135
|
+
let folder = gui.folder({
|
|
136
|
+
name: 'folder name',
|
|
136
137
|
closed: false // default is false
|
|
137
138
|
});
|
|
138
139
|
folder.button('click me!', callback);
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -378,19 +378,16 @@ export default class GUI {
|
|
|
378
378
|
this._checkMandatoryParams({
|
|
379
379
|
text: 'string',
|
|
380
380
|
data: 'object',
|
|
381
|
-
minX: 'number',
|
|
382
|
-
maxX: 'number',
|
|
383
|
-
minY: 'number',
|
|
384
|
-
maxY: 'number',
|
|
385
381
|
}, {
|
|
386
382
|
text,
|
|
387
383
|
data,
|
|
388
|
-
minX: data.x.min,
|
|
389
|
-
maxX: data.x.max,
|
|
390
|
-
minY: data.y.min,
|
|
391
|
-
maxY: data.y.max,
|
|
392
384
|
});
|
|
393
385
|
|
|
386
|
+
const minX = data.x.min ?? 0;
|
|
387
|
+
const maxX = data.x.max ?? 1;
|
|
388
|
+
const minY = data.y.min ?? 0;
|
|
389
|
+
const maxY = data.y.max ?? 1;
|
|
390
|
+
|
|
394
391
|
const objectX = data.x.object;
|
|
395
392
|
const propX = data.x.prop;
|
|
396
393
|
const propXReferenceIndex = this.propReferences.push(objectX[propX]) - 1;
|
|
@@ -417,8 +414,8 @@ export default class GUI {
|
|
|
417
414
|
el: 'div',
|
|
418
415
|
class: 'p-gui__vector2-area',
|
|
419
416
|
onclick: (evt) => {
|
|
420
|
-
objectX[propX] = parseFloat(this._mapLinear(evt.offsetX, 0, area.clientWidth,
|
|
421
|
-
objectY[propY] = parseFloat(this._mapLinear(evt.offsetY, 0, area.clientHeight,
|
|
417
|
+
objectX[propX] = parseFloat(this._mapLinear(evt.offsetX, 0, area.clientWidth, minX, maxX).toFixed(1));
|
|
418
|
+
objectY[propY] = parseFloat(this._mapLinear(evt.offsetY, 0, area.clientHeight, maxY, minY).toFixed(1));
|
|
422
419
|
}
|
|
423
420
|
});
|
|
424
421
|
|
|
@@ -437,13 +434,13 @@ export default class GUI {
|
|
|
437
434
|
class: 'p-gui__vector2-dot'
|
|
438
435
|
});
|
|
439
436
|
|
|
440
|
-
dot.style.left = this._mapLinear(objectX[propX],
|
|
441
|
-
dot.style.top = this._mapLinear(objectY[propY],
|
|
437
|
+
dot.style.left = this._mapLinear(objectX[propX], minX, maxX, 0, area.clientWidth) + 'px';
|
|
438
|
+
dot.style.top = this._mapLinear(objectY[propY], minY, maxY, area.clientHeight, 0) + 'px';
|
|
442
439
|
|
|
443
440
|
Object.defineProperty( objectX, propX, {
|
|
444
441
|
set: val => {
|
|
445
442
|
this.propReferences[propXReferenceIndex] = val;
|
|
446
|
-
dot.style.left = this._mapLinear(val,
|
|
443
|
+
dot.style.left = this._mapLinear(val, minX, maxX, 0, area.clientWidth) + 'px';
|
|
447
444
|
vector_value.textContent = String( val ) + ', ' + objectY[propY];
|
|
448
445
|
},
|
|
449
446
|
get: () => {
|
|
@@ -454,7 +451,7 @@ export default class GUI {
|
|
|
454
451
|
Object.defineProperty( objectY, propY, {
|
|
455
452
|
set: val => {
|
|
456
453
|
this.propReferences[propYReferenceIndex] = val;
|
|
457
|
-
dot.style.top = this._mapLinear(val,
|
|
454
|
+
dot.style.top = this._mapLinear(val, minY, maxY, area.clientHeight, 0) + 'px';
|
|
458
455
|
vector_value.textContent = objectX[propX] + ', ' + String( val );
|
|
459
456
|
},
|
|
460
457
|
get: () => {
|
|
@@ -463,17 +460,9 @@ export default class GUI {
|
|
|
463
460
|
});
|
|
464
461
|
}
|
|
465
462
|
|
|
466
|
-
folder(
|
|
463
|
+
folder(options = {}) {
|
|
467
464
|
let closed = typeof options.closed == 'boolean' ? options.closed : false;
|
|
468
|
-
|
|
469
|
-
let params = {
|
|
470
|
-
name,
|
|
471
|
-
closed
|
|
472
|
-
};
|
|
473
|
-
this._checkMandatoryParams({
|
|
474
|
-
name: 'string',
|
|
475
|
-
closed: 'boolean'
|
|
476
|
-
}, params);
|
|
465
|
+
let name = options.name || '';
|
|
477
466
|
|
|
478
467
|
this.imageContainer = null;
|
|
479
468
|
|
|
@@ -492,7 +481,7 @@ export default class GUI {
|
|
|
492
481
|
});
|
|
493
482
|
|
|
494
483
|
let folderHeader = this._createElement({
|
|
495
|
-
innerHTML: `<span class="p-gui__folder-arrow"></span>${
|
|
484
|
+
innerHTML: `<span class="p-gui__folder-arrow"></span>${name}`,
|
|
496
485
|
class: 'p-gui__folder-header',
|
|
497
486
|
onclick: function() {
|
|
498
487
|
this.parentNode.classList.toggle('p-gui__folder--closed');
|
package/test/src/index.html
CHANGED
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
|
|
152
152
|
<h2>Folders</h2>
|
|
153
153
|
|
|
154
|
-
<p>Folders can be closed by default by setting the <i>
|
|
154
|
+
<p>Folders can be closed by default by setting the <i>closed</i> parameter to <span class="code-inline">true</span>.</p>
|
|
155
155
|
|
|
156
156
|
<div id="container-3" class="container">
|
|
157
157
|
<div class="element"></div>
|
|
@@ -159,22 +159,27 @@
|
|
|
159
159
|
|
|
160
160
|
<div class="code-button" onclick="document.getElementById('code-block-folders').classList.toggle('code-block--hidden')">See code</div>
|
|
161
161
|
<div id="code-block-folders" class="code-block code-block--hidden">
|
|
162
|
-
<!-- HTML generated using hilite.me --><div style="background: #272822; overflow:auto;width:auto;;"><pre style="margin: 0; line-height: 125%"><span style="color: #66d9ef">const</span> <span style="color: #a6e22e">gui</span> <span style="color: #f92672">=</span> <span style="color: #66d9ef">new</span> <span style="color: #a6e22e">
|
|
162
|
+
<!-- HTML generated using hilite.me --><div style="background: #272822; overflow:auto;width:auto;;"><pre style="margin: 0; line-height: 125%"><span style="color: #66d9ef">const</span> <span style="color: #a6e22e">gui</span> <span style="color: #f92672">=</span> <span style="color: #66d9ef">new</span> <span style="color: #a6e22e">perfectGUI</span><span style="color: #f8f8f2">({</span>
|
|
163
163
|
<span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'Folders'</span>
|
|
164
164
|
<span style="color: #f8f8f2">});</span>
|
|
165
165
|
|
|
166
|
-
<span style="color: #66d9ef">let</span> <span style="color: #a6e22e">folder_1</span> <span style="color: #f92672">=</span> <span style="color: #a6e22e">gui</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">folder</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Folder 1'</span
|
|
166
|
+
<span style="color: #66d9ef">let</span> <span style="color: #a6e22e">folder_1</span> <span style="color: #f92672">=</span> <span style="color: #a6e22e">gui</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">folder</span><span style="color: #f8f8f2">({</span> <span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'Folder 1 (open)'</span> <span style="color: #f8f8f2">});</span>
|
|
167
167
|
|
|
168
|
-
<span style="color: #a6e22e">folder_1</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74"
|
|
168
|
+
<span style="color: #a6e22e">folder_1</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Random color'</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">()</span> <span style="color: #f92672">=></span> <span style="color: #f8f8f2">{</span>
|
|
169
169
|
<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>
|
|
170
170
|
<span style="color: #f8f8f2">});</span>
|
|
171
171
|
|
|
172
|
-
<span style="color: #
|
|
172
|
+
<span style="color: #a6e22e">folder_1</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">slider</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Size'</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">{</span> <span style="color: #a6e22e">value</span><span style="color: #f92672">:</span> <span style="color: #ae81ff">1</span> <span style="color: #f8f8f2">},</span> <span style="color: #a6e22e">value</span> <span style="color: #f92672">=></span> <span style="color: #f8f8f2">{</span>
|
|
173
|
+
<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">transform</span> <span style="color: #f92672">=</span> <span style="color: #960050; background-color: #1e0010">`</span><span style="color: #a6e22e">scale</span><span style="color: #f8f8f2">(</span><span style="color: #a6e22e">$</span><span style="color: #f8f8f2">{</span><span style="color: #a6e22e">value</span><span style="color: #f8f8f2">})</span><span style="color: #960050; background-color: #1e0010">`</span><span style="color: #f8f8f2">;</span>
|
|
174
|
+
<span style="color: #f8f8f2">});</span>
|
|
175
|
+
|
|
176
|
+
<span style="color: #66d9ef">let</span> <span style="color: #a6e22e">folder_2</span> <span style="color: #f92672">=</span> <span style="color: #a6e22e">gui</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">folder</span><span style="color: #f8f8f2">({</span> <span style="color: #a6e22e">name</span><span style="color: #f92672">:</span> <span style="color: #e6db74">'Folder 2 (closed)'</span><span style="color: #f8f8f2">,</span> <span style="color: #a6e22e">closed</span><span style="color: #f92672">:</span> <span style="color: #66d9ef">true</span> <span style="color: #f8f8f2">});</span>
|
|
173
177
|
|
|
174
|
-
<span style="color: #a6e22e">folder_2</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74"
|
|
178
|
+
<span style="color: #a6e22e">folder_2</span><span style="color: #f8f8f2">.</span><span style="color: #a6e22e">button</span><span style="color: #f8f8f2">(</span><span style="color: #e6db74">'Random color'</span><span style="color: #f8f8f2">,</span> <span style="color: #f8f8f2">()</span> <span style="color: #f92672">=></span> <span style="color: #f8f8f2">{</span>
|
|
175
179
|
<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>
|
|
176
180
|
<span style="color: #f8f8f2">});</span>
|
|
177
181
|
</pre></div>
|
|
182
|
+
|
|
178
183
|
</div>
|
|
179
184
|
|
|
180
185
|
<h2>Other options</h2>
|
package/test/src/js/folders.js
CHANGED
|
@@ -9,19 +9,19 @@ export default function folders() {
|
|
|
9
9
|
container: '#container-3'
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
let folder_1 = gui.folder('Folder 1 (open)');
|
|
12
|
+
let folder_1 = gui.folder({ name: 'Folder 1 (open)' });
|
|
13
13
|
|
|
14
|
-
folder_1.button(
|
|
14
|
+
folder_1.button('Random color', () => {
|
|
15
15
|
element.style.backgroundColor = getRandomColor();
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
folder_1.slider(
|
|
18
|
+
folder_1.slider('Size', { value: 1 }, value => {
|
|
19
19
|
element.style.transform = `scale(${value})`;
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
let folder_2 = gui.folder('Folder 2 (closed)',
|
|
22
|
+
let folder_2 = gui.folder({ name: 'Folder 2 (closed)', closed: true });
|
|
23
23
|
|
|
24
|
-
folder_2.button(
|
|
24
|
+
folder_2.button('Random color', () => {
|
|
25
25
|
element.style.backgroundColor = getRandomColor();
|
|
26
26
|
});
|
|
27
27
|
}
|