dataarts / dat.gui

Lightweight controller library for JavaScript.
Apache License 2.0
7.51k stars 1.09k forks source link

.add(controller) #238

Closed awelles closed 5 years ago

awelles commented 5 years ago

In reference to .add( controller ) #4

I read through @anhr's #232 then simply implemented .add(controller).

For custom controllers you can extend Controller.

For instance, anhr's KnobController:

class KnobController extends Controller {
    constructor(object, property, a, b) {
        super(object, property);

        // ... set up options if needed

        const _this = this;

        //input element
        this.__input = document.createElement('input');
        this.__input.setAttribute('type', 'number');
        this.__input.style.width = '40%';
        this.updateDisplay();
        this.domElement.appendChild(this.__input);

        //button element
        var button = document.createElement('input');
        button.setAttribute('type', 'button');
        button.value = 'Set ' + property;
        button.style.width = '50%';
        button.onclick = function (e) {
            object[property] = a + b;
            _this.updateDisplay();
        }
        this.domElement.appendChild(button);
    }

    updateDisplay() {
        this.__input.value = this.getValue();
    }
}

gui.add(new KnobController(obj, 'v', 0.5, 25));
awelles commented 5 years ago

As I implement a few more custom controllers I spot bits still needed here.

.add( controller, params ), for instance, to mirror factory parameters. And somewhere to stash the li class. Etc

awelles commented 5 years ago

Threw @anhr's PlotterController into src and example, though refactored to Controller and .add() Just wanted to give him his due.

awelles commented 5 years ago

I made a slimmer implementation of add( controller ) here: #243

It doesn't have the PlotterController or anything other than add( controller ) functionality bundled with it.

Pull that and close this.. if that be thy will.