Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 54da354a1eae0a552ff342e0b55eaa8a63415984 1 parent 651466f
authored February 20, 2012
10  gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java
@@ -83,6 +83,8 @@
83 83
 	private int selectionStart;
84 84
 	private float selectionX, selectionWidth;
85 85
 
  86
+	private char passwordCharacter = BULLET;
  87
+
86 88
 	public TextField (Skin skin) {
87 89
 		this("", null, skin.getStyle(TextFieldStyle.class), null);
88 90
 	}
@@ -125,6 +127,10 @@ public void setStyle (TextFieldStyle style) {
125 127
 		this.style = style;
126 128
 		invalidateHierarchy();
127 129
 	}
  130
+	
  131
+	public void setPasswordCharacter (char passwordCharacter) {
  132
+		this.passwordCharacter = passwordCharacter;
  133
+	}
128 134
 
129 135
 	/** Returns the text field's style. Modifying the returned style may not have an effect until {@link #setStyle(TextFieldStyle)}
130 136
 	 * is called. */
@@ -223,13 +229,13 @@ public void draw (SpriteBatch batch, float parentAlpha) {
223 229
 			}
224 230
 		} else {
225 231
 			font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
226  
-			if (passwordMode && font.containsCharacter(BULLET)) {
  232
+			if (passwordMode && font.containsCharacter(passwordCharacter)) {
227 233
 				if (passwordBuffer == null) passwordBuffer = new StringBuilder(text.length());
228 234
 				if (passwordBuffer.length() > text.length()) //
229 235
 					passwordBuffer.setLength(text.length());
230 236
 				else {
231 237
 					for (int i = passwordBuffer.length(), n = text.length(); i < n; i++)
232  
-						passwordBuffer.append(BULLET);
  238
+						passwordBuffer.append(passwordCharacter);
233 239
 				}
234 240
 				font.draw(batch, passwordBuffer, x + bgLeftWidth + textOffset, y + textY, visibleTextStart, visibleTextEnd);
235 241
 			} else
9  tests/gdx-tests/src/com/badlogic/gdx/tests/UITest.java
@@ -94,6 +94,12 @@ public void create () {
94 94
 			SplitPaneStyle.class), "split");
95 95
 		final Label fpsLabel = new Label("fps:", skin.getStyle(LabelStyle.class), "label");
96 96
 
  97
+		// configures an example of a TextField in password mode.
  98
+		final Label passwordLabel = new Label("Textfield in password mode: ", skin);
  99
+		final TextField passwordTextField = new TextField("", "password", skin);
  100
+		passwordTextField.setPasswordCharacter('*');
  101
+		passwordTextField.setPasswordMode(true);
  102
+
97 103
 		// window.debug();
98 104
 		Window window = new Window("Dialog", skin.getStyle(WindowStyle.class), "window");
99 105
 		window.x = window.y = 0;
@@ -112,6 +118,9 @@ public void create () {
112 118
 		window.row();
113 119
 		window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
114 120
 		window.row();
  121
+		window.add(passwordLabel).colspan(2);
  122
+		window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
  123
+		window.row();
115 124
 		window.add(fpsLabel).colspan(4);
116 125
 		window.pack();
117 126
 

0 notes on commit 54da354

Please sign in to comment.
Something went wrong with that request. Please try again.