Selaa lähdekoodia

Added Slice Text Node

CPKreuz 2 viikkoa sitten
vanhempi
commit
caaf143c8c

+ 37 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Text/SliceTextNode.cs

@@ -0,0 +1,37 @@
+using PixiEditor.ChangeableDocument.Rendering;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Text;
+
+[NodeInfo("SliceText")]
+public class SliceTextNode : Node
+{
+    public OutputProperty<string> SlicedText { get; }
+    
+    public InputProperty<string> Text { get; }
+    
+    public InputProperty<int> Index { get; }
+    
+    public InputProperty<int> Length { get; }
+    
+    public SliceTextNode()
+    {
+        SlicedText = CreateOutput("SlicedText", "TEXT", string.Empty);
+        Text = CreateInput("Text", "TEXT", string.Empty);
+        
+        Index = CreateInput("Index", "INDEX_START_AT", 0)
+            .WithRules(x => x.Min(0));
+        
+        Length = CreateInput("Length", "LENGTH", 1)
+            .WithRules(x => x.Min(0));
+    }
+
+    protected override void OnExecute(RenderContext context)
+    {
+        SlicedText.Value = Text.Value.Substring(
+            Math.Min(Index.Value, Text.Value.Length - 1),
+            Math.Min(Length.Value, Text.Value.Length));
+    }
+
+    public override Node CreateCopy() =>
+        new SliceTextNode();
+}

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

@@ -1116,5 +1116,7 @@
   "DISABLE_PREVIEWS": "Disable Previews",
   "MAX_BILINEAR_CANVAS_SIZE": "Max Bilinear Canvas Size",
   "MAX_BILINEAR_CANVAS_SIZE_DESC": "Maximum canvas size for bilinear filtering. Set to 0 to disable bilinear filtering. Bilinear filtering improves the quality of the canvas, but can cause performance issues on large canvases.",
-  "INVERT_MASK": "Invert mask"
+  "INVERT_MASK": "Invert mask",
+  "SLICE_TEXT": "Slice text",
+  "INDEX_START_AT": "Start at"
 }

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

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