perfect-gui 3.0.5 → 3.0.6

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/index.js +11 -14
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 parameter is optional, default is 0
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,6 +122,7 @@ gui.list('Select one', ['apple', 'lime', 'peach'], function(item) {
123
122
  <tr><td>vector2</td><td>
124
123
 
125
124
  ```javascript
125
+ // min and max parameters are optional, default is 0 (min) and 1 (max)
126
126
  let folder = 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 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Nice and simple GUI for JavaScript.",
5
5
  "main": "src/index.js",
6
6
  "directories": {
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, data.x.min, data.x.max).toFixed(1));
421
- objectY[propY] = parseFloat(this._mapLinear(evt.offsetY, 0, area.clientHeight, data.y.max, data.y.min).toFixed(1));
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], data.x.min, data.x.max, 0, area.clientWidth) + 'px';
441
- dot.style.top = this._mapLinear(objectY[propY], data.y.min, data.y.max, area.clientHeight, 0) + 'px';
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, data.x.min, data.x.max, 0, area.clientWidth) + 'px';
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, data.y.min, data.y.max, area.clientHeight, 0) + 'px';
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: () => {