perfect-gui 4.3.5 → 4.4.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/package.json +1 -1
- package/src/index.js +88 -13
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -423,10 +423,11 @@ export default class GUI {
|
|
|
423
423
|
if ( isObject ) {
|
|
424
424
|
obj[prop] = slider_ctrl.value;
|
|
425
425
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
else {
|
|
427
|
+
if (typeof callback == "function") {
|
|
428
|
+
callback(parseFloat(slider_ctrl.value));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
430
431
|
});
|
|
431
432
|
|
|
432
433
|
if ( isObject ) {
|
|
@@ -435,6 +436,10 @@ export default class GUI {
|
|
|
435
436
|
this.propReferences[propReferenceIndex] = val;
|
|
436
437
|
slider_ctrl.value = val;
|
|
437
438
|
slider_value.textContent = String( val );
|
|
439
|
+
|
|
440
|
+
if (typeof callback == "function") {
|
|
441
|
+
callback(parseFloat(slider_ctrl.value));
|
|
442
|
+
}
|
|
438
443
|
},
|
|
439
444
|
get: () => {
|
|
440
445
|
return this.propReferences[propReferenceIndex];
|
|
@@ -449,32 +454,102 @@ export default class GUI {
|
|
|
449
454
|
}
|
|
450
455
|
|
|
451
456
|
let name = typeof params.name == 'string' ? params.name || ' ' : ' ';
|
|
452
|
-
let
|
|
457
|
+
let isObject = false;
|
|
458
|
+
let propReferenceIndex = null;
|
|
459
|
+
let obj = params.obj || params.object;
|
|
460
|
+
let prop = params.prop || params.property;
|
|
461
|
+
let value = typeof params.value === 'boolean' ? params.value : null;
|
|
462
|
+
|
|
463
|
+
// callback mode
|
|
464
|
+
if ( value !== null ) {
|
|
465
|
+
if (prop != undefined || obj != undefined) {
|
|
466
|
+
console.warn(`[GUI] toggle() "obj" and "property" parameters are ignored when a "value" parameter is used.`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// object-binding
|
|
471
|
+
else if (prop != undefined && obj != undefined) {
|
|
472
|
+
if (typeof prop != 'string') {
|
|
473
|
+
throw Error(`[GUI] toggle() "prop" (or "property") parameter must be an string. Received: ${typeof prop}.`);
|
|
474
|
+
}
|
|
475
|
+
if (typeof obj != 'object') {
|
|
476
|
+
throw Error(`[GUI] toggle() "obj" (or "object") parameter must be an object. Received: ${typeof obj}.`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (name == ' ') {
|
|
480
|
+
name = prop;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
propReferenceIndex = this.propReferences.push(obj[prop]) - 1;
|
|
484
|
+
isObject = true;
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
if ((prop != undefined && obj == undefined) || (prop == undefined && obj == undefined)) {
|
|
488
|
+
console.warn(`[GUI] toggle() "obj" and "prop" parameters must be used together.`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
453
491
|
|
|
454
492
|
this.imageContainer = null;
|
|
455
493
|
|
|
456
|
-
|
|
494
|
+
const container = this._createElement({
|
|
457
495
|
class: 'p-gui__switch',
|
|
458
496
|
onclick: (ev) => {
|
|
459
|
-
|
|
460
|
-
|
|
497
|
+
const checkbox = ev.target.childNodes[1];
|
|
498
|
+
|
|
499
|
+
let value = true;
|
|
500
|
+
|
|
461
501
|
if (checkbox.classList.contains('p-gui__switch-checkbox--active')) {
|
|
462
502
|
value = false;
|
|
463
503
|
}
|
|
504
|
+
|
|
464
505
|
checkbox.classList.toggle('p-gui__switch-checkbox--active');
|
|
465
|
-
|
|
466
|
-
|
|
506
|
+
|
|
507
|
+
if ( isObject ) {
|
|
508
|
+
obj[prop] = value;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
else {
|
|
512
|
+
if (typeof callback == 'function') {
|
|
513
|
+
callback(value);
|
|
514
|
+
}
|
|
467
515
|
}
|
|
468
516
|
},
|
|
469
517
|
textContent: name
|
|
470
518
|
});
|
|
471
519
|
|
|
472
|
-
let activeClass =
|
|
520
|
+
let activeClass = (() => {
|
|
521
|
+
if (!isObject) {
|
|
522
|
+
return value ? ' p-gui__switch-checkbox--active' : '';
|
|
523
|
+
} else {
|
|
524
|
+
return obj[prop] ? ' p-gui__switch-checkbox--active' : '';
|
|
525
|
+
}
|
|
526
|
+
})();
|
|
473
527
|
|
|
474
|
-
this._createElement({
|
|
475
|
-
parent:
|
|
528
|
+
const checkbox = this._createElement({
|
|
529
|
+
parent: container,
|
|
476
530
|
class: 'p-gui__switch-checkbox' + activeClass
|
|
477
531
|
});
|
|
532
|
+
|
|
533
|
+
if ( isObject ) {
|
|
534
|
+
Object.defineProperty( obj, prop, {
|
|
535
|
+
set: val => {
|
|
536
|
+
this.propReferences[propReferenceIndex] = val;
|
|
537
|
+
|
|
538
|
+
if (val) {
|
|
539
|
+
checkbox.classList.add('p-gui__switch-checkbox--active');
|
|
540
|
+
} else {
|
|
541
|
+
checkbox.classList.remove('p-gui__switch-checkbox--active');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (typeof callback == 'function') {
|
|
545
|
+
callback(val);
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
get: () => {
|
|
549
|
+
return this.propReferences[propReferenceIndex];
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
478
553
|
}
|
|
479
554
|
|
|
480
555
|
list(params = {}, callback) {
|