summaryrefslogtreecommitdiff
path: root/Scripts/OutputRow.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/OutputRow.cs')
-rw-r--r--Scripts/OutputRow.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/Scripts/OutputRow.cs b/Scripts/OutputRow.cs
new file mode 100644
index 0000000..15a6454
--- /dev/null
+++ b/Scripts/OutputRow.cs
@@ -0,0 +1,72 @@
+using System;
+using Godot;
+
+namespace Texty.Scripts
+{
+ public abstract class OutputRow : VBoxContainer
+ {
+ [Signal]
+ public delegate void InputTextChanged(string newText);
+
+ [Signal]
+ public delegate void OutputTextChanged(string newText);
+
+ public Label Input;
+ public Label Output;
+
+ private string _inputText = "";
+ private string _outputText = "";
+
+ [Export]
+ public string InputText
+ {
+ get => _inputText;
+ set => UpdateText(Field.Input, value ?? "");
+ }
+
+ [Export]
+ public string OutputText
+ {
+ get => _outputText;
+ set => UpdateText(Field.Output, value ?? "");
+ }
+
+ public override void _Ready()
+ {
+ Input = GetNode<Label>(nameof(Input));
+ UpdateLabel(Input, _inputText);
+ Output = GetNode<Label>(nameof(Output));
+ UpdateLabel(Output, _outputText);
+ }
+
+ private void UpdateText(Field field, string value)
+ {
+ switch (field)
+ {
+ case Field.Input:
+ _inputText = value;
+ EmitSignal(nameof(InputTextChanged), _inputText);
+ UpdateLabel(Input, value);
+ break;
+ case Field.Output:
+ _outputText = value;
+ EmitSignal(nameof(OutputTextChanged), value);
+ UpdateLabel(Output, value);
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(field), field, "No such field!");
+ }
+ }
+
+ private static void UpdateLabel(Label label, string value)
+ {
+ if (label != null) label.Text = value;
+ }
+
+ private enum Field
+ {
+ Input,
+ Output
+ }
+ }
+} \ No newline at end of file