You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/06/12 05:24:29 UTC
svn commit: r1798413 -
/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
Author: rwhitcomb
Date: Mon Jun 12 05:24:29 2017
New Revision: 1798413
URL: http://svn.apache.org/viewvc?rev=1798413&view=rev
Log:
PIVOT-850: Adjust the text width calculations to just use the TextLayout.advance
value (adjusted to (int)Math.ceil(...) of course). This is completely accurate
and has no issues of the caret jumping around at times like the old code did.
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java?rev=1798413&r1=1798412&r2=1798413&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTextInputSkin.java Mon Jun 12 05:24:29 2017
@@ -376,23 +376,15 @@ public class TerraTextInputSkin extends
}
/**
- * Do the heavy lifting to figure out the width of the text that is
- * being displayed. This could be the user text, or the prompt text
- * if there is no user text.
- * <p> With {@link TextLayout} this is kind of tricky, so currently
- * we are calculating the average of the "bounds" and the "pixel bounds"
- * (which we see can differ by 1/2 character width sometimes).
+ * The text width is the just the "advance" value of the {@link TextLayout}
+ * (if any) or 0 if {@code null}.
*
- * @param textLayout The text to measure.
- * @return The width of the text in pixel amounts, or 0 if
- * there is no text currently.
+ * @param textLayout The existing text (if any).
+ * @return The "advance" value or 0 if there is no text.
*/
private int getTextWidth(TextLayout textLayout) {
if (textLayout != null) {
- Rectangle2D textBounds = textLayout.getBounds();
- int textWidth = (int)Math.ceil(textBounds.getWidth());
- Rectangle pixelBounds = textLayout.getPixelBounds(null, 0f, 0f);
- return (textWidth + pixelBounds.width + 1) / 2;
+ return (int)Math.ceil(textLayout.getAdvance());
}
return 0;
}