You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/10/10 16:34:54 UTC

[07/16] git commit: [flex-asjs] [refs/heads/develop] - handle percentages in layout

handle percentages in layout


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/16491839
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/16491839
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/16491839

Branch: refs/heads/develop
Commit: 16491839de8e84d3adfa54b4be68a0042cf1ab89
Parents: 4efdd81
Author: Alex Harui <ah...@apache.org>
Authored: Wed Oct 8 22:44:21 2014 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Fri Oct 10 07:34:32 2014 -0700

----------------------------------------------------------------------
 .../src/org/apache/flex/core/ILayoutChild.as    | 94 ++++++++++++++++++++
 .../src/org/apache/flex/core/IUIBase.as         |  8 +-
 .../FlexJSUI/src/org/apache/flex/core/UIBase.as | 74 ++++++++++++---
 .../src/org/apache/flex/core/UIButtonBase.as    | 60 ++++++++++++-
 .../html/beads/layouts/NonVirtualBasicLayout.as | 18 +++-
 .../beads/layouts/NonVirtualHorizontalLayout.as | 14 +++
 .../beads/layouts/NonVirtualVerticalLayout.as   | 14 +++
 7 files changed, 266 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ILayoutChild.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ILayoutChild.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ILayoutChild.as
new file mode 100755
index 0000000..b2bf2cb
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ILayoutChild.as
@@ -0,0 +1,94 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.core
+{
+    import flash.display.DisplayObjectContainer;
+    
+    /**
+     *  The IChild interface is the basic interface for a 
+     *  component that is parented by another component.
+     * 
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public interface ILayoutChild extends IChild, IUIBase
+	{
+        /**
+         *  The requested percentage width of
+         *  this component in its container.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function get percentWidth():Number;
+        function set percentWidth(value:Number):void;
+        
+        /**
+         *  The requested percentage height of
+         *  this component in its container.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function get percentHeight():Number;
+        function set percentHeight(value:Number):void;
+        
+        /**
+         * Sets the height of the component without
+         * setting explicitHeight.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function setHeight(value:Number):void;
+        
+        /**
+         * Sets the width of the component without
+         * setting explicitWidth.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function setWidth(value:Number):void;
+        
+        /**
+         * Sets the width and height of the component 
+         * without setting explicitWidth or explicitHeight.
+         * It also sends one change event.  If both
+         * values change it only sends heightCHange event.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function setWidthAndHeight(newWidth:Number, newHeight:Number):void;
+        
+   	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
index 8509678..445241b 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
@@ -99,8 +99,14 @@ package org.apache.flex.core
 		
 		/**
 		 * The height of the bounding box.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
 		 */
 		function get height():Number;
 		function set height(value:Number):void;
-	}
+        
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as
index 98a7c86..18953be 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as
@@ -49,7 +49,7 @@ package org.apache.flex.core
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public class UIBase extends Sprite implements IStrandWithModel, IEventDispatcher, IParentIUIBase, IStyleableObject, IChild
+	public class UIBase extends Sprite implements IStrandWithModel, IEventDispatcher, IParentIUIBase, IStyleableObject, ILayoutChild
 	{
         /**
          *  Constructor.
@@ -252,11 +252,7 @@ package org.apache.flex.core
 				explicitWidth = value;
 			}
 			
-			if (_width != value)
-			{
-				_width = value;
-				dispatchEvent(new org.apache.flex.events.Event("widthChanged"));
-			}
+            setWidth(value);
 		}
 
         /**
@@ -314,11 +310,7 @@ package org.apache.flex.core
 				explicitHeight = value;
 			}
 			
-			if (_height != value)
-			{
-				_height = value;
-				dispatchEvent(new org.apache.flex.events.Event("heightChanged"));
-			}
+            setHeight(value);
 		}
         
         /**
@@ -334,7 +326,65 @@ package org.apache.flex.core
 		{
 			return super.height;
 		}
-		
+        
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setHeight
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setHeight(value:Number):void
+        {
+            if (_height != value)
+            {
+                _height = value;
+                dispatchEvent(new org.apache.flex.events.Event("heightChanged"));
+            }            
+        }
+
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setWidth
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setWidth(value:Number):void
+        {
+            if (_width != value)
+            {
+                _width = value;
+                dispatchEvent(new org.apache.flex.events.Event("widthChanged"));
+            }
+        }
+        
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setWidthAndHeight
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setWidthAndHeight(newWidth:Number, newHeight:Number):void
+        {
+            if (_width != newWidth)
+            {
+                _width = newWidth;
+                if (_height == newHeight)
+                    dispatchEvent(new org.apache.flex.events.Event("widthChanged"));
+            }
+            if (_height != newHeight)
+            {
+                _height = newHeight;
+                dispatchEvent(new org.apache.flex.events.Event("heightChanged"));
+            }            
+            
+        }
+        
 		private var _model:IBeadModel;
 
         /**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
index 6dbcfd3..09e1d96 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
@@ -57,7 +57,7 @@ package org.apache.flex.core
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public class UIButtonBase extends SimpleButton implements IStrandWithModel, IEventDispatcher, IUIBase, IStyleableObject
+	public class UIButtonBase extends SimpleButton implements IStrandWithModel, IEventDispatcher, IUIBase, IStyleableObject, ILayoutChild
 	{
         /**
          *  Constructor.
@@ -371,6 +371,64 @@ package org.apache.flex.core
 			return super.height;
 		}
 
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setHeight
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setHeight(value:Number):void
+        {
+            if (_height != value)
+            {
+                _height = value;
+                dispatchEvent(new org.apache.flex.events.Event("heightChanged"));
+            }            
+        }
+        
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setWidth
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setWidth(value:Number):void
+        {
+            if (_width != value)
+            {
+                _width = value;
+                dispatchEvent(new org.apache.flex.events.Event("widthChanged"));
+            }
+        }
+        
+        /**
+         *  @copy org.apache.flex.core.IUIBase#setWidthAndHeight
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function setWidthAndHeight(newWidth:Number, newHeight:Number):void
+        {
+            if (_width != newWidth)
+            {
+                _width = newWidth;
+                if (_height == newHeight)
+                    dispatchEvent(new org.apache.flex.events.Event("widthChanged"));
+            }
+            if (_height != newHeight)
+            {
+                _height = newHeight;
+                dispatchEvent(new org.apache.flex.events.Event("heightChanged"));
+            }            
+            
+        }
+        
         private var _model:IBeadModel;
 
         /**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualBasicLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualBasicLayout.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualBasicLayout.as
index 7def726..0db1cc0 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualBasicLayout.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualBasicLayout.as
@@ -20,10 +20,11 @@ package org.apache.flex.html.beads.layouts
 {
 	
 	import org.apache.flex.core.IBeadLayout;
+    import org.apache.flex.core.ILayoutChild;
 	import org.apache.flex.core.ILayoutParent;
 	import org.apache.flex.core.IParentIUIBase;
 	import org.apache.flex.core.IStrand;
-	import org.apache.flex.core.IUIBase;
+    import org.apache.flex.core.IUIBase;
 	import org.apache.flex.core.ValuesManager;
 	import org.apache.flex.events.Event;
 	import org.apache.flex.events.IEventDispatcher;
@@ -83,7 +84,7 @@ package org.apache.flex.html.beads.layouts
 			var n:int = contentView.numElements;
 			for (var i:int = 0; i < n; i++)
 			{
-				var child:IUIBase = contentView.getElementAt(i) as IUIBase;
+				var child:ILayoutChild = contentView.getElementAt(i) as ILayoutChild;
                 var left:Number = ValuesManager.valuesImpl.getValue(child, "left");
                 var right:Number = ValuesManager.valuesImpl.getValue(child, "right");
                 var top:Number = ValuesManager.valuesImpl.getValue(child, "top");
@@ -97,6 +98,19 @@ package org.apache.flex.html.beads.layouts
                 {
                     child.y = top;
                 }
+                var ilc:ILayoutChild;
+                if (child is ILayoutChild)
+                {
+                    ilc = child as ILayoutChild;
+                    if (!isNaN(ilc.percentHeight))
+                        ilc.setHeight(contentView.height * ilc.percentHeight / 100);
+                }
+                if (child is ILayoutChild)
+                {
+                    ilc = child as ILayoutChild;
+                    if (!isNaN(ilc.percentWidth))
+                        ilc.setWidth(contentView.width * ilc.percentWidth / 100);
+                }
                 if (!isNaN(right))
                 {
                     if (!isNaN(left))

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualHorizontalLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualHorizontalLayout.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualHorizontalLayout.as
index 1da19a8..062972b 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualHorizontalLayout.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualHorizontalLayout.as
@@ -19,6 +19,7 @@
 package org.apache.flex.html.beads.layouts
 {
 	import org.apache.flex.core.IBeadLayout;
+    import org.apache.flex.core.ILayoutChild;
 	import org.apache.flex.core.ILayoutParent;
 	import org.apache.flex.core.IStrand;
     import org.apache.flex.core.IParentIUIBase;
@@ -77,6 +78,7 @@ package org.apache.flex.html.beads.layouts
 			var contentView:IParentIUIBase = layoutParent.contentView;
 			
 			var n:int = contentView.numElements;
+            var ilc:ILayoutChild;
 			var marginLeft:Object;
 			var marginRight:Object;
 			var marginTop:Object;
@@ -151,6 +153,12 @@ package org.apache.flex.html.beads.layouts
 					child.x = ml;
 				else
 					child.x = xx + ml + lastmr;
+                if (child is ILayoutChild)
+                {
+                    ilc = child as ILayoutChild;
+                    if (!isNaN(ilc.percentWidth))
+                        ilc.setWidth(contentView.width * ilc.percentWidth / 100);
+                }
 				xx = child.x + child.width;
 				lastmr = mr;
 				var valign:Object = ValuesManager.valuesImpl.getValue(child, "vertical-align");
@@ -160,6 +168,12 @@ package org.apache.flex.html.beads.layouts
 			{
 				var obj:Object = verticalMargins[0]
 				child = contentView.getElementAt(i) as IUIBase;
+                if (child is ILayoutChild)
+                {
+                    ilc = child as ILayoutChild;
+                    if (!isNaN(ilc.percentHeight))
+                        ilc.setHeight(contentView.height * ilc.percentHeight / 100);
+                }
 				if (obj.valign == "middle")
 					child.y = maxHeight - child.height / 2;
 				else if (valign == "bottom")

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/16491839/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualVerticalLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualVerticalLayout.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualVerticalLayout.as
index 082980f..0bc1bdd 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualVerticalLayout.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/layouts/NonVirtualVerticalLayout.as
@@ -20,6 +20,7 @@ package org.apache.flex.html.beads.layouts
 {
 	
 	import org.apache.flex.core.IBeadLayout;
+    import org.apache.flex.core.ILayoutChild;
 	import org.apache.flex.core.ILayoutParent;
     import org.apache.flex.core.IParentIUIBase;
 	import org.apache.flex.core.IStrand;
@@ -80,6 +81,7 @@ package org.apache.flex.html.beads.layouts
 			var n:int = contentView.numElements;
 			var hasHorizontalFlex:Boolean;
 			var flexibleHorizontalMargins:Array = [];
+            var ilc:ILayoutChild;
 			var marginLeft:Object;
 			var marginRight:Object;
 			var marginTop:Object;
@@ -134,6 +136,12 @@ package org.apache.flex.html.beads.layouts
 					child.y = mt;
 				else
 					child.y = yy + Math.max(mt, lastmb);
+                if (child is ILayoutChild)
+                {
+                    ilc = child as ILayoutChild;
+                    if (!isNaN(ilc.percentHeight))
+                        ilc.setHeight(contentView.height * ilc.percentHeight / 100);
+                }
 				yy = child.y + child.height;
 				lastmb = mb;
 				flexibleHorizontalMargins[i] = {};
@@ -179,6 +187,12 @@ package org.apache.flex.html.beads.layouts
 				for (i = 0; i < n; i++)
 				{
 					child = contentView.getElementAt(i) as IUIBase;
+                    if (child is ILayoutChild)
+                    {
+                        ilc = child as ILayoutChild;
+                        if (!isNaN(ilc.percentWidth))
+                            ilc.setWidth(contentView.width * ilc.percentWidth / 100);
+                    }
 					var obj:Object = flexibleHorizontalMargins[i];
 					if (obj.marginLeft == "auto" && obj.marginRight == "auto")
 						child.x = maxWidth - child.width / 2;