TextField.cs 804 B

123456789101112131415161718192021222324252627
  1. using PixiEditor.Extensions.CommonApi.FlyUI;
  2. using PixiEditor.Extensions.CommonApi.FlyUI.Events;
  3. namespace PixiEditor.Extensions.Sdk.Api.FlyUI;
  4. public class TextField : LayoutElement
  5. {
  6. public event ElementEventHandler<TextEventArgs> TextChanged
  7. {
  8. add => AddEvent(nameof(TextChanged), value);
  9. remove => RemoveEvent(nameof(TextChanged), value);
  10. }
  11. public string Text { get; set; }
  12. public TextField(string? text = null, Cursor? cursor = null) : base(cursor)
  13. {
  14. Text = text ?? string.Empty;
  15. TextChanged += e => Text = e.Text;
  16. }
  17. protected override ControlDefinition CreateControl()
  18. {
  19. ControlDefinition textField = new ControlDefinition(UniqueId, "TextField");
  20. textField.AddProperty(Text);
  21. return textField;
  22. }
  23. }