Permalink
Browse files

Added passwordCharacter field to TextField by default with the value …

…of the TextField.BULLET constant, and a setPasswordCharacter(char) to be able to configure the desired password character for the TextField. Added a TextField with passwordMode enabled in the UITest to show how it works

git-svn-id: http://libgdx.googlecode.com/svn/trunk@3382 6c4fd544-2939-11df-bb46-9574ba5d0bfa
  • Loading branch information...
1 parent 651466f commit 54da354a1eae0a552ff342e0b55eaa8a63415984 ariel.coppes@gmail.com committed Feb 20, 2012
@@ -83,6 +83,8 @@
private int selectionStart;
private float selectionX, selectionWidth;
+ private char passwordCharacter = BULLET;
+
public TextField (Skin skin) {
this("", null, skin.getStyle(TextFieldStyle.class), null);
}
@@ -125,6 +127,10 @@ public void setStyle (TextFieldStyle style) {
this.style = style;
invalidateHierarchy();
}
+
+ public void setPasswordCharacter (char passwordCharacter) {
+ this.passwordCharacter = passwordCharacter;
+ }
/** Returns the text field's style. Modifying the returned style may not have an effect until {@link #setStyle(TextFieldStyle)}
* is called. */
@@ -223,13 +229,13 @@ public void draw (SpriteBatch batch, float parentAlpha) {
}
} else {
font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
- if (passwordMode && font.containsCharacter(BULLET)) {
+ if (passwordMode && font.containsCharacter(passwordCharacter)) {
if (passwordBuffer == null) passwordBuffer = new StringBuilder(text.length());
if (passwordBuffer.length() > text.length()) //
passwordBuffer.setLength(text.length());
else {
for (int i = passwordBuffer.length(), n = text.length(); i < n; i++)
- passwordBuffer.append(BULLET);
+ passwordBuffer.append(passwordCharacter);
}
font.draw(batch, passwordBuffer, x + bgLeftWidth + textOffset, y + textY, visibleTextStart, visibleTextEnd);
} else
@@ -94,6 +94,12 @@ public void create () {
SplitPaneStyle.class), "split");
final Label fpsLabel = new Label("fps:", skin.getStyle(LabelStyle.class), "label");
+ // configures an example of a TextField in password mode.
+ final Label passwordLabel = new Label("Textfield in password mode: ", skin);
+ final TextField passwordTextField = new TextField("", "password", skin);
+ passwordTextField.setPasswordCharacter('*');
+ passwordTextField.setPasswordMode(true);
+
// window.debug();
Window window = new Window("Dialog", skin.getStyle(WindowStyle.class), "window");
window.x = window.y = 0;
@@ -112,6 +118,9 @@ public void create () {
window.row();
window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
window.row();
+ window.add(passwordLabel).colspan(2);
+ window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
+ window.row();
window.add(fpsLabel).colspan(4);
window.pack();

0 comments on commit 54da354

Please sign in to comment.