TestState.cs 712 B

123456789101112131415161718192021222324
  1. using PixiEditor.Extensions.CommonApi.FlyUI.Events;
  2. using PixiEditor.Extensions.FlyUI.Elements;
  3. namespace PixiEditor.Extensions.Test;
  4. public class TestState : State
  5. {
  6. public const string Format = "Clicked: {0}";
  7. public int ClickedTimes { get; private set; } = 0;
  8. public bool ReplaceText { get; set; } = false;
  9. public LayoutElement? ReplaceTextWith { get; set; } = null;
  10. public override LayoutElement BuildElement()
  11. {
  12. return new Button(
  13. onClick: OnClick,
  14. child: ReplaceText ? ReplaceTextWith : new Text(string.Format(Format, ClickedTimes)));
  15. }
  16. private void OnClick(ElementEventArgs args)
  17. {
  18. SetState(() => ClickedTimes++);
  19. }
  20. }