MaxLength on textfields

This commit is contained in:
Paul Chote
2010-07-10 23:50:42 +12:00
parent 62995ffad8
commit 3296cc2ec1
2 changed files with 26 additions and 17 deletions

View File

@@ -26,6 +26,7 @@ namespace OpenRA.Widgets
class TextFieldWidget : Widget
{
public string Text = "";
public int MaxLength = 0;
public bool Bold = false;
public int VisualHeight = 1;
public Func<bool> OnEnterKey = () => {return false;};
@@ -41,6 +42,9 @@ namespace OpenRA.Widgets
:base(widget)
{
Text = (widget as TextFieldWidget).Text;
MaxLength = (widget as TextFieldWidget).MaxLength;
Bold = (widget as TextFieldWidget).Bold;
VisualHeight = (widget as TextFieldWidget).VisualHeight;
}
public override bool HandleInput(MouseInput mi)
@@ -103,8 +107,14 @@ namespace OpenRA.Widgets
Text = Text.Remove(Text.Length - 1);
}
else if (!char.IsControl(c))
{
Console.WriteLine("{0} {1}",MaxLength, Text.Length);
if (MaxLength > 0 && Text.Length >= MaxLength)
return;
Text += c;
}
}
int blinkCycle = 10;
bool showCursor = true;
@@ -122,9 +132,8 @@ namespace OpenRA.Widgets
{
int margin = 5;
var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
var text = Text + ((showCursor && Chrome.selectedWidget == this) ? "|" : "");
var textSize = font.Measure(Text);
var cursor = (showCursor && Chrome.selectedWidget == this) ? "|" : "";
var textSize = font.Measure(Text + "|");
var pos = DrawPosition();
WidgetUtils.DrawPanel("dialog3",
@@ -140,7 +149,7 @@ namespace OpenRA.Widgets
Game.chrome.renderer.Device.EnableScissor(pos.X + margin, pos.Y, Bounds.Width - 2*margin, Bounds.Bottom);
}
font.DrawText(text, textPos, Color.White);
font.DrawText(Text + cursor, textPos, Color.White);
if (textSize.X > Bounds.Width - 2*margin)
{

View File

@@ -356,11 +356,11 @@ Container:
TextField@NAME:
Id:NAME
Text:Name
Width:127
Width:139
Height:25
X:0
Y:0
Bold: true
MaxLength:16
Button@COLOR:
Id:COLOR
Width:65
@@ -378,7 +378,7 @@ Container:
Id:FACTION
Width:110
Height:25
X:256
X:244
Y:0
Children:
Image@FACTIONFLAG:
@@ -399,7 +399,7 @@ Container:
Text:Team
Width:25
Height:25
X:398
X:374
Y:0
Checkbox@STATUS:
Id:STATUS
@@ -417,7 +417,7 @@ Container:
Label@NAME:
Id:NAME
Text:Name
Width:127
Width:139
Height:25
X:0
Y:0
@@ -431,7 +431,7 @@ Container:
Id:FACTION
Width:110
Height:25
X:256
X:244
Y:0
Children:
Image@FACTIONFLAG:
@@ -452,7 +452,7 @@ Container:
Text:Team
Width:70
Height:25
X:375
X:351
Y:0
Align:Center
Bold: false
@@ -467,7 +467,7 @@ Container:
Children:
Label@LABEL_LOBBY_NAME:
Id:LABEL_LOBBY_NAME
Width:127
Width:139
Height:25
X:0
Y:0
@@ -487,7 +487,7 @@ Container:
Id:LABEL_LOBBY_FACTION
Width:110
Height:25
X:256
X:244
Y:0
Text:Faction
Align:Center
@@ -496,7 +496,7 @@ Container:
Id:LABEL_LOBBY_TEAM
Width:70
Height:25
X:375
X:351
Y:0
Text:Team
Align:Center
@@ -530,7 +530,7 @@ Container:
#rabeep1.aud for ra
Label@LABEL_CHATTYPE:
Id:LABEL_CHATTYPE
Width:70
Width:65
Height:25
X:0
Y:PARENT_BOTTOM - 75
@@ -539,9 +539,9 @@ Container:
TextField@CHAT_TEXTFIELD:
Id:CHAT_TEXTFIELD
Visible:true
X:75
X:70
Y:PARENT_BOTTOM - 74
Width:705
Width:710
Height:25
Button@DISCONNECT_BUTTON:
Id:DISCONNECT_BUTTON