Przeglądaj źródła

Added a text info node

CPKreuz 2 tygodni temu
rodzic
commit
9bd59e9743

+ 32 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/TextInfoNode.cs

@@ -0,0 +1,32 @@
+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;
+        
+        Length.Value = text.Length;
+        LineCount.Value = text.AsSpan().Count('\n');
+    }
+
+    public override Node CreateCopy() =>
+        new TextInfoNode();
+}

+ 4 - 1
src/PixiEditor/Data/Localization/Languages/en.json

@@ -1123,5 +1123,8 @@
   "FIRST_POSITION": "First position",
   "LAST_POSITION": "Last position",
   "MATCH_CASE": "Match case",
-  "SEARCH_TEXT": "Search text"
+  "SEARCH_TEXT": "Search text",
+  "TEXT_INFO_NODE": "Text info",
+  "TEXT_LENGTH": "Length",
+  "TEXT_LINE_COUNT": "Line count"
 }

+ 7 - 0
src/PixiEditor/ViewModels/Document/Nodes/Text/TextInfoNodeViewModel.cs

@@ -0,0 +1,7 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
+using PixiEditor.ViewModels.Nodes;
+
+namespace PixiEditor.ViewModels.Document.Nodes.Text;
+
+[NodeViewModel("TEXT_INFO_NODE", "SHAPE", null)]
+internal class TextInfoNodeViewModel : NodeViewModel<TextInfoNode>;