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

[royale-asjs] branch develop updated: Fix Jewel ToolTip to avoid get out of screen

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

carlosrovira 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 39a7d70  Fix Jewel ToolTip to avoid get out of screen
39a7d70 is described below

commit 39a7d70425fcdf690595e84cfc416a6aa6fb3425
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Mon Sep 17 22:42:28 2018 +0200

    Fix Jewel ToolTip to avoid get out of screen
---
 .../JewelExample/src/main/royale/MainContent.mxml  | 10 +++-
 .../apache/royale/jewel/beads/controls/ToolTip.as  | 69 ++++++++++++++--------
 2 files changed, 53 insertions(+), 26 deletions(-)

diff --git a/examples/royale/JewelExample/src/main/royale/MainContent.mxml b/examples/royale/JewelExample/src/main/royale/MainContent.mxml
index f04358a..4a50dcd 100644
--- a/examples/royale/JewelExample/src/main/royale/MainContent.mxml
+++ b/examples/royale/JewelExample/src/main/royale/MainContent.mxml
@@ -99,12 +99,18 @@ limitations under the License.
                 <j:TopAppBarTitle text="Apache Royale Jewel UI Set Theme Showcase"/>
             </j:TopAppBarSection>
             <j:TopAppBarSection alignRight="true">
-                <j:IconButton click="drawer.fixed = !drawer.fixed">
+                <!-- <j:IconButton click="drawer.fixed = !drawer.fixed">
+                    <j:beads>
+                        <j:ToolTip toolTip="Lock(fix) or Unlock the TopBar"/>
+                    </j:beads>
                     <j:icon>
                         <js:FontIcon text="{MaterialIconType.VISIBILITY}" material="true"/>
                     </j:icon>
-                </j:IconButton>
+                </j:IconButton> -->
                 <j:ToggleButton click="toggleTopAppBarFixed()">
+                    <j:beads>
+                        <j:ToolTip toolTip="Lock(fix) or Unlock the TopBar"/>
+                    </j:beads>
                     <j:icon>
                         <js:ToggleFontIcon text="{MaterialIconType.LOCK}" selectedText="{MaterialIconType.LOCK_OPEN}" material="true"/>
                     </j:icon>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/ToolTip.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/ToolTip.as
index 5ad42ac..e5bdb23 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/ToolTip.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/ToolTip.as
@@ -28,6 +28,7 @@ package org.apache.royale.jewel.beads.controls
 	import org.apache.royale.jewel.supportClasses.tooltip.ToolTipLabel;
 	import org.apache.royale.utils.PointUtils;
 	import org.apache.royale.utils.UIUtils;
+	import org.apache.royale.core.IParentIUIBase;
 
 	/**
 	 *  The ToolTip class is a specialty bead that can be used with
@@ -146,10 +147,12 @@ package org.apache.royale.jewel.beads.controls
 
             tt = new ToolTipLabel();
             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;
-            host.popUpParent.addElement(tt, false); // don't trigger a layout
 		}
 
 		/**
@@ -159,34 +162,52 @@ package org.apache.royale.jewel.beads.controls
 		 */
 		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 xFactor:Number = 1;
-			var yFactor:Number = 1;
-			var pt:Point;
-			var relative:Boolean = _xPos > TOP &&  _yPos > TOP;
-
-			if (_xPos == LEFT) {
-				xFactor = Number.POSITIVE_INFINITY;
-			}
-			else if (_xPos == MIDDLE) {
-				xFactor = 2;
-			}
-			else if (_xPos == RIGHT) {
-				xFactor = 1;
-			}
-			if (_yPos == TOP) {
-				yFactor = Number.POSITIVE_INFINITY;
+			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;
 			}
-			else if (_yPos == MIDDLE) {
-				yFactor = 2;
-			}
-			else if (_yPos == BOTTOM) {
-				yFactor = 1;
+			switch(_yPos){
+				case TOP:
+					y = -ttHeight;
+					break;
+				case MIDDLE:
+					y = (comp.height - ttHeight) / 2;
+					break;
+				case BOTTOM:
+					y = comp.height;
+					break;
 			}
 
-			pt = new Point(comp.width/xFactor, comp.height/yFactor);
+			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;
 		}