From dc462b8771745e5a71fd5cc4c7f85207495cf44c Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sat, 26 Jul 2014 01:59:35 +0200 Subject: [PATCH] Editor: Started implementing UI.Dialog. --- editor/index.html | 16 ++++++++- editor/js/Editor.js | 10 ++++++ editor/js/Menubar.File.js | 12 ++++++- editor/js/libs/ui.js | 72 +++++++++++++++++++++++++++++++++++++-- 4 files changed, 105 insertions(+), 5 deletions(-) diff --git a/editor/index.html b/editor/index.html index 25d52ae02f..c339f8481c 100644 --- a/editor/index.html +++ b/editor/index.html @@ -96,7 +96,10 @@ var sidebar = new Sidebar( editor ).setId( 'sidebar' ); document.body.appendChild( sidebar.dom ); - + + var dialog = new UI.Dialog(); + document.body.appendChild( dialog.dom ); + // editor.setTheme( editor.config.getKey( 'theme' ) ); @@ -149,6 +152,17 @@ signals.materialChanged.add( saveState ); signals.sceneGraphChanged.add( saveState ); + var showDialog = function ( content ) { + + dialog.clear(); + + dialog.add( content ); + dialog.showModal(); + + }; + + signals.showDialog.add( showDialog ); + } ); // diff --git a/editor/js/Editor.js b/editor/js/Editor.js index b7a7905d92..878c77a24c 100644 --- a/editor/js/Editor.js +++ b/editor/js/Editor.js @@ -9,6 +9,8 @@ var Editor = function () { playAnimation: new SIGNALS.Signal(), stopAnimation: new SIGNALS.Signal(), + showDialog: new SIGNALS.Signal(), + // notifications themeChanged: new SIGNALS.Signal(), @@ -65,6 +67,14 @@ Editor.prototype = { }, + showDialog: function ( value ) { + + this.signals.showDialog.dispatch( value ); + + }, + + // + setScene: function ( scene ) { this.scene.name = scene.name; diff --git a/editor/js/Menubar.File.js b/editor/js/Menubar.File.js index 729654a1b3..faa84a6198 100644 --- a/editor/js/Menubar.File.js +++ b/editor/js/Menubar.File.js @@ -154,6 +154,13 @@ Menubar.File = function ( editor ) { } + function onExportTestOptionClick() { + + var text = new UI.Text( 'blah' ); + editor.showDialog( text ); + + } + // create file input element for scene import var fileInput = document.createElement( 'input' ); @@ -176,7 +183,10 @@ Menubar.File = function ( editor ) { createOption( 'Export Object', onExportObjectOptionClick ), createOption( 'Export Scene', onExportSceneOptionClick ), createOption( 'Export OBJ', onExportOBJOptionClick ), - createOption( 'Export STL', onExportSTLOptionClick ) + createOption( 'Export STL', onExportSTLOptionClick ), + createDivider(), + + createOption( 'Export Test', onExportTestOptionClick ) ]; var optionsPanel = UI.MenubarHelper.createOptionsPanel( menuConfig ); diff --git a/editor/js/libs/ui.js b/editor/js/libs/ui.js index 35e5e830cd..e97aa498e0 100644 --- a/editor/js/libs/ui.js +++ b/editor/js/libs/ui.js @@ -106,7 +106,17 @@ UI.Panel.prototype.add = function () { for ( var i = 0; i < arguments.length; i ++ ) { - this.dom.appendChild( arguments[ i ].dom ); + var argument = arguments[ i ]; + + if ( argument instanceof UI.Element ) { + + this.dom.appendChild( argument.dom ); + + } else { + + console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' ) + + } } @@ -118,8 +128,18 @@ UI.Panel.prototype.add = function () { UI.Panel.prototype.remove = function () { for ( var i = 0; i < arguments.length; i ++ ) { + + var argument = arguments[ i ]; + + if ( argument instanceof UI.Element ) { + + this.dom.removeChild( argument.dom ); + + } else { - this.dom.removeChild( arguments[ i ].dom ); + console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' ) + + } } @@ -1085,4 +1105,50 @@ UI.Button.prototype.setLabel = function ( value ) { return this; -}; \ No newline at end of file +}; + + +// Dialog + +UI.Dialog = function ( value ) { + + var scope = this; + + var dom = document.createElement( 'dialog' ); + + if ( dom.showModal === undefined ) { + + // fallback + + dom = document.createElement( 'div' ); + dom.style.display = 'none'; + + dom.showModal = function () { + + dom.style.position = 'absolute'; + dom.style.left = '100px'; + dom.style.top = '100px'; + dom.style.zIndex = 1; + dom.style.display = ''; + + }; + + } + + dom.className = 'Dialog'; + + this.dom = dom; + + return this; + +}; + +UI.Dialog.prototype = Object.create( UI.Panel.prototype ); + +UI.Dialog.prototype.showModal = function () { + + this.dom.showModal(); + + return this; + +}; -- GitLab