Skip to content

Conversation

@awelles
Copy link
Contributor

@awelles awelles commented Jun 19, 2019

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
Copy link
Contributor Author

awelles commented Jun 19, 2019

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
Copy link
Contributor Author

awelles commented Jun 19, 2019

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

ex. gui.add( new dat.controllers.PlotterController(obj, 'plotThis'),{ liClass: 'plotter' });
Also added 2 ways to call each controller on examples.html,
first running through ControllerFactory, the second using .add( controller ).
@awelles
Copy link
Contributor Author

awelles commented Jun 21, 2019

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.

@awelles awelles closed this Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant