Skip to content

.add(controller) - #238

Closed
awelles wants to merge 4 commits into
dataarts:masterfrom
awelles:master
Closed

.add(controller)#238
awelles wants to merge 4 commits into
dataarts:masterfrom
awelles:master

Conversation

@awelles

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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

awelles commented Jun 19, 2019

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.

@awellesawelles closed this Jun 21, 2019
Sign up for freeto 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

@awelles