Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion examples/jsm/inspector/tabs/Parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class ParametersGroup {
constructor( parameters, name ) {

this.parameters = parameters;
this.name = name;

this.paramList = new Item( name );
this.paramList.setCollapsible( true );

this.objects = [];

Expand All @@ -25,6 +25,30 @@ class ParametersGroup {

}

name( name ) {

this.paramList.setValue( 0, name );

return this;

}

show() {

this.paramList.show();

return this;

}

hide() {

this.paramList.hide();

return this;

}

add( object, property, ...params ) {

const value = object[ property ];
Expand Down Expand Up @@ -129,6 +153,9 @@ class ParametersGroup {

this.objects.push( { object: object, key: property, editor: editor, subItem: subItem } );

editor.addEventListener( 'show', () => subItem.show() );
editor.addEventListener( 'hide', () => subItem.hide() );

}

addString( object, property ) {
Expand Down
2 changes: 2 additions & 0 deletions examples/jsm/inspector/tabs/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Viewer extends Tab {
this.content.appendChild( fullViewerContainer );

const nodes = new Item( 'User Defined' );
nodes.setCollapsible( true );
nodeList.add( nodes );

//
Expand Down Expand Up @@ -200,6 +201,7 @@ class Viewer extends Tab {
if ( folder === undefined ) {

folder = new Item( name );
folder.setCollapsible( true );

this.folderLibrary.set( name, folder );
this.nodeList.add( folder );
Expand Down
105 changes: 92 additions & 13 deletions examples/jsm/inspector/ui/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class Item {

this.children = [];
this.isOpen = true;
this.isCollapsible = false;
this.childrenContainer = null;
this.parent = null;
this.domElement = document.createElement( 'div' );
Expand All @@ -13,23 +14,15 @@ export class Item {

this.userData = {};

this.data = data;
this.data.forEach( ( cellData ) => {
this.data = [];
data.forEach( ( cellData, index ) => {

const cell = document.createElement( 'div' );
cell.className = 'list-item-cell';
if ( cellData instanceof HTMLElement ) {

cell.appendChild( cellData );

} else {

cell.append( String( cellData ) );

}

this.itemRow.appendChild( cell );

this.setValue( index, cellData );

} );

this.domElement.appendChild( this.itemRow );
Expand Down Expand Up @@ -116,7 +109,7 @@ export class Item {
const firstCell = this.itemRow.querySelector( '.list-item-cell:first-child' );
let toggler = this.itemRow.querySelector( '.item-toggler' );

if ( this.children.length > 0 ) {
if ( this.children.length > 0 || this.isCollapsible ) {

if ( ! toggler ) {

Expand All @@ -140,6 +133,36 @@ export class Item {

}

setCollapsible( collapsible ) {

this.isCollapsible = collapsible;

if ( collapsible ) {

this.itemRow.classList.add( 'collapsible' );

if ( ! this.childrenContainer ) {

this.childrenContainer = document.createElement( 'div' );
this.childrenContainer.className = 'list-children-container';
this.childrenContainer.classList.toggle( 'closed', ! this.isOpen );
this.domElement.appendChild( this.childrenContainer );
this.itemRow.addEventListener( 'click', this.onItemClick );

}

} else {

this.itemRow.classList.remove( 'collapsible' );

}

this.updateToggler();

return this;

}

toggle() {

this.isOpen = ! this.isOpen;
Expand Down Expand Up @@ -167,4 +190,60 @@ export class Item {

}

show() {

this.domElement.style.display = '';

return this;

}

hide() {

this.domElement.style.display = 'none';

return this;

}

setValue( index, value ) {

this.data[ index ] = value;

const cell = this.itemRow.children[ index ];

if ( cell ) {

const toggler = cell.querySelector( '.item-toggler' );

cell.innerHTML = '';

if ( toggler ) {

cell.appendChild( toggler );

}

if ( value instanceof HTMLElement ) {

cell.appendChild( value );

} else {

cell.append( String( value ) );

}

}

return this;

}

getValue( index ) {

return this.data[ index ];

}

}
2 changes: 1 addition & 1 deletion examples/jsm/inspector/ui/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ export class Style {
min-height: 16px;
display: flex;
align-items: center;
line-height: 1;
}

.mini-panel-content .collapsible-icon {
Expand Down Expand Up @@ -1109,7 +1110,6 @@ export class Style {

.list-item-wrapper.header-wrapper>.list-item-row>.list-item-cell:first-child {
font-weight: 600;
line-height: 1;
}

.list-item-row.collapsible,
Expand Down
68 changes: 65 additions & 3 deletions examples/jsm/inspector/ui/Values.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ class Value extends EventDispatcher {

}

show() {

this.dispatchEvent( { type: 'show' } );

return this;

}

hide() {

this.dispatchEvent( { type: 'hide' } );

return this;

}

}

class ValueNumber extends Value {
Expand Down Expand Up @@ -333,6 +349,32 @@ class ValueSelect extends Value {

}

setValue( val ) {

if ( Array.isArray( this.options ) ) {

this.select.value = val;

} else {

const entry = Object.entries( this.options ).find( ( [ , v ] ) => v === val );

if ( entry ) {

this.select.value = entry[ 0 ];

} else {

this.select.value = val;

}

}

return super.setValue( val );

}

getValue() {

const options = this.options;
Expand Down Expand Up @@ -386,19 +428,39 @@ class ValueColor extends Value {

}

setValue( val ) {

const colorHex = this._getColorHex( val );

this.colorInput.value = colorHex;

if ( this._value && this._value.isColor ) {

this._value.setHex( parseInt( colorHex.slice( 1 ), 16 ) );

} else {

this._value = val;

}

return super.setValue( val );

}

_getColorHex( color ) {

if ( color.isColor ) {
if ( color && color.isColor ) {

color = color.getHex();

}

if ( typeof color === 'number' ) {

color = `#${ color.toString( 16 ) }`;
color = '#' + color.toString( 16 ).padStart( 6, '0' );

} else if ( color[ 0 ] !== '#' ) {
} else if ( typeof color === 'string' && color[ 0 ] !== '#' ) {

color = '#' + color;

Expand Down