Author: rwhitcomb Date: Fri Aug 19 16:30:49 2011 New Revision: 1159676 URL: http://svn.apache.org/viewvc?rev=1159676&view=rev Log: Switch the tooltip X position to be left of the mouse position if it would go off the right of the display. But, make sure it will not go off the left. And if the tooltip will be behind the mouse cursor (so it would be partially obscured by it) then shift it to display above the cursor except don't let it go above the display.
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java?rev=1159676&r1=1159675&r2=1159676&view=diff ============================================================================== --- pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java (original) +++ pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ComponentSkin.java Fri Aug 19 16:30:49 2011 @@ -300,7 +300,31 @@ public abstract class ComponentSkin impl int tooltipX = location.x + 16; int tooltipY = location.y; + int tooltipWidth = tooltip.getPreferredWidth(); int tooltipHeight = tooltip.getPreferredHeight(); + if (tooltipX + tooltipWidth > display.getWidth()) { + // Try to just fit it inside the display if + // there would be room to shift it above the + // cursor, otherwise move it to the left of + // the cursor + if (tooltipY > tooltipHeight) { + tooltipX = display.getWidth() - tooltipWidth; + } else { + tooltipX = location.x - tooltipWidth - 16; + } + if (tooltipX < 0) { + tooltipX = 0; + } + // Adjust the y location if the tip ends up + // being behind the mouse cursor because of + // these x adjustments + if (tooltipX < location.x && tooltipX + tooltipWidth > location.x) { + tooltipY -= tooltipHeight; + if (tooltipY < 0) { + tooltipY = 0; + } + } + } if (tooltipY + tooltipHeight > display.getHeight()) { tooltipY -= tooltipHeight; }