Skip to content

Implement .add( controller ) & its use for custom Controllers. - #243

Open
awelles wants to merge 1 commit into
dataarts:masterfrom
awelles:addcontroller
Open

Implement .add( controller ) & its use for custom Controllers.#243
awelles wants to merge 1 commit into
dataarts:masterfrom
awelles:addcontroller

Conversation

@awelles

@awellesawelles commented Jun 21, 2019

Copy link
Copy Markdown
Contributor

See example of a custom controller in example.html.
Fixes#4.

I stripped out everything unessential. It's just add( controller ) and a couple examples.

You can include parameters when adding:

gui.add( controller, params );

Currently a parameter called liClass lives here.

ParamTypeDefaultDescription
[params]Object
[params.liClass]Stringclass name appended to controller's li row.

This was needed to avoid more special cases in assigning li row class, which is done just after controller class is squared away in GUI.js.

See example of a custom controller in example.html.
@awellesawelles mentioned this pull request Jun 21, 2019

@donmccurdydonmccurdy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and sorry for the slow followup. Are you still interested in doing this PR?

Comment threadsrc/dat/gui/GUI.js
} else if ( params.liClass ) {
dom.addClass(li, params.liClass);
} else if ( controller.liClass ) {
dom.addClass(li, controller.liClass);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both of these (params.liClass and controller.liClass) needed? If this li will later be set as controller.__li, could the controller add the class itself?

Comment threadsrc/dat/gui/GUI.js

if (object instanceof Controller) {
controller = object;
params = property || { };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params doesn't take a default value normally, so is it OK to omit the || {} here?

Comment threadexample.html

gui.add(new KnobController(api, 'value', 0.5, 25), {
liClass: 'knobby'
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if this is compatible with the augmentController method here?

functionaugmentController(gui,li,controller){
controller.__li=li;
controller.__gui=gui;
common.extend(controller,/** @lends Controller.prototype */{
/**
* @param {Array|Object} options
* @return {Controller}
*/
options: function(options){
if(arguments.length>1){
constnextSibling=controller.__li.nextElementSibling;
controller.remove();
returnadd(
gui,
controller.object,
controller.property,
{
before: nextSibling,
factoryArgs: [common.toArray(arguments)]
}
);
}
if(common.isArray(options)||common.isObject(options)){
constnextSibling=controller.__li.nextElementSibling;
controller.remove();
returnadd(
gui,
controller.object,
controller.property,
{
before: nextSibling,
factoryArgs: [options]
}
);
}
},
/**
* Sets the name of the controller.
* @param {string} name
* @return {Controller}
*/
name: function(name){
controller.__li.firstElementChild.firstElementChild.innerHTML=name;
returncontroller;
},
/**
* Sets controller to listen for changes on its underlying object.
* @return {Controller}
*/
listen: function(){
controller.__gui.listen(controller);
returncontroller;
},
/**
* Removes the controller from its parent GUI.
* @return {Controller}
*/
remove: function(){
controller.__gui.remove(controller);
returncontroller;
}
});

... specifically — can you still remove(), listen(), and name() the KnobController normally? I don't suppose it's possible to override those methods in the subclass, which is unfortunate, but probably not this PR's problem to solve.

@amir-arad

Copy link
Copy Markdown

Hi.
I've just started using this library and seems like this PR is a huge thing for my use case.

what is needed in order for this to be published?

superkelvint added a commit to superkelvint/dat.gui that referenced this pull request Mar 30, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.add( controller )

3 participants

@awelles@amir-arad@donmccurdy