TextInfoNode.cs 991 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using PixiEditor.ChangeableDocument.Rendering;
  2. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
  3. [NodeInfo("TextInfo")]
  4. public class TextInfoNode : Node
  5. {
  6. public OutputProperty<int> Length { get; }
  7. public OutputProperty<int> LineCount { get; }
  8. public InputProperty<string> Text { get; }
  9. public TextInfoNode()
  10. {
  11. Length = CreateOutput("Length", "TEXT_LENGTH", 0);
  12. LineCount = CreateOutput("LineCount", "TEXT_LINE_COUNT", 0);
  13. Text = CreateInput("Text", "TEXT", string.Empty);
  14. }
  15. protected override void OnExecute(RenderContext context)
  16. {
  17. var text = Text.Value;
  18. if (string.IsNullOrEmpty(text))
  19. {
  20. Length.Value = 0;
  21. LineCount.Value = 0;
  22. return;
  23. }
  24. Length.Value = text.Length;
  25. LineCount.Value = text.AsSpan().Count('\n');
  26. }
  27. public override Node CreateCopy() =>
  28. new TextInfoNode();
  29. }