You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by pe...@apache.org on 2018/03/29 12:56:44 UTC

[royale-asjs] branch feature/MXRoyale updated: Added CanvasLayout.

This is an automated email from the ASF dual-hosted git repository.

pent pushed a commit to branch feature/MXRoyale
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/feature/MXRoyale by this push:
     new 6b5ae47  Added CanvasLayout.
6b5ae47 is described below

commit 6b5ae4756e9a484aeee0cd058bcc0eeb748a5963
Author: Peter Ent <pe...@apache.org>
AuthorDate: Thu Mar 29 08:56:40 2018 -0400

    Added CanvasLayout.
---
 .../MXRoyale/src/main/resources/defaults.css       |   5 +
 .../src/main/resources/mx-royale-manifest.xml      |   1 +
 .../MXRoyale/src/main/royale/MXRoyaleClasses.as    |   1 +
 .../src/main/royale/mx/containers/Canvas.as        |   1 +
 .../royale/mx/containers/beads/CanvasLayout.as     | 221 +++++++++++++++++++++
 5 files changed, 229 insertions(+)

diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index a7d26e9..425501f 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -41,6 +41,11 @@ Button
     IBeadModel: ClassReference("org.apache.royale.html.beads.models.ImageAndTextModel");
 }
 
+Canvas
+{
+	IBeadLayout: ClassReference("mx.containers.beads.CanvasLayout");
+}
+
 CheckBox
 {
 	IBeadModel: ClassReference("org.apache.royale.html.beads.models.ToggleButtonModel");
diff --git a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
index 8170f60..6db6ad4 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
+++ b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
@@ -41,6 +41,7 @@
 	<component id="VBox" class="mx.containers.VBox" />	
 	<component id="ApplicationLayout" class="mx.containers.beads.ApplicationLayout" />
 	<component id="BoxLayout" class="mx.containers.beads.BoxLayout" />
+	<component id="CanvasLayout" class="mx.containers.beads.CanvasLayout" />
 	
     <component id="State" class="mx.states.State" />
 	
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index d27891f..39b68a1 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -31,6 +31,7 @@ internal class MXRoyaleClasses
 	import mx.core.Container; Container;
 	import mx.containers.beads.ApplicationLayout; ApplicationLayout;
 	import mx.containers.beads.BoxLayout; BoxLayout;
+	import mx.containers.beads.CanvasLayout; CanvasLayout;
 	import mx.controls.ToolTip; ToolTip;
 	import mx.controls.beads.ToolTipBead; ToolTipBead;
 	
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/Canvas.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/Canvas.as
index 1d3e638..c431f53 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/Canvas.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/Canvas.as
@@ -123,6 +123,7 @@ public class Canvas extends Container implements IConstraintLayout
     public function Canvas()
     {
         super();
+		typeNames = "Canvas";
 
         //layoutObject.target = this;
     }
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/CanvasLayout.as b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/CanvasLayout.as
new file mode 100644
index 0000000..46fe600
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/CanvasLayout.as
@@ -0,0 +1,221 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 mx.containers.beads
+{
+	import mx.containers.Canvas;
+	import mx.core.Container;
+	import mx.core.EdgeMetrics;
+	import mx.core.IUIComponent;
+	
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.core.LayoutBase;
+	import org.apache.royale.geom.Rectangle;
+
+/*
+import mx.core.mx_internal;
+import mx.events.ChildExistenceChangedEvent;
+import mx.events.MoveEvent;
+import mx.resources.IResourceManager;
+import mx.resources.ResourceManager;
+import flash.utils.Dictionary;
+
+use namespace mx_internal;
+*/
+
+/**
+ *  @private
+ *  The CanvasLayout class is for internal use only.
+ */
+public class CanvasLayout extends LayoutBase
+{
+    
+
+    //--------------------------------------------------------------------------
+    //
+    //  Constructor
+    //
+    //--------------------------------------------------------------------------
+
+    /**
+     *  Constructor.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function CanvasLayout()
+    {
+        super();
+    }
+	
+	//--------------------------------------------------------------------------
+	//
+	//  Properties
+	//
+	//--------------------------------------------------------------------------
+	
+	private var _strand:IStrand;
+	
+	override public function set strand(value:IStrand):void
+	{
+		_strand = value;
+		_target = value as Container;
+		super.strand = value;
+		
+	}
+	
+	private var _target:Container;
+	
+	public function get target():Container
+	{
+		return _target;
+	}
+	
+	public function set target(value:Container):void
+	{
+		_target = value;
+	}
+
+    
+    //--------------------------------------------------------------------------
+    //
+    //  Overridden methods
+    //
+    //--------------------------------------------------------------------------
+
+	override public function layout():Boolean
+	{
+		COMPILE::SWF
+		{			
+			var hostWidthSizedToContent:Boolean = host.isWidthSizedToContent();
+			var hostHeightSizedToContent:Boolean = host.isHeightSizedToContent();
+			
+			var w:Number = hostWidthSizedToContent ? 0 : target.width;
+			var h:Number = hostHeightSizedToContent ? 0 : target.height;
+			
+			var n:int = target.numChildren;
+				
+			for (var i:int = 0; i < n; i++)
+			{
+				var child:IUIComponent = target.getLayoutChildAt(i);
+				if (!child.includeInLayout) continue;
+				
+				var positions:Object = childPositions(child);
+				var margins:Object = childMargins(child, target.width, target.height);
+				var ww:Number = w;
+				var hh:Number = h;
+				
+				var xpos:Number;
+				var ypos:Number;
+				var useWidth:Number;
+				var useHeight:Number;
+								
+				// set the top edge of the child
+				if (!isNaN(positions.left))
+				{
+					xpos = positions.left+margins.left;
+					ww -= positions.left + margins.left;
+				}
+				
+				// set the left edge of the child
+				if (!isNaN(positions.top))
+				{
+					ypos = positions.top+margins.top;
+					hh -= positions.top + margins.top;
+				}
+				
+				// set the right edge of the child
+				if (!isNaN(positions.right))
+				{
+					if (!hostWidthSizedToContent)
+					{
+						if (!isNaN(positions.left))
+						{
+							useWidth = ww - positions.right - margins.right;
+						}
+						else
+						{
+							xpos = w - positions.right - margins.left - child.width - margins.right
+						}
+					}
+				}
+				else if (child != null && !isNaN(child.percentWidth) && !hostWidthSizedToContent)
+				{
+					useWidth = (ww - margins.right - margins.left) * child.percentWidth/100;
+				}
+				
+				// set the bottm edge of the child
+				if (!isNaN(positions.bottom))
+				{
+					if (!hostHeightSizedToContent)
+					{
+						if (!isNaN(positions.top))
+						{
+							useHeight = hh - positions.bottom - margins.bottom;
+						}
+						else
+						{
+							ypos = h - positions.bottom - child.height - margins.bottom;
+						}
+					}
+				}
+				else if (child != null && !isNaN(child.percentHeight) && !hostHeightSizedToContent)
+				{
+					useHeight = (hh - margins.top - margins.bottom) * child.percentHeight/100;
+				}
+				
+				if (margins.auto)
+				{
+					xpos = (w - child.width) / 2;
+				}
+				
+				child.move(xpos, ypos);
+				child.setActualSize(useWidth, useHeight);
+			}
+				
+			return true;
+				
+		}
+			
+		COMPILE::JS
+		{
+			var i:int
+			var n:int;
+			
+			n = target.numChildren;
+			
+			// host must have either have position:absolute or position:relative
+			if (target.element.style.position != "absolute" && target.element.style.position != "relative") {
+				target.element.style.position = "relative";
+			}
+			
+			// each child must have position:absolute for BasicLayout to work
+			for (i=0; i < n; i++) {
+				var child:IUIComponent = target.getLayoutChildAt(i);
+				child.positioner.style.position = "absolute";
+			}
+			
+			return true;
+		}
+	}
+}
+}
+

-- 
To stop receiving notification emails like this one, please contact
pent@apache.org.