iFactory.Godot/BITKit/Scripts/UX/UXLineEdit.cs

30 lines
566 B
C#
Raw Normal View History

using Godot;
using System;
using BITKit;
namespace BITFactory;
public partial class UXLineEdit : LineEdit
{
[Export] private TextValidationResource textValidation;
[Export] private RichTextLabel hints;
public override void _Ready()
{
TextChanged += OnTextChanged;
}
private void OnTextChanged(string newText)
{
2023-07-17 04:10:14 +08:00
if (hints is null) return;
if (textValidation is not null && textValidation.IsTextValid(newText,out var errorReason) is false)
{
hints.Text = $"[color=red]{errorReason}[/color]";
}
else
{
hints.Text = string.Empty;
}
}
}