You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2007/02/28 00:57:33 UTC

svn commit: r512533 - in /incubator/xap/trunk: codebase/src/xap/bridges/dojo/ codebase/src/xap/widgets/dojo/ samples/WebContent/examples/widgets/

Author: jmargaris
Date: Tue Feb 27 16:57:32 2007
New Revision: 512533

URL: http://svn.apache.org/viewvc?view=rev&rev=512533
Log:
boxFlex is now working

Modified:
    incubator/xap/trunk/codebase/src/xap/bridges/dojo/HorizontalPanelBridge.js
    incubator/xap/trunk/codebase/src/xap/bridges/dojo/VerticalPanelBridge.js
    incubator/xap/trunk/codebase/src/xap/widgets/dojo/HorizontalPanel.js
    incubator/xap/trunk/codebase/src/xap/widgets/dojo/VerticalPanel.js
    incubator/xap/trunk/samples/WebContent/examples/widgets/horizontalBoxPane.xal
    incubator/xap/trunk/samples/WebContent/examples/widgets/verticalBoxPane.xal

Modified: incubator/xap/trunk/codebase/src/xap/bridges/dojo/HorizontalPanelBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/dojo/HorizontalPanelBridge.js?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/dojo/HorizontalPanelBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/dojo/HorizontalPanelBridge.js Tue Feb 27 16:57:32 2007
@@ -80,7 +80,7 @@
 	var element = childHandler.getElement();
 
 	var flex = element.getAttribute("boxFlex");
-	var flexInt = 1;
+	var flexInt = 0;
 	if (flex) {
 		flexInt= parseInt(flex);
 	}

Modified: incubator/xap/trunk/codebase/src/xap/bridges/dojo/VerticalPanelBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/dojo/VerticalPanelBridge.js?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/dojo/VerticalPanelBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/dojo/VerticalPanelBridge.js Tue Feb 27 16:57:32 2007
@@ -79,7 +79,7 @@
 	var element = childHandler.getElement();
 
 	var flex = element.getAttribute("boxFlex");
-	var flexInt = 1;
+	var flexInt = 0;
 	if (flex) {
 		flexInt= parseInt(flex);
 	}

Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/HorizontalPanel.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/HorizontalPanel.js?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/HorizontalPanel.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/HorizontalPanel.js Tue Feb 27 16:57:32 2007
@@ -35,6 +35,7 @@
 xap.widgets.dojo.HorizontalPanel = function(){
 	dojo.widget.HtmlWidget.call(this);
 	this.align = "start";
+	this._totalFlex = 0;
 }
 dojo.inherits(xap.widgets.dojo.HorizontalPanel, dojo.widget.HtmlWidget);
 
@@ -58,6 +59,7 @@
 		cell.style.height = "100%";
 	 	
 		child.domNode.flex = flex;
+		this._totalFlex += flex;
 		
 		if (insertIndex >= 0 && insertIndex < row.childNodes.length ) {
 			row.insertBefore(cell, row.childNodes[insertIndex]);
@@ -71,15 +73,24 @@
 		xap.widgets.dojo.HorizontalPanel.superclass.addChild.call(this,child, overrideContainerNode, pos, ref, insertIndex);
  
  		this.setAlign(this.align);
+ 		
+ 		if (!this._resizeTask && this.isShowing()){
+			this._resizeTask = dojo.lang.setTimeout(this, this.onResized, 0);
+		}
 	},
 	
 	 removeChild: function(child) {
 	 	
+	 	this._totalFlex -= child.domNode.flex;
 	 	//when we remove the child we also have to remove the entire
 	 	//cell it was in
 	 	var containerCell= child.domNode.parentNode;
 		xap.widgets.dojo.HorizontalPanel.superclass.removeChild.call(this,child);
 		containerCell.parentNode.removeChild(containerCell);
+		
+		if (!this._resizeTask && this.isShowing()){
+			this._resizeTask = dojo.lang.setTimeout(this, this.onResized, 0);
+		}
     },
     
     setAlign: function(align) {
@@ -122,7 +133,56 @@
    		else if (pack == "center") {
    			this.centerTd.align = "center";
    		}
-    }
+    },
+    
+    flex: function() {
+		var children = this.children;
+		
+		//set all flexible children to height ''
+		for (var i = 0; i < children.length; i++) {
+			if (children[i].domNode.flex) {
+				children[i].domNode.style.width='';
+			}
+		}
+		
+		
+		//after we reset the flexible children we need to wait for container
+		//to size accordingly
+		dojo.lang.setTimeout(this, this.finishFlex, 0);
+	},
+	
+	finishFlex: function(){
+		var children = this.children;
+		
+		var freeSpace = this.domNode.clientWidth;
+		
+		for (var i = 0; i < children.length; i++) {
+			freeSpace -= children[i].domNode.offsetWidth;
+		}	
+		//figure out how much space 1 'point' of flex is worth
+		var flexUnit = freeSpace/this._totalFlex;
+		
+		//if a child has flex defined, stretch it out
+		for (var i = 0; i < children.length; i++) {
+			if (children[i].domNode.flex) {
+				children[i].domNode.style.width = (children[i].domNode.clientWidth + (flexUnit * children[i].domNode.flex)) + 'px';
+			}
+		}
+		xap.widgets.dojo.HorizontalPanel.superclass.onResized.call(this);
+	},
+	
+	onResized: function(){
+		delete this._resizeTask;
+		
+		//if we have a flex don't call super.onResized() here,
+		//we will do it after we lay out the children based on flex
+		if (this._totalFlex>0){
+			this.flex();
+		}
+		else{
+			xap.widgets.dojo.HorizontalPanel.superclass.onResized.call(this);
+		}
+	}
 	
 }
 );

Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/VerticalPanel.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/VerticalPanel.js?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/VerticalPanel.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/VerticalPanel.js Tue Feb 27 16:57:32 2007
@@ -35,6 +35,7 @@
 xap.widgets.dojo.VerticalPanel = function() {
 	dojo.widget.HtmlWidget.call(this);
 	this.align = "start";//start, center, end, stretch
+	this._totalFlex = 0;
 }
 dojo.inherits(xap.widgets.dojo.VerticalPanel, dojo.widget.HtmlWidget);
 
@@ -56,6 +57,8 @@
 		var row = document.createElement("tr");
 		var cell = document.createElement("td");  
 		child.domNode.flex = flex;
+		this._totalFlex += flex;
+		
  
 		row.appendChild(cell);
 		
@@ -73,16 +76,24 @@
 		
 		
 		this.setAlign(this.align);
-		this.setPack("start");
+		
+		if (!this._resizeTask && this.isShowing()){
+			this._resizeTask = dojo.lang.setTimeout(this, this.onResized, 0);
+		}
 	},
 	
 	removeChild: function(child) {
 	 	
+	 	this._totalFlex -= child.domNode.flex;
 	 	//when we remove the child we also have to remove the entire
 	 	//row it was in
 	 	var containerRow = child.domNode.parentNode.parentNode;	
 		xap.widgets.dojo.VerticalPanel.superclass.removeChild.call(this,child);
 		containerRow.parentNode.removeChild(containerRow);
+		
+		if (!this._resizeTask && this.isShowing()){
+			this._resizeTask = dojo.lang.setTimeout(this, this.onResized, 0);
+		}
     },
     
     setAlign: function(align){
@@ -132,9 +143,70 @@
    			this.centerTd.style.verticalAlign = "middle";
    		}
     }, 
-
-	show: function() {
-		this.isHidden = false;
+	
+	
+	//notes on flex:
+	//flex is pretty complicated to get right. The basic strategy is this:
+	//1. They set the height of the container
+	//2. For every flexible component we set the height to ''. We must do that because
+	//if the children flexed to fill up the space available making the container smaller
+	//won't have any effect, it will size to fit children.
+	//3. we wait for the browser to resize the container.
+	//4. Now that the container has resized, we adjust the flexible children to take up
+	//the remaining space. 
+	//This strategy works well in general, but has some small problems.
+	//for example, the container does not have a fixed height but the child does.
+	//The child is flexible and is a freePane, which means it does not have an intrinsic height.
+	//In this case when we change the height of the child to '' it will size to 0 tall,
+	//then the container will be zero tall as well. Hopefull this will not happen much...
+	flex: function() {
+		var children = this.children;
+		
+		//set all flexible children to height ''
+		for (var i = 0; i < children.length; i++) {
+			if (children[i].domNode.flex) {
+				children[i].domNode.style.height='';
+			}
+		}
+		
+		
+		//after we reset the flexible children we need to wait for container
+		//to size accordingly
+		dojo.lang.setTimeout(this, this.finishFlex, 0);
+	},
+	
+	finishFlex: function(){
+		var children = this.children;
+		
+		var freeSpace = this.domNode.clientHeight;
+		
+		for (var i = 0; i < children.length; i++) {
+			freeSpace -= children[i].domNode.offsetHeight;
+		}
+		
+		//figure out how much space 1 'point' of flex is worth
+		var flexUnit = freeSpace/this._totalFlex;
+		
+		//if a child has flex defined, stretch it out
+		for (var i = 0; i < children.length; i++) {
+			if (children[i].domNode.flex) {
+				children[i].domNode.style.height = (children[i].domNode.clientHeight + (flexUnit * children[i].domNode.flex)) + 'px';
+			}
+		}
+		xap.widgets.dojo.VerticalPanel.superclass.onResized.call(this);
+	},
+	
+	onResized: function(){
+		delete this._resizeTask;
+		
+		//if we have a flex don't call super.onResized() here,
+		//we will do it after we lay out the children based on flex
+		if (this._totalFlex>0){
+			this.flex();
+		}
+		else{
+			xap.widgets.dojo.VerticalPanel.superclass.onResized.call(this);
+		}
 	}
 }
 ); 

Modified: incubator/xap/trunk/samples/WebContent/examples/widgets/horizontalBoxPane.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/samples/WebContent/examples/widgets/horizontalBoxPane.xal?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/samples/WebContent/examples/widgets/horizontalBoxPane.xal (original)
+++ incubator/xap/trunk/samples/WebContent/examples/widgets/horizontalBoxPane.xal Tue Feb 27 16:57:32 2007
@@ -30,19 +30,16 @@
 			<freePane width="500px" height="300px" backgroundColor="#F0F0F0"
 				id="testComponentFreePane">
 				<xal:horizontalBoxPane id="testComponent">
-
-					<xal:freePane flex="3" height="110px" width="20px" backgroundColor="red"
-						id="redComponent" onCreate="mco:attributeSetter.registerElement(this)">
-						<label text="flex:3 width:110" x="0" y="0"/>
-					</xal:freePane>
-					<xal:freePane flex="4" height="120px" width="20px" backgroundColor="green"
-						id="greenComponent" onCreate="mco:attributeSetter.registerElement(this)">
-						<label text="flex:4 width:120" x="0" y="0"/>
-					</xal:freePane>
-					<xal:freePane flex="1" height="150px" width="20px" backgroundColor="yellow"
+					<label text="boxFlex:1 height:110" boxFlex="3" height="110px" backgroundColor="red"
+						id="redComponent" onCreate="mco:attributeSetter.registerElement(this)"/>
+						
+					
+					<label boxFlex="2" height="120px" text="flex:4 height:120" backgroundColor="green"
+						id="greenComponent" onCreate="mco:attributeSetter.registerElement(this)"/>
+					<xal:freePane height="150px" width="20px" backgroundColor="yellow"
 						id="yellowComponent" onCreate="mco:attributeSetter.registerElement(this)">
 						<label
-							text="flex:1 width:150 Debug-Mon Nov 06 2006 14:29:05 GMT-0500 (Eastern Standard Time) (xap.taghandling.PluginRegistryImpl): Add tag mapping:binding:xap.data.bridge.BindingBridge"
+							text="width:150 Debug-Mon Nov 06 2006 14:29:05 GMT-0500 (Eastern Standard Time) (xap.taghandling.PluginRegistryImpl): Add tag mapping:binding:xap.data.bridge.BindingBridge"
 							x="0" y="0"/>
 					</xal:freePane>
 					<xal:freePane height="140px" width="20px" backgroundColor="blue"

Modified: incubator/xap/trunk/samples/WebContent/examples/widgets/verticalBoxPane.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/samples/WebContent/examples/widgets/verticalBoxPane.xal?view=diff&rev=512533&r1=512532&r2=512533
==============================================================================
--- incubator/xap/trunk/samples/WebContent/examples/widgets/verticalBoxPane.xal (original)
+++ incubator/xap/trunk/samples/WebContent/examples/widgets/verticalBoxPane.xal Tue Feb 27 16:57:32 2007
@@ -31,24 +31,19 @@
 			<freePane width="500px" height="300px" backgroundColor="#F0F0F0"
 				id="testComponentFreePane">
 				<xal:verticalBoxPane id="testComponent">
-
-					<xal:freePane flex="3" width="110px" height="20px" backgroundColor="red"
-						id="redComponent" onCreate="mco:attributeSetter.registerElement(this)">
-						<label text="flex:3 width:110" x="0" y="0"/>
-					</xal:freePane>
-					<xal:freePane flex="4" width="120px" height="20px" backgroundColor="green"
-						id="greenComponent" onCreate="mco:attributeSetter.registerElement(this)">
-						<label text="flex:4 width:120" x="0" y="0"/>
-					</xal:freePane>
-					<xal:freePane flex="1" width="150px" height="20px" backgroundColor="yellow"
+					<label text="boxFlex:2 width:110" x="0" y="0"  boxFlex="2" width="110px" backgroundColor="red"
+						id="redComponent" onCreate="mco:attributeSetter.registerElement(this)"/>
+					<label text="boxFlex:1 width:110" x="0" y="0"  boxFlex="1" width="120px" backgroundColor="green"
+						id="greenComponent" onCreate="mco:attributeSetter.registerElement(this)"/>
+					<xal:freePane width="150px" height="20px" backgroundColor="yellow"
 						id="yellowComponent" onCreate="mco:attributeSetter.registerElement(this)">
 						<label
-							text="flex:1 width:150 Debug-Mon Nov 06 2006 14:29:05 GMT-0500 (Eastern Standard Time) (xap.taghandling.PluginRegistryImpl): Add tag mapping:binding:xap.data.bridge.BindingBridge"
+							text="width:150 Debug-Mon Nov 06 2006 14:29:05 GMT-0500 (Eastern Standard Time) (xap.taghandling.PluginRegistryImpl): Add tag mapping:binding:xap.data.bridge.BindingBridge"
 							x="0" y="0"/>
 					</xal:freePane>
 					<xal:freePane width="140px" height="20px" backgroundColor="blue"
 						id="blueComponent" onCreate="mco:attributeSetter.registerElement(this)">
-						<label text="flex:null width:140" x="0" y="0"/>
+						<label text="width:140" x="0" y="0"/>
 					</xal:freePane>
 				</xal:verticalBoxPane>
 			</freePane>