Fix selection logic for text fields

This commit is contained in:
drdev
2014-06-05 21:47:17 +00:00
parent a5573cd0e4
commit e124c76e5a

View File

@@ -2,6 +2,7 @@ package forge.toolbox;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import forge.Forge;
import forge.Forge.Graphics;
@@ -290,6 +291,18 @@ public class FTextField extends FDisplayObject implements ITextField {
float h = getHeight();
g.fillRect(BACK_COLOR, 0, 0, w, h);
//determine actual rendered font so selection logic is accurate
TextBounds textBounds = font.getMultiLineBounds(text);
while (textBounds.width > w || textBounds.height > h) {
if (font.canShrink()) { //shrink font to fit if possible
font = font.shrink();
textBounds = font.getMultiLineBounds(text);
}
else {
break;
}
}
//draw selection if key input is active
if (isEditing) {
float selLeft = PADDING;