47 lines
No EOL
1.6 KiB
C#
47 lines
No EOL
1.6 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace ONDClient.GUI;
|
|
|
|
public class MenuInputField : UIElement {
|
|
private readonly TextUIElement labelElement;
|
|
private readonly TextBoxUIElement textBoxElement;
|
|
|
|
public MenuInputField(SpriteFont font, Point position, string label, string defaultValue = "") : base(position, position) {
|
|
labelElement =
|
|
new TextUIElement(position, font){Text = label, Color = Color.Gray};
|
|
textBoxElement =
|
|
new TextBoxUIElement(font,
|
|
new(labelElement.Bounds.Item1.X + (int)labelElement.Measure().X, labelElement.Bounds.Item1.Y),
|
|
new(640, labelElement.Bounds.Item2.Y + (int)labelElement.Measure().Y));
|
|
textBoxElement.OnFocused = () => {
|
|
textBoxElement.Color = Color.LightGreen;
|
|
labelElement.Color = Color.DarkGreen;
|
|
};
|
|
textBoxElement.OnUnfocused = () => {
|
|
textBoxElement.Color = Color.White;
|
|
labelElement.Color = Color.Gray;
|
|
};
|
|
|
|
Bounds = (labelElement.Bounds.Item1, textBoxElement.Bounds.Item2);
|
|
Pressable = true;
|
|
OnMousePress = textBoxElement.OnMousePress;
|
|
textBoxElement.Text = defaultValue;
|
|
}
|
|
|
|
public string Text{
|
|
get => textBoxElement.Text;
|
|
set => textBoxElement.Text = value;
|
|
}
|
|
|
|
public override void Draw(SpriteBatch spriteBatch) {
|
|
labelElement.Draw(spriteBatch);
|
|
textBoxElement.Draw(spriteBatch);
|
|
}
|
|
|
|
public override void Update() {
|
|
base.Update();
|
|
labelElement.Update();
|
|
textBoxElement.Update();
|
|
}
|
|
} |