dataarts / dat.gui

Lightweight controller library for JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customize the display name of GUI's Controller

hijiangtao opened this issue · comments

According to the code

this.property = property;
, the name of the property to manipulate is set to the same as the display name of the controller.

However, there are many situations that developers want to differentiate the manipulated property with its display name, such as Chinese words, space, special characters, etc.

We can add a property to the base class - Controller (suppose the new property is named name), and decide whether to use it when we call the .add() method (we can use expression like name || property to set the inner HTML of this Controller),

name.innerHTML = controller.property;

This new property can be set in the second parameter property, too. So the second parameter can be an object or a string normally, it's perfectly compatible to previous version in this way, and the only thing that dat.gui need to handle is judge the type of property and decide whether to set the name in the instance.

I can raise a PR if this approach is acceptable for you.

Each controller has a .name('foo') method — does that do what you need?

gui.add( object, 'property' ).name( 'My Property' );

https://github.com/dataarts/dat.gui/blob/master/API.md#Controller+name

@donmccurdy Sorry for the bothering. I focus myself on the methods of GUI, and ignored the fact that it belongs to the Controller class in fact.

Thanks very much. :-)