Răsfoiți Sursa

Editor - Add CollapsiblePanel

aaron 11 ani în urmă
părinte
comite
c9362b3d20

+ 22 - 0
editor/css/dark.css

@@ -55,6 +55,28 @@ button {
 	user-select: none;
 	user-select: none;
 }
 }
 
 
+.CollapsiblePanel .CollapsiblePanelButton {
+	float: left;
+	margin-right: 4px;
+	width: 0px;
+	height: 0px;
+	border: 6px solid transparent;
+}
+
+.CollapsiblePanel.collapsed .CollapsiblePanelButton {
+	margin-top: 2px;
+	border-left-color: #bbb;
+}
+
+.CollapsiblePanel:not(.collapsed) .CollapsiblePanelButton {
+	margin-top: 6px;
+	border-top-color: #bbb;
+}
+
+.CollapsiblePanel.collapsed .CollapsibleContent {
+	display: none;
+}
+
 .FancySelect {
 .FancySelect {
 	background: #222;
 	background: #222;
 	border: 1px solid #3C3C3C;
 	border: 1px solid #3C3C3C;

+ 22 - 0
editor/css/light.css

@@ -28,6 +28,28 @@ button {
 	user-select: none;
 	user-select: none;
 }
 }
 
 
+.CollapsiblePanel .CollapsiblePanelButton {
+	float: left;
+	margin-right: 4px;
+	width: 0px;
+	height: 0px;
+	border: 6px solid transparent;
+}
+
+.CollapsiblePanel.collapsed .CollapsiblePanelButton {
+	margin-top: 2px;
+	border-left-color: #333;
+}
+
+.CollapsiblePanel:not(.collapsed) .CollapsiblePanelButton {
+	margin-top: 6px;
+	border-top-color: #333;
+}
+
+.CollapsiblePanel.collapsed .CollapsibleContent {
+	display: none;
+}
+
 .FancySelect {
 .FancySelect {
 	background: #fff;
 	background: #fff;
 	border: 1px solid #ccc;
 	border: 1px solid #ccc;

+ 3 - 3
editor/js/Sidebar.Geometry.js

@@ -2,11 +2,11 @@ Sidebar.Geometry = function ( editor ) {
 
 
 	var signals = editor.signals;
 	var signals = editor.signals;
 
 
-	var container = new UI.Panel();
+	var container = new UI.CollapsiblePanel();
 	container.setDisplay( 'none' );
 	container.setDisplay( 'none' );
 
 
-	container.add( new UI.Text().setValue( 'GEOMETRY' ) );
-	container.add( new UI.Break(), new UI.Break() );
+	container.addStatic( new UI.Text().setValue( 'GEOMETRY' ) );
+	container.add( new UI.Break() );
 
 
 	// uuid
 	// uuid
 
 

+ 3 - 3
editor/js/Sidebar.Material.js

@@ -20,12 +20,12 @@ Sidebar.Material = function ( editor ) {
 
 
 	};
 	};
 
 
-	var container = new UI.Panel();
+	var container = new UI.CollapsiblePanel();
 	container.setDisplay( 'none' );
 	container.setDisplay( 'none' );
 	container.dom.classList.add( 'Material' );
 	container.dom.classList.add( 'Material' );
 
 
-	container.add( new UI.Text().setValue( 'MATERIAL' ) );
-	container.add( new UI.Break(), new UI.Break() );
+	container.addStatic( new UI.Text().setValue( 'MATERIAL' ) );
+	container.add( new UI.Break() );
 
 
 	// uuid
 	// uuid
 
 

+ 3 - 3
editor/js/Sidebar.Object3D.js

@@ -2,12 +2,12 @@ Sidebar.Object3D = function ( editor ) {
 
 
 	var signals = editor.signals;
 	var signals = editor.signals;
 
 
-	var container = new UI.Panel();
+	var container = new UI.CollapsiblePanel();
 	container.setDisplay( 'none' );
 	container.setDisplay( 'none' );
 
 
 	var objectType = new UI.Text().setTextTransform( 'uppercase' );
 	var objectType = new UI.Text().setTextTransform( 'uppercase' );
-	container.add( objectType );
-	container.add( new UI.Break(), new UI.Break() );
+	container.addStatic( objectType );
+	container.add( new UI.Break() );
 
 
 	// uuid
 	// uuid
 
 

+ 3 - 3
editor/js/Sidebar.Renderer.js

@@ -13,10 +13,10 @@ Sidebar.Renderer = function ( editor ) {
 
 
 	};
 	};
 
 
-	var container = new UI.Panel();
+	var container = new UI.CollapsiblePanel();
 
 
-	container.add( new UI.Text( 'RENDERER' ) );
-	container.add( new UI.Break(), new UI.Break() );
+	container.addStatic( new UI.Text( 'RENDERER' ) );
+	container.add( new UI.Break() );
 
 
 	// class
 	// class
 
 

+ 3 - 3
editor/js/Sidebar.Scene.js

@@ -2,10 +2,10 @@ Sidebar.Scene = function ( editor ) {
 
 
 	var signals = editor.signals;
 	var signals = editor.signals;
 
 
-	var container = new UI.Panel();
+	var container = new UI.CollapsiblePanel();
 
 
-	container.add( new UI.Text( 'SCENE' ) );
-	container.add( new UI.Break(), new UI.Break() );
+	container.addStatic( new UI.Text( 'SCENE' ) );
+	container.add( new UI.Break() );
 
 
 	var outliner = new UI.FancySelect().setId( 'outliner' );
 	var outliner = new UI.FancySelect().setId( 'outliner' );
 	outliner.onChange( function () {
 	outliner.onChange( function () {

+ 127 - 0
editor/js/libs/ui.js

@@ -137,6 +137,133 @@ UI.Panel.prototype.clear = function () {
 
 
 };
 };
 
 
+
+// Collapsible Panel
+
+UI.CollapsiblePanel = function () {
+
+	UI.Panel.call( this );
+	this.dom.className = 'Panel CollapsiblePanel';
+
+	this.button = document.createElement( 'div' );
+	this.button.className = 'CollapsiblePanelButton';
+	this.dom.appendChild( this.button );
+
+	var scope = this;
+	this.button.addEventListener( 'click', function ( event ) {
+
+		scope.toggle();
+
+	}, false );
+
+	this.content = document.createElement( 'div' );
+	this.content.className = 'CollapsibleContent';
+	this.dom.appendChild( this.content );
+
+	this.isCollapsed = false;
+
+	return this;
+
+};
+
+UI.CollapsiblePanel.prototype = Object.create( UI.Panel.prototype );
+
+UI.CollapsiblePanel.prototype.addStatic = function () {
+
+	for ( var i = 0; i < arguments.length; i ++ ) {
+
+		this.dom.insertBefore( arguments[ i ].dom, this.content );
+
+	}
+
+	return this;
+
+};
+
+UI.CollapsiblePanel.prototype.removeStatic = UI.Panel.prototype.remove;
+
+UI.CollapsiblePanel.prototype.clearStatic = function () {
+
+	this.dom.childNodes.forEach( function ( child ) {
+
+		if ( child !== this.content ) {
+
+			this.dom.removeChild( child );
+
+		}
+
+	});
+
+};
+
+UI.CollapsiblePanel.prototype.add = function () {
+
+	for ( var i = 0; i < arguments.length; i ++ ) {
+
+		this.content.appendChild( arguments[ i ].dom );
+
+	}
+
+	return this;
+
+};
+
+UI.CollapsiblePanel.prototype.remove = function () {
+
+	for ( var i = 0; i < arguments.length; i ++ ) {
+
+		this.content.removeChild( arguments[ i ].dom );
+
+	}
+
+	return this;
+
+};
+
+UI.CollapsiblePanel.prototype.clear = function () {
+
+	while ( this.content.children.length ) {
+
+		this.content.removeChild( this.content.lastChild );
+
+	}
+
+};
+
+UI.CollapsiblePanel.prototype.toggle = function() {
+
+	this.setCollapsed( !this.isCollapsed );
+
+};
+
+UI.CollapsiblePanel.prototype.collapse = function() {
+
+	this.setCollapsed( true );
+
+};
+
+UI.CollapsiblePanel.prototype.expand = function() {
+
+	this.setCollapsed( false );
+
+};
+
+UI.CollapsiblePanel.prototype.setCollapsed = function( setCollapsed ) {
+
+	if ( setCollapsed ) {
+
+		this.dom.classList.add('collapsed');
+
+	} else {
+
+		this.dom.classList.remove('collapsed');
+
+	}
+
+	this.isCollapsed = setCollapsed;
+
+};
+
 // Text
 // Text
 
 
 UI.Text = function ( text ) {
 UI.Text = function ( text ) {