You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ha...@apache.org on 2018/09/17 10:08:43 UTC

[royale-asjs] branch develop updated: Added AdaptiveToolTipBead

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 968944b  Added AdaptiveToolTipBead
968944b is described below

commit 968944b6c570eec72d544a512be3cf4f4bf7576d
Author: Harbs <ha...@in-tools.com>
AuthorDate: Mon Sep 17 13:08:33 2018 +0300

    Added AdaptiveToolTipBead
    
    It’s smarter about positioning the tooltip relative to its parent and keeps the tooltip from geting cut off on the edge of the screen.
---
 .../Basic/src/main/resources/basic-manifest.xml    |   1 +
 .../royale/html/accessories/AdaptiveToolTipBead.as | 150 +++++++++++++++++++++
 .../apache/royale/html/accessories/ToolTipBead.as  |  36 +++--
 3 files changed, 173 insertions(+), 14 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index 398e5a2..5945ef0 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -208,6 +208,7 @@
     <component id="VerticalColumnLayout" class="org.apache.royale.html.beads.layouts.VerticalColumnLayout" />
 
     <component id="ToolTipBead" class="org.apache.royale.html.accessories.ToolTipBead" />
+    <component id="AdaptiveToolTipBead" class="org.apache.royale.html.accessories.AdaptiveToolTipBead" />
     
     <component id="LayoutOnShow" class="org.apache.royale.html.beads.layouts.LayoutOnShow"/>
     <component id="ImageButton" class="org.apache.royale.html.ImageButton"/>
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/AdaptiveToolTipBead.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/AdaptiveToolTipBead.as
new file mode 100644
index 0000000..a6a1e33
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/AdaptiveToolTipBead.as
@@ -0,0 +1,150 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.royale.html.accessories
+{
+	import org.apache.royale.core.IBead;
+	import org.apache.royale.core.IParentIUIBase;
+	import org.apache.royale.core.IPopUpHost;
+	import org.apache.royale.core.IStrand;
+	import org.apache.royale.core.IUIBase;
+	import org.apache.royale.events.IEventDispatcher;
+	import org.apache.royale.events.MouseEvent;
+	import org.apache.royale.geom.Point;
+	import org.apache.royale.html.ToolTip;
+	import org.apache.royale.utils.PointUtils;
+	import org.apache.royale.utils.UIUtils;
+	import org.apache.royale.utils.DisplayUtils;
+
+	/**
+	 *  The AdaptiveToolTipBead class is a specialty bead that can be used with
+	 *  any control. The bead floats a string over a control if
+   *  the user hovers over the control with a mouse.
+	 *  It contains logic to ensure the tooltip remains inside the window.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.5
+	 */
+	public class AdaptiveToolTipBead extends ToolTipBead
+	{
+		/**
+		 *  constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9
+		 */
+		public function AdaptiveToolTipBead()
+		{
+		}
+
+		public static const TOP:int = 10000;
+		public static const BOTTOM:int = 10001;
+		public static const LEFT:int = 10002;
+		public static const RIGHT:int = 10003;
+		public static const MIDDLE:int = 10004;
+
+
+		/**
+		 * @private
+		 * @royaleignorecoercion org.apache.royale.core.IUIBase
+		 * @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+		 */
+		override protected function rollOverHandler(event:MouseEvent):void
+		{
+			if (!toolTip || tt)
+				return;
+
+			IEventDispatcher(_strand).addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler, false);
+
+			var comp:IUIBase = _strand as IUIBase
+			host = UIUtils.findPopUpHost(comp);
+			if (tt)
+				host.popUpParent.removeElement(tt);
+
+			tt = new ToolTip();
+			tt.text = toolTip;
+			// add this before measuring or measurement is not accurate.
+			host.popUpParent.addElement(tt, false); // don't trigger a layout
+			var pt:Point = determinePosition(event, event.target);
+			tt.x = pt.x;
+			tt.y = pt.y;
+		}
+
+		/**
+		 * @private
+		 * Determines the position of the toolTip.
+		 * @royaleignorecoercion org.apache.royale.core.IUIBase
+		 */
+		override protected function determinePosition(event:MouseEvent, base:Object):Point
+		{
+			var ttWidth:Number = tt.width;
+			var ttHeight:Number = tt.height;
+			var comp:IUIBase = _strand as IUIBase;
+			var x:Number;
+			var y:Number;
+			switch(xPos){
+				case LEFT:
+					x = -ttWidth;
+					break;
+				case MIDDLE:
+					x = (comp.width - ttWidth) / 2;
+					break;
+				case RIGHT:
+					x = comp.width;
+					break;
+			}
+			switch(yPos){
+				case TOP:
+					y = -ttHeight;
+					break;
+				case MIDDLE:
+					y = (comp.height - ttHeight) / 2;
+					break;
+				case BOTTOM:
+					y = comp.height;
+					break;
+			}
+
+			var pt:Point = new Point(x,y);
+			pt = PointUtils.localToGlobal(pt, comp);
+
+			//make sure it's not too high or to the left.
+			pt.x = Math.max(pt.x,0);
+			pt.y = Math.max(pt.y,0);
+
+			var screenHeight:Number = (host.popUpParent as IParentIUIBase).height;
+			// add an extra pixel for rounding errors
+			var extraHeight:Number = 1 + pt.y + ttHeight - screenHeight;
+			if(extraHeight > 0){
+				pt.y -= extraHeight;
+			}
+			var screenWidth:Number = (host.popUpParent as IParentIUIBase).width;
+			var extraWidth:Number = 1 + pt.x + ttWidth - screenWidth;
+			if(extraWidth > 0){
+				pt.x -= extraWidth;
+			}
+			return pt;
+		}
+
+	}
+}
+
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/ToolTipBead.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/ToolTipBead.as
index fa3d601..d360314 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/ToolTipBead.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/ToolTipBead.as
@@ -60,8 +60,8 @@ package org.apache.royale.html.accessories
 		public static const MIDDLE:int = 10004;
 
 		private var _toolTip:String;
-		private var tt:ToolTip;
-		private var host:IPopUpHost;
+		protected var tt:ToolTip;
+		protected var host:IPopUpHost;
 		private var _xPos:int = RIGHT;
 		private var _yPos:int = BOTTOM;
 
@@ -95,7 +95,10 @@ package org.apache.royale.html.accessories
 		{
 			_xPos = pos;
 		}
-
+		public function get xPos():int
+		{
+			return _xPos;
+		}
 		/**
 		 *  Sets the tooltip y relative position to one of
 		 *  TOP, MIDDLE or BOTTOM.
@@ -109,8 +112,12 @@ package org.apache.royale.html.accessories
 		{
 			_yPos = pos;
 		}
+		public function get yPos():int
+		{
+			return _yPos;
+		}
 
-		private var _strand:IStrand;
+		protected var _strand:IStrand;
 
 		/**                         	
 		 *  @copy org.apache.royale.core.IBead#strand
@@ -138,18 +145,19 @@ package org.apache.royale.html.accessories
 			if (!toolTip || tt)
 				return;
 
-            IEventDispatcher(_strand).addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler, false);
+			IEventDispatcher(_strand).addEventListener(MouseEvent.MOUSE_OUT, rollOutHandler, false);
 
-            var comp:IUIBase = _strand as IUIBase
-            host = UIUtils.findPopUpHost(comp);
-			if (tt) host.popUpParent.removeElement(tt);
+			var comp:IUIBase = _strand as IUIBase
+			host = UIUtils.findPopUpHost(comp);
+			if (tt)
+				host.popUpParent.removeElement(tt);
 
-            tt = new ToolTip();
-            tt.text = toolTip;
-            var pt:Point = determinePosition(event, event.target);
-            tt.x = pt.x;
-            tt.y = pt.y;
-            host.popUpParent.addElement(tt, false); // don't trigger a layout
+			tt = new ToolTip();
+			tt.text = toolTip;
+			var pt:Point = determinePosition(event, event.target);
+			tt.x = pt.x;
+			tt.y = pt.y;
+			host.popUpParent.addElement(tt, false); // don't trigger a layout
 		}
 
 		/**