123456789101112131415161718192021222324252627282930313233343536373839 |
- using PixiEditor.ChangeableDocument.Rendering;
- namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
- [NodeInfo("TextInfo")]
- public class TextInfoNode : Node
- {
- public OutputProperty<int> Length { get; }
-
- public OutputProperty<int> LineCount { get; }
-
- public InputProperty<string> Text { get; }
- public TextInfoNode()
- {
- Length = CreateOutput("Length", "TEXT_LENGTH", 0);
- LineCount = CreateOutput("LineCount", "TEXT_LINE_COUNT", 0);
-
- Text = CreateInput("Text", "TEXT", string.Empty);
- }
-
- protected override void OnExecute(RenderContext context)
- {
- var text = Text.Value;
- if (string.IsNullOrEmpty(text))
- {
- Length.Value = 0;
- LineCount.Value = 0;
- return;
- }
-
- Length.Value = text.Length;
- LineCount.Value = text.AsSpan().Count('\n');
- }
- public override Node CreateCopy() =>
- new TextInfoNode();
- }
|